Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
extract AnnotationLineColumns
  • Loading branch information
fsimonjetz committed Aug 1, 2024
1 parent 384d04f commit e37da95
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 69 deletions.
73 changes: 73 additions & 0 deletions src/transliteration/ui/annotation-line-tokens.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from 'react'
import {
annotationLineAccFromColumns,
TextLineColumn,
} from 'transliteration/domain/columns'
import { TextLine } from 'transliteration/domain/text-line'
import { LineNumber } from './line-number'

export function AnnotationLineColumns({
line,
lineIndex,
columns,
maxColumns,
}: {
line: TextLine
lineIndex: number
columns: readonly TextLineColumn[]
maxColumns: number
}): JSX.Element {
const lineAccumulator = annotationLineAccFromColumns(columns)

const sourceTextLine = (
<tr className={'annotation-line__source'}>
<td>
<LineNumber line={line} />
</td>
{lineAccumulator.flatResult.map((token, index) => {
return (
<td key={index}>
<span
onClick={() =>
console.log(
`clicked on token ${token.token.cleanValue} at line=${lineIndex}, index=${index}`,
token.token
)
}
>
{token.display()}
</span>
</td>
)
})}
</tr>
)
const lemmaAnnotationLayer = (
<tr className={'annotation-line__lemmatization'}>
<td></td>
{lineAccumulator.flatResult.map((token, index) => {
return (
<td key={index}>
<span
onClick={() =>
console.log(
`clicked on lemma of token ${token.token.cleanValue} at line=${lineIndex}, index=${index}`,
token.token
)
}
>
{token.token.uniqueLemma}
</span>
</td>
)
})}
</tr>
)

return (
<>
{sourceTextLine}
{lemmaAnnotationLayer}
</>
)
}
69 changes: 0 additions & 69 deletions src/transliteration/ui/line-tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import {
} from './LineLemmasContext'
import { LineAccumulator } from './LineAccumulator'
import {
annotationLineAccFromColumns,
lineAccFromColumns,
TextLineColumn,
} from 'transliteration/domain/columns'
import { PhoneticProps } from 'akkadian/application/phonetics/segments'
import { TextLine } from 'transliteration/domain/text-line'
import { LineNumber } from './line-number'

export function LineTokens({
content,
Expand Down Expand Up @@ -83,72 +80,6 @@ export function LineColumns({
)
}

export function AnnotationLineColumns({
line,
lineIndex,
columns,
maxColumns,
}: {
line: TextLine
lineIndex: number
columns: readonly TextLineColumn[]
maxColumns: number
}): JSX.Element {
const lineAccumulator = annotationLineAccFromColumns(columns)

const sourceTextLine = (
<tr className={'annotation-line__source'}>
<td>
<LineNumber line={line} />
</td>
{lineAccumulator.flatResult.map((token, index) => {
return (
<td key={index}>
<span
onClick={() =>
console.log(
`clicked on token ${token.token.cleanValue} at line=${lineIndex}, index=${index}`,
token.token
)
}
>
{token.display()}
</span>
</td>
)
})}
</tr>
)
const lemmaAnnotationLayer = (
<tr className={'annotation-line__lemmatization'}>
<td></td>
{lineAccumulator.flatResult.map((token, index) => {
return (
<td key={index}>
<span
onClick={() =>
console.log(
`clicked on lemma of token ${token.token.cleanValue} at line=${lineIndex}, index=${index}`,
token.token
)
}
>
{token.token.uniqueLemma}
</span>
</td>
)
})}
</tr>
)

return (
<>
{sourceTextLine}
{lemmaAnnotationLayer}
</>
)
}

export class LineToken {
token: LemmatizableToken
lemma: DictionaryWord[] | null = null
Expand Down

0 comments on commit e37da95

Please sign in to comment.