-
Notifications
You must be signed in to change notification settings - Fork 5
User benchmarks #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
User benchmarks #55
Changes from all commits
8d35f9f
f3720aa
a7c7b6d
4c6edab
9249a6d
fef10f4
1f77b7d
10121b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import useAuthUser from "@/hooks/useAuthUser"; | ||
| import { ScribeModel } from "@/types"; | ||
| import { Button } from "./ui/button"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { I18NNAMESPACE } from "@/utils/constants"; | ||
| import { Dialog, DialogContent, DialogTitle, DialogTrigger } from "./ui/dialog"; | ||
| import { useContainerRef } from "@/hooks/useContainerRef"; | ||
| import { useStorage } from "@/hooks/useStorage"; | ||
| import { CreatedBenchmark } from "@/pages/Benchmark"; | ||
| import { useState } from "react"; | ||
| import { Input } from "./ui/input"; | ||
| import { openDB, putAudio } from "@/utils/idb"; | ||
|
|
||
| export default function CreateBenchmark(props: { | ||
| scribe: ScribeModel; | ||
| formState: unknown; | ||
| }) { | ||
| const { t } = useTranslation(I18NNAMESPACE); | ||
| const containerRef = useContainerRef(); | ||
| const [createdBenchmarks, setCreatedBenchmarks] = useStorage( | ||
| "scribe-created-benchmarks", | ||
| ); | ||
| const [name, setName] = useState(""); | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
| const { scribe, formState } = props; | ||
|
|
||
| const user = useAuthUser(); | ||
|
|
||
| const handleCreateBenchmark = async () => { | ||
| if (!scribe) { | ||
| alert(t("no_scribe_to_benchmark")); | ||
|
||
| return; | ||
| } | ||
|
|
||
| const storedIdentifier = crypto.randomUUID(); | ||
| const db = await openDB(); | ||
|
|
||
| for (const audio of scribe.audio) { | ||
| const response = await fetch(audio.read_signed_url); | ||
| const arrayBuffer = await response.arrayBuffer(); | ||
|
|
||
| await putAudio(db, storedIdentifier, { | ||
| identifier: storedIdentifier, | ||
| mimeType: audio.mime_type, | ||
| data: arrayBuffer, | ||
| }); | ||
| } | ||
|
|
||
| db.close(); | ||
|
|
||
| const form: any = formState ? formState : []; | ||
|
||
| const newBenchmark: CreatedBenchmark = { | ||
| name: name || `Benchmark ${createdBenchmarks.length + 1}`, | ||
| id: crypto.randomUUID(), | ||
| createdAt: new Date(), | ||
| files: scribe.audio.map((a) => ({ | ||
| identifier: storedIdentifier, | ||
| type: "audio", | ||
| mimeType: a.mime_type, | ||
| })), | ||
| formState: form, | ||
| }; | ||
| setCreatedBenchmarks((prev) => [...prev, newBenchmark]); | ||
| setOpen(false); | ||
| }; | ||
|
|
||
| if (!user?.is_superuser) return null; | ||
|
|
||
| return ( | ||
| <Dialog open={open} onOpenChange={setOpen}> | ||
| <DialogTrigger asChild> | ||
| <Button>{t("create_benchmark")}</Button> | ||
| </DialogTrigger> | ||
| <DialogContent portalProps={{ container: containerRef?.current }}> | ||
| <DialogTitle className="text-lg font-semibold"> | ||
| {t("create_benchmark")}? | ||
| </DialogTitle> | ||
| <p>{t("create_benchmark_information")}</p> | ||
| <Input | ||
| className="mt-4" | ||
| placeholder={t("benchmark_name") || ""} | ||
| value={name} | ||
| onChange={(e) => setName(e.target.value)} | ||
| /> | ||
| <Button onClick={handleCreateBenchmark}>{t("create_benchmark")}</Button> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ohcnetwork/care_scribe_fe
Length of output: 51
🏁 Script executed:
Repository: ohcnetwork/care_scribe_fe
Length of output: 98
🏁 Script executed:
rg -n "useAuthUser" --type tsxRepository: ohcnetwork/care_scribe_fe
Length of output: 96
🏁 Script executed:
Repository: ohcnetwork/care_scribe_fe
Length of output: 1441
🏁 Script executed:
rg "useAuthUser" src/components/Controller.tsxRepository: ohcnetwork/care_scribe_fe
Length of output: 115
🏁 Script executed:
Repository: ohcnetwork/care_scribe_fe
Length of output: 102
🏁 Script executed:
Repository: ohcnetwork/care_scribe_fe
Length of output: 372
🏁 Script executed:
cat tsconfig.json | head -50Repository: ohcnetwork/care_scribe_fe
Length of output: 281
🏁 Script executed:
cat -n src/components/CreateBenchmark.tsx | head -60Repository: ohcnetwork/care_scribe_fe
Length of output: 2307
🏁 Script executed:
Repository: ohcnetwork/care_scribe_fe
Length of output: 245
Remove unused
useAuthUserimport to fix TS6133 build erroruseAuthUseris imported but never used in this file. SincenoUnusedLocalsis enabled intsconfig.app.json, this triggers TS6133. The auth gating already happens insideCreateBenchmark(line 42), so this import can be safely removed.Apply this diff:
📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: Build and Deploy
[error] 54-54: TS6133: 'useAuthUser' is declared but its value is never read.
🪛 GitHub Check: build
[failure] 54-54:
'useAuthUser' is declared but its value is never read.
🤖 Prompt for AI Agents