Skip to content
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

Refactor LineAccumulator #501

Merged
merged 4 commits into from
Jul 31, 2024
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
5 changes: 1 addition & 4 deletions src/transliteration/domain/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ export function lineAccFromColumns({
acc.addColumnToken(
token,
index,
isInLineGroup,
showMeter,
showIpa,
updatePhoneticPropsContext(column.content, index, phoneticProps),
_.isEmpty(_.intersection(token.uniqueLemma, highlightLemmas))
? []
Expand All @@ -72,7 +69,7 @@ export function lineAccFromColumns({
acc
)
return acc
}, new LineAccumulator())
}, new LineAccumulator(isInLineGroup, showMeter, showIpa))
}

export function numberOfColumns(columns: readonly TextLineColumn[]): number {
Expand Down
31 changes: 13 additions & 18 deletions src/transliteration/ui/LineAccumulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ export class LineAccumulator {
private enclosureOpened = false
private protocol: Protocol | null = null
private isFirstWord = true
private isInLineGroup = false
private showMeter = false
private showIpa = false
lemmas: string[] = []

constructor(isInLineGroup?: boolean, showMeter?: boolean, showIpa?: boolean) {
this.isInLineGroup = isInLineGroup || false
this.showMeter = showMeter || false
this.showIpa = showIpa || false
}

getColumns(maxColumns: number): React.ReactNode[] {
return this.columns.map((column: ColumnData, index: number) => (
<td key={index} colSpan={column.span ?? maxColumns}>
Expand Down Expand Up @@ -87,9 +96,6 @@ export class LineAccumulator {
pushToken(
token: Token,
index: number,
isInLineGroup = false,
showMeter = false,
showIpa = false,
phoneticProps?: PhoneticProps,
bemModifiers: string[] = []
): void {
Expand All @@ -100,7 +106,7 @@ export class LineAccumulator {
this.pushSeparator()
}

const DisplayTokenComponent = isInLineGroup
const DisplayTokenComponent = this.isInLineGroup
? DisplayLineGroupToken
: DisplayToken

Expand All @@ -110,8 +116,8 @@ export class LineAccumulator {
token={token}
bemModifiers={[...this.bemModifiers, ...bemModifiers]}
Wrapper={this.inGloss && !isEnclosure(token) ? GlossWrapper : undefined}
showMeter={showMeter}
showIpa={showIpa}
showMeter={this.showMeter}
showIpa={this.showIpa}
phoneticProps={phoneticProps}
/>
)
Expand Down Expand Up @@ -139,9 +145,6 @@ export class LineAccumulator {
addColumnToken(
token: Token,
index: number,
isInLineGroup?: boolean,
showMeter?: boolean,
showIpa?: boolean,
phoneticProps?: PhoneticProps,
bemModifiers: string[] = []
): void {
Expand All @@ -158,15 +161,7 @@ export class LineAccumulator {
case 'Column':
throw new Error('Unexpected column token.')
default:
this.pushToken(
token,
index,
isInLineGroup,
showMeter,
showIpa,
phoneticProps,
bemModifiers
)
this.pushToken(token, index, phoneticProps, bemModifiers)
this.pushLemma(token.uniqueLemma)
this.isFirstWord = false
}
Expand Down
3 changes: 0 additions & 3 deletions src/transliteration/ui/line-tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export function LineTokens({
acc.addColumnToken(
token,
index,
false,
false,
false,
{},
highlightTokens.includes(index) ? ['highlight'] : []
)
Expand Down
Loading