Skip to content

Commit

Permalink
DataEntry code/test cleanup (#2051)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Apr 18, 2023
1 parent b7ba947 commit fb27058
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 165 deletions.
20 changes: 6 additions & 14 deletions src/components/DataEntry/DataEntryComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interface DataEntryProps {

interface DataEntryState {
domain: SemanticDomainFull;
existingWords: Word[];
domainWords: DomainWord[];
isSmallScreen: boolean;
drawerOpen: boolean;
Expand Down Expand Up @@ -70,10 +69,10 @@ export function filterWordsByDomain(
}

export function sortDomainWordByVern(
existingWords: Word[],
words: Word[],
domain: SemanticDomain
): DomainWord[] {
const domainWords = filterWordsByDomain(existingWords, domain);
const domainWords = filterWordsByDomain(words, domain);
return domainWords.sort((a, b) => {
const comp = a.vernacular.localeCompare(b.vernacular);
return comp !== 0 ? comp : a.gloss.localeCompare(b.gloss);
Expand All @@ -96,7 +95,6 @@ export default class DataEntryComponent extends React.Component<
this.props.currentDomainTree.name,
this.props.currentDomainTree.lang
),
existingWords: [],
domainWords: [],
isSmallScreen: window.matchMedia("(max-width: 960px)").matches,
drawerOpen: false,
Expand All @@ -119,12 +117,6 @@ export default class DataEntryComponent extends React.Component<

toggleDrawer = (drawerOpen: boolean) => this.setState({ drawerOpen });

async getWordsFromBackend(): Promise<Word[]> {
const existingWords = await getFrontierWords();
this.setState({ existingWords });
return filterWords(existingWords);
}

render(): ReactElement {
return (
<Grid container justifyContent="center" spacing={3} wrap={"nowrap"}>
Expand Down Expand Up @@ -161,11 +153,11 @@ export default class DataEntryComponent extends React.Component<
<Dialog fullScreen open={!!this.props.treeIsOpen}>
<AppBar />
<TreeView
returnControlToCaller={() =>
this.getWordsFromBackend().then(() => {
this.setState((prevState, props) => ({
returnControlToCaller={async () =>
await getFrontierWords().then((words) => {
this.setState((_, props) => ({
domainWords: sortDomainWordByVern(
prevState.existingWords,
words,
props.currentDomainTree
),
}));
Expand Down
11 changes: 3 additions & 8 deletions src/components/DataEntry/DataEntryTable/DataEntryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default function DataEntryTable(
setState((prevState) => ({
...prevState,
isFetchingFrontier: false,
existingWords: existingWords,
existingWords,
}));
}
}, [innerGetWordsFromBackend, state.isFetchingFrontier]);
Expand All @@ -168,10 +168,7 @@ export default function DataEntryTable(
const defunctWordIds = state.defunctWordIds;
if (!defunctWordIds.includes(wordId)) {
defunctWordIds.push(wordId);
setState((prevState) => ({
...prevState,
defunctWordIds: defunctWordIds,
}));
setState((prevState) => ({ ...prevState, defunctWordIds }));
}
};

Expand Down Expand Up @@ -330,9 +327,7 @@ export default function DataEntryTable(
gloss: string,
audioFileURLs?: string[]
): Promise<void> => {
const existingWord = state.existingWords.find(
(word: Word) => word.id === wordId
);
const existingWord = state.existingWords.find((w: Word) => w.id === wordId);
if (!existingWord) {
throw new Error("You are trying to update a nonexistent word");
}
Expand Down
Loading

0 comments on commit fb27058

Please sign in to comment.