Skip to content

Commit

Permalink
So close
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirazad committed Jul 10, 2024
1 parent ddd7b86 commit 486203b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",
"dev": "next dev --turbo",
"dev": "next dev",
"lint": "next lint",
"start": "next start"
},
Expand Down
9 changes: 4 additions & 5 deletions src/app/api/whishperRecording/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { getUserData } from "@/app/actions";
import { getWhishperRecordings } from "@/app/whishper/page";

export async function DELETE(req: Request) {
const url = new URL(req.url);
const name = url.searchParams.get("name");
const id = url.searchParams.get("id");

if (!name) {
return new Response("Name parameter is missing", { status: 400 });
if (!id) {
return new Response("id parameter is missing", { status: 400 });
}

const userData = await getUserData();
Expand All @@ -16,7 +15,7 @@ export async function DELETE(req: Request) {
}

const response = await fetch(
`${userData.whishperURL}/api/transcriptions/${name}`,
`${userData.whishperURL}/api/transcriptions/${id}`,
{
method: "DELETE",
},
Expand Down
4 changes: 2 additions & 2 deletions src/app/whishper/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import type { WhishperRecordingType } from "@/types";

const queryClient = new QueryClient();

export async function getWhishperRecordings(
async function getWhishperRecordings(
query: string,
): Promise<WhishperRecordingType[] | null> {
const userData = await getUserData();
Expand Down Expand Up @@ -224,7 +224,7 @@ function DataTable<TData extends WhishperRecordingType>({
header: "Name",
cell: ({ getValue, row }) => (
<OpenInternalLink
href={`/whishper/recording/${row.original.fileName}?query=${query}`}
href={`/whishper/recording/${row.original.id}?query=${query}`}
>
{getValue() as string}
</OpenInternalLink>
Expand Down
61 changes: 35 additions & 26 deletions src/components/audio-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
} from "@/components/ui/tooltip";
import { useState } from "react";
import { getWhishperRecordings } from "@/app/whishper/page";
import OpenExternalLink from "./external-link";
import { SimpleWhishperTranscription, WhishperRecordingType } from "@/types";

const queryClient = new QueryClient();

Expand Down Expand Up @@ -54,32 +56,45 @@ function SkeletonLoader() {
);
}

function AudioInfo(props: { name: string }) {
async function fetchWhishperRecording(
searchId: string,
userData: UsersTableType,
) {
const response = await fetch(`${userData.whishperURL}/api/transcriptions`);
const data = (await response.json()) as WhishperRecordingType[];
for (const recording of data) {
if (recording.id === searchId) {
return recording;
}
}
}

function AudioInfo(props: { id: string }) {
const router = useRouter();
const [isPlaying, setIsPlaying] = useState(false);

console.log(getWhishperRecordings(props.name));

const {
data: userData,
isLoading: isUserDataLoading,
error,
} = useQuery({
const { data: userData, isLoading: isUserDataLoading } = useQuery({
queryKey: ["userData"],
queryFn: fetchUserData,
});

const decodedName = decodeURIComponent(props.name);
const frontPart = decodedName.split("_WHSHPR_")[1] ?? decodedName;
const formattedName = frontPart.replace(".m4a", "") ?? decodedName;
const { data: recordingData, isLoading: isRecordingDataLoading } = useQuery({
queryKey: ["whishperRecording", props.idgt modify -cam "So close"], // Include id in the query key
queryFn: () => fetchWhishperRecording(props.id, userData),
enabled: !!userData, // Only fetch recording data when userData is available
});

if (isUserDataLoading) {
if (isUserDataLoading ?? isRecordingDataLoading) {
return <SkeletonLoader />;
}
if (!userData?.whishperURL ?? error) {
return <h1>Failed to get whishper url</h1>;
if (!userData?.whishperURL ?? !recordingData) {
return <h1>Failed</h1>;
}

const decodedName = decodeURIComponent(recordingData.fileName);
const frontPart = decodedName.split("_WHSHPR_")[1] ?? decodedName;
const formattedName = frontPart.replace(".m4a", "") ?? decodedName;

return (
<div className="flex w-full justify-center">
<div className="flex h-full justify-center md:w-1/2">
Expand Down Expand Up @@ -121,7 +136,9 @@ function AudioInfo(props: { name: string }) {
className="cursor-not-allowed opacity-50"
>
<Button className="w-24">
<ExternalLink /> Open
<OpenExternalLink href={`${userData.whishperURL}`}>
Open
</OpenExternalLink>
</Button>
</TooltipTrigger>
<TooltipContent>Comming soon!</TooltipContent>
Expand All @@ -146,15 +163,7 @@ function AudioInfo(props: { name: string }) {
tabIndex={-1}
className="cursor-not-allowed opacity-50"
>
<Button
className="w-24"
variant="destructive"
onClick={() => {
fetch("/api/deleteWhishperRecording" + id, {
method: "DELETE",
});
}}
>
<Button className="w-24" variant="destructive">
Delete
</Button>
</TooltipTrigger>
Expand All @@ -169,10 +178,10 @@ function AudioInfo(props: { name: string }) {
);
}

export default function AudioPreview({ name }: { name: string }) {
export default function AudioPreview({ id }: { id: string }) {
return (
<QueryClientProvider client={queryClient}>
<AudioInfo name={name} />
<AudioInfo id={id} />
</QueryClientProvider>
);
}
15 changes: 14 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,20 @@ export type WhishperRecordingType = {
}[];
text: string;
};
translations: [];
translations: Translation[];
};

type Translation = {
sourceLanguage: string;
targetLanguage: string;
text: string;
segments: [];
};

export type SimpleWhishperTranscription = {
id: string;
duration: number;
name: string;
};

export type AdviceAPIType = {
Expand Down

0 comments on commit 486203b

Please sign in to comment.