-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SummarySenseCard] Add glosses and bg color (#3109)
- Loading branch information
1 parent
8be0003
commit 63563d9
Showing
5 changed files
with
108 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { type ReactElement } from "react"; | ||
|
||
import { type Sense } from "api/models"; | ||
import { TypographyWithFont } from "utilities/fontComponents"; | ||
|
||
interface SensesTextSummaryProp { | ||
definitionsOrGlosses: "definitions" | "glosses"; | ||
maxLengthPerSense?: number; | ||
senses: Sense[]; | ||
} | ||
|
||
export default function SensesTextSummary( | ||
props: SensesTextSummaryProp | ||
): ReactElement { | ||
const ellipses = "[...]"; | ||
const interSenseSep = " | "; | ||
const intraSenseSep = "; "; | ||
|
||
const typographies: ReactElement[] = []; | ||
|
||
props.senses.forEach((sense) => { | ||
let texts: string[]; | ||
switch (props.definitionsOrGlosses) { | ||
case "definitions": | ||
texts = sense.definitions.map((d) => d.text.trim()); | ||
break; | ||
case "glosses": | ||
texts = sense.glosses.map((g) => g.def.trim()); | ||
break; | ||
} | ||
let text = texts.filter((t) => t).join(intraSenseSep); | ||
if (!text) { | ||
return; | ||
} | ||
|
||
if (props.maxLengthPerSense) { | ||
const maxLength = Math.max(props.maxLengthPerSense, ellipses.length + 1); | ||
if (text.length > maxLength) { | ||
text = `${text.substring(0, maxLength - ellipses.length)}${ellipses}`; | ||
} | ||
} | ||
|
||
// Add a sense separator if this isn't the first. | ||
if (typographies.length) { | ||
typographies.push( | ||
<TypographyWithFont analysis display="inline" key={`${sense.guid}-sep`}> | ||
{interSenseSep} | ||
</TypographyWithFont> | ||
); | ||
} | ||
|
||
// Use the analysis language of the first non-empty definition/gloss, if any. | ||
let lang: string | undefined; | ||
switch (props.definitionsOrGlosses) { | ||
case "definitions": | ||
lang = sense.definitions.find((d) => d.text.trim())?.language; | ||
break; | ||
case "glosses": | ||
lang = sense.glosses.find((g) => g.def.trim())?.language; | ||
break; | ||
} | ||
typographies.push( | ||
<TypographyWithFont | ||
analysis | ||
display="inline" | ||
key={`${sense.guid}-text`} | ||
lang={lang} | ||
> | ||
{text} | ||
</TypographyWithFont> | ||
); | ||
}); | ||
|
||
return <div>{typographies}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 8 additions & 41 deletions
49
src/goals/ReviewEntries/ReviewEntriesTable/Cells/DefinitionsCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,14 @@ | ||
import { type ReactElement } from "react"; | ||
|
||
import SensesTextSummary from "components/WordCard/SensesTextSummary"; | ||
import { type CellProps } from "goals/ReviewEntries/ReviewEntriesTable/Cells/CellTypes"; | ||
import { TypographyWithFont } from "utilities/fontComponents"; | ||
|
||
export default function DefinitionsCell(props: CellProps): ReactElement { | ||
const MAX_LENGTH = 75; | ||
const typographies: ReactElement[] = []; | ||
|
||
props.word.senses.forEach((sense) => { | ||
let text = sense.definitions | ||
.map((d) => d.text.trim()) | ||
.filter((t) => t) | ||
.join("; "); | ||
if (!text) { | ||
return; | ||
} | ||
|
||
if (text.length > MAX_LENGTH) { | ||
text = `${text.substring(0, MAX_LENGTH)}[...]`; | ||
} | ||
|
||
// Add a sense separator if this isn't the first. | ||
if (typographies.length) { | ||
typographies.push( | ||
<TypographyWithFont analysis display="inline" key={`${sense.guid}-sep`}> | ||
{" | "} | ||
</TypographyWithFont> | ||
); | ||
} | ||
|
||
// Use the analysis language of the first non-empty definition, if any. | ||
const lang = sense.definitions.find((d) => d.text.trim())?.language; | ||
typographies.push( | ||
<TypographyWithFont | ||
analysis | ||
display="inline" | ||
key={`${sense.guid}-text`} | ||
lang={lang} | ||
> | ||
{text} | ||
</TypographyWithFont> | ||
); | ||
}); | ||
|
||
return <div>{typographies}</div>; | ||
return ( | ||
<SensesTextSummary | ||
definitionsOrGlosses="definitions" | ||
maxLengthPerSense={75} | ||
senses={props.word.senses} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 8 additions & 41 deletions
49
src/goals/ReviewEntries/ReviewEntriesTable/Cells/GlossesCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,14 @@ | ||
import { type ReactElement } from "react"; | ||
|
||
import SensesTextSummary from "components/WordCard/SensesTextSummary"; | ||
import { type CellProps } from "goals/ReviewEntries/ReviewEntriesTable/Cells/CellTypes"; | ||
import { TypographyWithFont } from "utilities/fontComponents"; | ||
|
||
export default function GlossesCell(props: CellProps): ReactElement { | ||
const MAX_LENGTH = 50; | ||
const typographies: ReactElement[] = []; | ||
|
||
props.word.senses.forEach((sense) => { | ||
let text = sense.glosses | ||
.map((g) => g.def.trim()) | ||
.filter((t) => t) | ||
.join("; "); | ||
if (!text) { | ||
return; | ||
} | ||
|
||
if (text.length > MAX_LENGTH) { | ||
text = `${text.substring(0, MAX_LENGTH)}[...]`; | ||
} | ||
|
||
// Add a sense separator if this isn't the first. | ||
if (typographies.length) { | ||
typographies.push( | ||
<TypographyWithFont analysis display="inline" key={`${sense.guid}-sep`}> | ||
{" | "} | ||
</TypographyWithFont> | ||
); | ||
} | ||
|
||
// Use the analysis language of the first non-empty gloss, if any. | ||
const lang = sense.glosses.find((g) => g.def.trim())?.language; | ||
typographies.push( | ||
<TypographyWithFont | ||
analysis | ||
display="inline" | ||
key={`${sense.guid}-text`} | ||
lang={lang} | ||
> | ||
{text} | ||
</TypographyWithFont> | ||
); | ||
}); | ||
|
||
return <div>{typographies}</div>; | ||
return ( | ||
<SensesTextSummary | ||
definitionsOrGlosses="glosses" | ||
maxLengthPerSense={50} | ||
senses={props.word.senses} | ||
/> | ||
); | ||
} |