Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 26 additions & 36 deletions apps/desktop/src/components/right-panel/views/transcript-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { useHypr } from "@/contexts";
import { commands as dbCommands, Human, Word } from "@hypr/plugin-db";
import { commands as miscCommands } from "@hypr/plugin-misc";
import TranscriptEditor, {
getSpeakerLabel,
SPEAKER_ID_ATTR,
SPEAKER_INDEX_ATTR,
SPEAKER_LABEL_ATTR,
type SpeakerChangeRange,
type SpeakerViewInnerProps,
type TranscriptEditorRef,
Expand Down Expand Up @@ -310,6 +314,7 @@ const MemoizedSpeakerSelector = memo(({
onSpeakerChange,
speakerId,
speakerIndex,
speakerLabel,
}: SpeakerViewInnerProps) => {
const { userId } = useHypr();
const [isOpen, setIsOpen] = useState(false);
Expand All @@ -320,29 +325,11 @@ const MemoizedSpeakerSelector = memo(({
const noteMatch = useMatch({ from: "/app/note/$id", shouldThrow: false });
const sessionId = noteMatch?.params.id;

const { data: participants = [] } = useQuery({
enabled: !!sessionId,
queryKey: ["participants", sessionId!, "selector"],
queryFn: () => dbCommands.sessionListParticipants(sessionId!),
});

useEffect(() => {
if (human) {
onSpeakerChange(human, speakerRange);
}
}, [human]);

useEffect(() => {
if (participants.length === 1 && participants[0]) {
setHuman(participants[0]);
return;
}

const foundHuman = participants.find((s) => s.id === speakerId);
if (foundHuman) {
setHuman(foundHuman);
}
}, [participants, speakerId]);
}, [human, speakerRange]);

const handleClickHuman = (human: Human) => {
setHuman(human);
Expand All @@ -358,13 +345,19 @@ const MemoizedSpeakerSelector = memo(({
}

const getDisplayName = (human: Human | null) => {
if (!human) {
return `Speaker ${speakerIndex ?? 0}`;
}
if (human.id === userId && !human.full_name) {
return "You";
if (human) {
if (human.id === userId && !human.full_name) {
return "You";
}

return human.full_name ?? human.id;
}
return human.full_name ?? `Speaker ${speakerIndex ?? 0}`;

return getSpeakerLabel({
[SPEAKER_INDEX_ATTR]: speakerIndex,
[SPEAKER_ID_ATTR]: speakerId,
[SPEAKER_LABEL_ATTR]: speakerLabel ?? null,
});
};

return (
Expand All @@ -381,14 +374,12 @@ const MemoizedSpeakerSelector = memo(({
</PopoverTrigger>
<PopoverContent align="start" side="bottom">
<div className="space-y-4">
{!speakerId && (
<div className="border-b border-neutral-100 pb-3">
<SpeakerRangeSelector
value={speakerRange}
onChange={setSpeakerRange}
/>
</div>
)}
<div className="border-b border-neutral-100 pb-3">
<SpeakerRangeSelector
value={speakerRange}
onChange={setSpeakerRange}
/>
</div>

<ParticipantsChipInner sessionId={sessionId} handleClickHuman={handleClickHuman} />
</div>
Expand Down Expand Up @@ -417,7 +408,7 @@ function SpeakerRangeSelector({ value, onChange }: SpeakerRangeSelectorProps) {
{options.map((option) => (
<label
key={option.value}
className={`flex-1 ${option.value === "current" ? "cursor-pointer" : "cursor-not-allowed"}`}
className="flex-1 cursor-pointer"
>
<input
type="radio"
Expand All @@ -426,14 +417,13 @@ function SpeakerRangeSelector({ value, onChange }: SpeakerRangeSelectorProps) {
className="sr-only"
checked={value === option.value}
onChange={() => onChange(option.value)}
disabled={option.value !== "current"}
/>
<div
className={`px-2 py-1 text-xs font-medium text-center rounded transition-colors ${
value === option.value
? "bg-white text-neutral-900 shadow-sm"
: "text-neutral-600 hover:text-neutral-900 hover:bg-white/50"
} ${option.value !== "current" ? "opacity-50" : ""}`}
}`}
>
{option.label}
</div>
Expand Down
2 changes: 2 additions & 0 deletions crates/data/src/english_6/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub const WORDS_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/src/english_6/words.json");
pub const WORDS_JSON: &str = include_str!("./words.json");
Loading