diff --git a/src/app/actions.ts b/src/app/actions.ts
index 31b2211..acac180 100644
--- a/src/app/actions.ts
+++ b/src/app/actions.ts
@@ -3,7 +3,7 @@
import { db } from "@/server/db";
import type { UsersTableType } from "@/server/db/schema";
import { users } from "@/server/db/schema";
-import type { PaperlessDocumentsType } from "@/types";
+import type { PaperlessDocumentsType, WhishperRecordingsType } from "@/types";
import { auth } from "@clerk/nextjs/server";
import type { AdviceAPIType } from "@/types";
@@ -96,18 +96,11 @@ export async function getWhishperRecordings(query: string) {
if (!query || query == "null" || query.length < 3 || !userData) return null;
- const response = await fetch(
- `${userData.whishperURL}/api/documents/?query=${query}&page=1&page_size=10&truncate_content=true`,
- {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Token ${userData.paperlessToken}`,
- },
- },
- );
+ const response = await fetch(`${userData.whishperURL}/api/transcriptions`);
- const data = (await response.json()) as PaperlessDocumentsType;
+ const data = (await response.json()) as WhishperRecordingsType;
+
+ console.log(data)
return data;
}
diff --git a/src/app/paperless/page.tsx b/src/app/paperless/page.tsx
index fa68ac5..bcdb724 100644
--- a/src/app/paperless/page.tsx
+++ b/src/app/paperless/page.tsx
@@ -131,7 +131,7 @@ function DocumentsPage() {
const paperlessDocumentMap = PaperlessDocuments.data.results;
- if (paperlessDocumentMap.length === 0) {
+ if (!paperlessDocumentMap ?? paperlessDocumentMap.length === 0) {
return
No results!
;
}
@@ -165,7 +165,9 @@ export default function PaperlessPage() {
-
+
+
+
diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx
index c31b715..756bf29 100644
--- a/src/app/settings/page.tsx
+++ b/src/app/settings/page.tsx
@@ -171,6 +171,70 @@ function PaperlessToken({ setActiveTab, userData }: FormProps) {
);
}
+function WhishperURL({ setActiveTab, userData }: FormProps) {
+ const [isAutofilled, setIsAutofilled] = useState(false);
+ const formSchema = z.object({
+ URL: z.string(),
+ });
+
+ const form = useForm>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ URL: "",
+ },
+ });
+
+ if (userData.whishperURL && !isAutofilled) {
+ form.setValue("URL", userData.whishperURL);
+ setIsAutofilled(true);
+ }
+
+ async function onSubmit(values: z.infer) {
+ if (values.URL == "") {
+ setActiveTab((prevTab) => prevTab + 2); // Skip api key form
+ } else {
+ setActiveTab((prevTab) => prevTab + 1); // Increment activeTab
+ }
+ try {
+ await setUserProperty("whishperURL", values.URL);
+ // Operation succeeded, show success toast
+ toast("Your whishper URL preferences was saved");
+ // Optionally, move to a new tab or take another action to indicate success
+ } catch {
+ // Operation failed, show error toast
+ toast("Uh oh! Something went wrong.", {
+ description: "Your whishper URL preferences were not saved.",
+ action: {
+ label: "Go back",
+ onClick: () => setActiveTab((prevTab) => prevTab - 1), // Go back to try again
+ },
+ });
+ }
+ }
+
+ return (
+
+
+ );
+}
+
interface ProgressIndicatorProps {
activeTab: number;
totalTabs: number;
@@ -227,6 +291,11 @@ export function Forms() {
setActiveTab={setActiveTab}
userData={userData}
/>,
+ ,
];
return (
<>
diff --git a/src/app/whishper/page.tsx b/src/app/whishper/page.tsx
index a669718..401095a 100644
--- a/src/app/whishper/page.tsx
+++ b/src/app/whishper/page.tsx
@@ -17,9 +17,30 @@ import { Input } from "@/components/ui/input";
import Link from "next/link";
import { zodResolver } from "@hookform/resolvers/zod";
import { useCallback } from "react";
-import { useQuery } from "@tanstack/react-query";
-import { getUserData, getWhishperRecordings } from "../actions";
+import {
+ useQuery,
+ QueryClientProvider,
+ QueryClient,
+} from "@tanstack/react-query";
+import { getUserData } from "../actions";
import LoadingSpinner from "@/components/loading-spinner";
+import { WhishperRecordingsType } from "@/types";
+
+async function getWhishperRecordings(query: string) {
+ const userData = await getUserData();
+
+ if (!query || query == "null" || query.length < 3 || !userData) return null;
+
+ const response = await fetch(`${userData.whishperURL}/api/transcriptions`);
+
+ const data = (await response.json()) as WhishperRecordingsType;
+
+ console.log(data);
+
+ return data;
+}
+
+const queryClient = new QueryClient();
function SearchForm() {
const formSchema = z.object({
@@ -100,20 +121,24 @@ function RecordingsList() {
},
});
+ if (!userData.data?.whishperURL) {
+ return (
+
+ You need to set your whishper url in{" "}
+ settings
+
+ );
+ }
+
if (!query) {
return Start Searching!
;
}
if (WhishperRecordings.isLoading || userData.isLoading) {
return Loading...;
- } else if (!userData.data?.whishperURL) {
- return (
-
- You need to set your paperless url in{" "}
- settings
-
- );
- } else if (!WhishperRecordings.data || WhishperRecordings.error) {
+ }
+
+ if (!WhishperRecordings.data || WhishperRecordings.error) {
return (
Connection failed! Check that the whishper url is set correctly in{" "}
@@ -122,9 +147,9 @@ function RecordingsList() {
);
}
- const WhishperRecordingsMap = WhishperRecordings.data.results;
+ const WhishperRecordingsMap = WhishperRecordings.data;
- if (WhishperRecordingsMap.length === 0) {
+ if (!WhishperRecordingsMap ?? WhishperRecordingsMap.length === 0) {
return No results!
;
}
@@ -134,12 +159,12 @@ function RecordingsList() {
{WhishperRecordingsMap.map((recording, index) => (
-
-
- {recording.title}
-
+ {recording.fileName.split("_WHSHPR_")[1]}
+
))}
@@ -157,7 +182,16 @@ export default function WhishperPage() {
-
+
diff --git a/src/types/index.ts b/src/types/index.ts
index ed86760..bd1bb75 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -68,6 +68,36 @@ export type PaperlessDocumentsType = {
}[];
};
+export type WhishperRecordingsType = {
+ id: string;
+ status: number;
+ language: string;
+ modelSize: string;
+ task: string;
+ device: string;
+ fileName: string;
+ sourceUrl: string;
+ result: {
+ language: string;
+ duration: number;
+ segments: {
+ end: number;
+ id: string;
+ start: number;
+ score: number;
+ text: string;
+ words: {
+ end: number;
+ start: number;
+ word: string;
+ score: number;
+ }[];
+ }[];
+ text: string;
+ };
+ translations: [];
+}[];
+
export type AdviceAPIType = {
slip: {
slip_id: number;