Skip to content

Commit 46b53e3

Browse files
committed
[DataEntryTable] Click recent entries to edit
1 parent 2fc573e commit 46b53e3

File tree

2 files changed

+115
-20
lines changed

2 files changed

+115
-20
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Edit } from "@mui/icons-material";
2+
import { Grid2 } from "@mui/material";
3+
import { ReactElement, memo } from "react";
4+
5+
import { Word, WritingSystem } from "api/models";
6+
import { NoteButton } from "components/Buttons";
7+
import { AudioSummary } from "components/WordCard";
8+
import theme from "types/theme";
9+
import { TypographyWithFont } from "utilities/fontComponents";
10+
import { firstGlossText } from "utilities/wordUtilities";
11+
12+
const idAffix = "recent-entry";
13+
14+
export interface RecentEntryProps {
15+
analysisLang: WritingSystem;
16+
entry: Word;
17+
rowIndex: number;
18+
senseGuid: string;
19+
}
20+
21+
/** Displays a recently entered word that a user cannot edit. */
22+
export function RecentEntryCold(props: RecentEntryProps): ReactElement {
23+
const sense = props.entry.senses.find((s) => s.guid === props.senseGuid);
24+
const gloss = sense ? firstGlossText(sense, props.analysisLang.bcp47) : "";
25+
26+
return (
27+
<Grid2 alignItems="center" container id={`${idAffix}-${props.rowIndex}`}>
28+
<Grid2
29+
size={4}
30+
style={{ paddingInline: theme.spacing(2), position: "relative" }}
31+
>
32+
<TypographyWithFont vernacular>
33+
{props.entry.vernacular}
34+
</TypographyWithFont>
35+
</Grid2>
36+
37+
<Grid2
38+
size={4}
39+
style={{ paddingInline: theme.spacing(2), position: "relative" }}
40+
>
41+
<TypographyWithFont analysis lang={props.analysisLang.bcp47}>
42+
{gloss}
43+
</TypographyWithFont>
44+
</Grid2>
45+
46+
<Grid2
47+
size={1}
48+
style={{ paddingInline: theme.spacing(1), position: "relative" }}
49+
>
50+
{props.entry.note.text ? (
51+
<NoteButton disabled noteText={props.entry.note.text} />
52+
) : null}
53+
</Grid2>
54+
55+
<Grid2
56+
size={1}
57+
style={{ paddingInline: theme.spacing(1), position: "relative" }}
58+
>
59+
<AudioSummary count={props.entry.audio.length} />
60+
</Grid2>
61+
62+
<Grid2 size={1} />
63+
64+
<Grid2
65+
size={1}
66+
style={{ paddingInline: theme.spacing(1), position: "relative" }}
67+
>
68+
<Edit />
69+
</Grid2>
70+
</Grid2>
71+
);
72+
}
73+
74+
export default memo(RecentEntryCold);

src/components/DataEntry/DataEntryTable/index.tsx

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import * as backend from "backend";
2727
import { getCurrentUser, getUserId } from "backend/localStorage";
2828
import NewEntry from "components/DataEntry/DataEntryTable/NewEntry";
2929
import RecentEntry from "components/DataEntry/DataEntryTable/RecentEntry";
30+
import { RecentEntryCold } from "components/DataEntry/DataEntryTable/RecentEntryCold";
3031
import {
3132
filterWordsWithSenses,
3233
focusInput,
@@ -35,7 +36,6 @@ import { uploadFileFromPronunciation } from "components/Pronunciations/utilities
3536
import { useAppSelector } from "rootRedux/hooks";
3637
import { type StoreState } from "rootRedux/types";
3738
import { type Hash } from "types/hash";
38-
import theme from "types/theme";
3939
import {
4040
FileWithSpeakerId,
4141
newGloss,
@@ -214,6 +214,7 @@ const defaultNewEntryState = (): NewEntryState => ({
214214
interface EntryTableState extends NewEntryState {
215215
defunctUpdates: Hash<string>;
216216
defunctWordIds: Hash<DefunctStatus>;
217+
recentWordEditingIndex: number | undefined;
217218
recentWords: WordAccess[];
218219
senseSwitches: SenseSwitch[];
219220
}
@@ -222,6 +223,7 @@ const defaultEntryTableState = (): EntryTableState => ({
222223
...defaultNewEntryState(),
223224
defunctUpdates: {},
224225
defunctWordIds: {},
226+
recentWordEditingIndex: undefined,
225227
recentWords: [],
226228
senseSwitches: [],
227229
});
@@ -1016,7 +1018,7 @@ export default function DataEntryTable(
10161018

10171019
return (
10181020
<form onSubmit={(e?: FormEvent<HTMLFormElement>) => e?.preventDefault()}>
1019-
<Grid2 container rowSpacing={theme.spacing(2)}>
1021+
<Grid2 container rowSpacing={1}>
10201022
<Grid2 size={4}>
10211023
<Typography align="center" variant="h5">
10221024
{t("addWords.vernacular")}
@@ -1033,25 +1035,44 @@ export default function DataEntryTable(
10331035
<Grid2
10341036
key={`${wordAccess.word.id}_${wordAccess.senseGuid}`}
10351037
size={12}
1038+
sx={{ borderBottom: "1px solid #eee" }}
10361039
>
1037-
<RecentEntry
1038-
rowIndex={index}
1039-
entry={wordAccess.word}
1040-
senseGuid={wordAccess.senseGuid}
1041-
updateGloss={updateRecentGloss}
1042-
updateNote={updateRecentNote}
1043-
updateVern={updateRecentVern}
1044-
removeEntry={undoRecentEntry}
1045-
addAudioToWord={addAudioFileToWord}
1046-
delAudioFromWord={deleteAudioFromWord}
1047-
repAudioInWord={replaceAudioInWord}
1048-
focusNewEntry={handleFocusNewEntry}
1049-
analysisLang={analysisLang}
1050-
vernacularLang={vernacularLang}
1051-
disabled={Object.keys(state.defunctWordIds).includes(
1052-
wordAccess.word.id
1053-
)}
1054-
/>
1040+
{index === state.recentWordEditingIndex ? (
1041+
<RecentEntry
1042+
rowIndex={index}
1043+
entry={wordAccess.word}
1044+
senseGuid={wordAccess.senseGuid}
1045+
updateGloss={updateRecentGloss}
1046+
updateNote={updateRecentNote}
1047+
updateVern={updateRecentVern}
1048+
removeEntry={undoRecentEntry}
1049+
addAudioToWord={addAudioFileToWord}
1050+
delAudioFromWord={deleteAudioFromWord}
1051+
repAudioInWord={replaceAudioInWord}
1052+
focusNewEntry={handleFocusNewEntry}
1053+
analysisLang={analysisLang}
1054+
vernacularLang={vernacularLang}
1055+
disabled={Object.keys(state.defunctWordIds).includes(
1056+
wordAccess.word.id
1057+
)}
1058+
/>
1059+
) : (
1060+
<div
1061+
onClick={() =>
1062+
setState((prev) => ({
1063+
...prev,
1064+
recentWordEditingIndex: index,
1065+
}))
1066+
}
1067+
>
1068+
<RecentEntryCold
1069+
analysisLang={analysisLang}
1070+
entry={wordAccess.word}
1071+
rowIndex={index}
1072+
senseGuid={wordAccess.senseGuid}
1073+
/>
1074+
</div>
1075+
)}
10551076
</Grid2>
10561077
))}
10571078

0 commit comments

Comments
 (0)