diff --git a/src/app/@modal/default.tsx b/src/app/@modal/default.tsx deleted file mode 100644 index 7046598..0000000 --- a/src/app/@modal/default.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default function DefaultModal() { - return null; - } \ No newline at end of file diff --git a/src/app/whishper/recording/[id]/page.tsx b/src/app/whishper/recording/[id]/page.tsx index 406e2a4..29ae35d 100644 --- a/src/app/whishper/recording/[id]/page.tsx +++ b/src/app/whishper/recording/[id]/page.tsx @@ -1,14 +1,240 @@ -import AudioPreview from "@/components/audio-preview"; +"use client"; -export default async function FullAudioPage( - props: { - params: Promise<{ id: string }>; +import { + useQuery, + QueryClientProvider, + QueryClient, +} from "@tanstack/react-query"; +import type { UsersTableType } from "@/server/db/schema"; +import { Button, buttonVariants } from "@/components/ui/button"; +import { useRouter } from "next/navigation"; +import { ChevronLeft } from "lucide-react"; +import { useState } from "react"; +import OpenExternalLink from "@/components/external-link"; +import type { WhishperRecordingType } from "@/types"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "@/components/ui/alert-dialog"; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { toast } from "sonner"; +import BodyMessage from "@/components/body-message"; +import ky from "ky"; +import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; +import { getUserData } from "@/app/actions"; + +const queryClient = new QueryClient(); + +async function fetchUserData(): Promise { + return await ky.get("/api/getUserData").json(); +} + +function SkeletonLoader() { + return ( +
+
+
+
+ {/* Title Skeleton */} +
+ {/* Audio Skeleton */} +
+
+
+
+
+
+
+ ); +} + +async function fetchWhishperRecording( + searchId: string, + whishperURL: string, +): Promise { + const data = await ky + .get(`${whishperURL}/api/transcriptions`) + .json(); + console.log(data); + return data.find((recording) => recording.id === searchId); +} + +type AudioInfoProps = { + id: string; +}; + +function AudioInfo({ id }: AudioInfoProps) { + const router = useRouter(); + const [isPlaying, setIsPlaying] = useState(false); + + const { + data: userData, + isLoading: isUserDataLoading, + error: userDataError, + } = useQuery({ + queryKey: ["userData"], + queryFn: getUserData, + }); + + const whishperURL = userData?.whishperURL; + + const { + data: recordingData, + isLoading: isRecordingDataLoading, + error: recordingDataError, + } = useQuery({ + queryKey: ["whishperRecording", id, whishperURL], // Include id in the query key + queryFn: () => fetchWhishperRecording(id, whishperURL!), + enabled: !!whishperURL, // Only fetch recording data when userData is available + }); + + if (isUserDataLoading) { + return ; + } + + if (userDataError ?? !userData) { + return Error loading user data; + } + + if (isRecordingDataLoading) { + return ; + } + + if (recordingDataError ?? !recordingData) { + return Error loading recording data; } -) { - const params = await props.params; + + const decodedName = decodeURIComponent(recordingData.fileName); + const frontPart = decodedName.split("_WHSHPR_")[1] ?? decodedName; + const formattedName = frontPart.replace(".m4a", "") ?? decodedName; + + return ( +
+
+
+
+
+ {formattedName} + +
+ {/* Audio */} +
+ +
+
+ + + + + + Download + + + +

+ To download the audio file, right click and select + "Save as". +

+
+
+
+ + + + + + + + Are you absolutely sure? + + + This action cannot be undone. This will permanently delete + the recording. + + + + Cancel + { + const response = await ky.delete( + `${userData.whishperURL}/api/transcriptions/${id}`, + ); + if (response.ok) { + toast("Recording deleted", { + description: "The recording has been deleted.", + }); + } else { + toast("Error deleting recording", { + description: + "An error occurred while deleting the recording.", + }); + } + router.back(); + }} + > + Continue + + + + +
+
+
+
+
+ ); +} + +export default function AudioPreview({ id }: { id: string }) { return ( -
- -
+ + + + ); } diff --git a/src/components/audio-preview.tsx b/src/components/audio-preview.tsx deleted file mode 100644 index 5b84861..0000000 --- a/src/components/audio-preview.tsx +++ /dev/null @@ -1,242 +0,0 @@ -"use client"; - -import { - useQuery, - QueryClientProvider, - QueryClient, -} from "@tanstack/react-query"; -import type { UsersTableType } from "@/server/db/schema"; -import { Button, buttonVariants } from "@/components/ui/button"; -import { useRouter } from "next/navigation"; -import { ChevronLeft } from "lucide-react"; -import { useState } from "react"; -import OpenExternalLink from "@/components/external-link"; -import type { WhishperRecordingType } from "@/types"; -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, - AlertDialogTrigger, -} from "@/components/ui/alert-dialog"; -import { - Tooltip, - TooltipContent, - TooltipProvider, - TooltipTrigger, -} from "@/components/ui/tooltip"; -import { toast } from "sonner"; -import BodyMessage from "@/components/body-message"; -import ky from "ky"; - -const queryClient = new QueryClient(); - -async function fetchUserData(): Promise { - return await ky.get("/api/getUserData").json(); -} - -function SkeletonLoader() { - return ( -
-
-
-
- {/* Title Skeleton */} -
- {/* Audio Skeleton */} -
-
-
- {/* Button Skeletons */} -
- {Array.from({ length: 5 }, (_, index) => ( -
-
-
-
-
- ); -} - -async function fetchWhishperRecording( - searchId: string, - whishperURL: string, -): Promise { - const data = await ky - .get(`${whishperURL}/api/transcriptions`) - .json(); - return data.find((recording) => recording.id === searchId); -} - -type AudioInfoProps = { - id: string; -}; - -function AudioInfo({ id }: AudioInfoProps) { - const router = useRouter(); - const [isPlaying, setIsPlaying] = useState(false); - - const { - data: userData, - isLoading: isUserDataLoading, - error: userDataError, - } = useQuery({ - queryKey: ["userData"], - queryFn: fetchUserData, - }); - - const whishperURL = userData?.whishperURL; - - const { - data: recordingData, - isLoading: isRecordingDataLoading, - error: recordingDataError, - } = useQuery({ - queryKey: ["whishperRecording", id, whishperURL], // Include id in the query key - queryFn: () => fetchWhishperRecording(id, whishperURL!), - enabled: !!whishperURL, // Only fetch recording data when userData is available - }); - - if (isUserDataLoading) { - return ; - } - - if (userDataError ?? !userData) { - return Error loading user data; - } - - if (isRecordingDataLoading) { - return ; - } - - if (recordingDataError ?? !recordingData) { - return Error loading recording data; - } - - const decodedName = decodeURIComponent(recordingData.fileName); - const frontPart = decodedName.split("_WHSHPR_")[1] ?? decodedName; - const formattedName = frontPart.replace(".m4a", "") ?? decodedName; - - return ( -
-
-
-
-
- {formattedName} - -
- {/* Audio */} -
- -
-
- - - - - - Download - - - -

- To download the audio file, right click and select - "Save as". -

-
-
-
- - - - - - - - Are you absolutely sure? - - - This action cannot be undone. This will permanently delete - the recording. - - - - Cancel - { - const response = await ky.delete( - `${userData.whishperURL}/api/transcriptions/${id}`, - ); - if (response.ok) { - toast("Recording deleted", { - description: "The recording has been deleted.", - }); - } else { - toast("Error deleting recording", { - description: - "An error occurred while deleting the recording.", - }); - } - router.back(); - }} - > - Continue - - - - -
-
-
-
-
- ); -} - -export default function AudioPreview({ id }: { id: string }) { - return ( - - - - ); -}