Skip to content

Commit

Permalink
Adapt UI to use new wsId field
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Oct 21, 2024
1 parent cd5ebf1 commit 3f1dcc5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion frontend/viewer/src/ProjectView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
let newEntryDialog: NewEntryDialog;
async function openNewEntryDialog(text: string, options?: NewEntryDialogOptions): Promise<IEntry | undefined> {
const defaultWs = $writingSystems?.vernacular[0].id;
const defaultWs = $writingSystems?.vernacular[0].wsId;
if (defaultWs === undefined) return undefined;
const entry = await newEntryDialog.openWithValue({lexemeForm: {[defaultWs]: text}});
if (entry) onEntryCreated(entry, options);
Expand Down
24 changes: 12 additions & 12 deletions frontend/viewer/src/lib/DictionaryEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
const vernacularColor: Record<string, typeof vernacularColors[number]> = {};
const analysisColor: Record<string, typeof analysisColors[number]> = {};
vernacular.forEach((ws, i) => {
vernacularColor[ws.id] = vernacularColors[i % vernacularColors.length];
vernacularColor[ws.wsId] = vernacularColors[i % vernacularColors.length];
});
analysis.forEach((ws, i) => {
analysisColor[ws.id] = analysisColors[i % analysisColors.length];
analysisColor[ws.wsId] = analysisColors[i % analysisColors.length];
});
return (ws: string, type: 'vernacular' | 'analysis') => {
const colors = type === 'vernacular' ? vernacularColor : analysisColor;
Expand All @@ -42,7 +42,7 @@
});
$: headwords = $allWritingSystems.vernacular
.map(ws => ({ws: ws.id, value: headword(entry, ws.id)}))
.map(ws => ({ws: ws.wsId, value: headword(entry, ws.wsId)}))
.filter(({value}) => !!value);
const partsOfSpeech = usePartsOfSpeech();
Expand Down Expand Up @@ -74,31 +74,31 @@
{/if}
<span>
{#each $allWritingSystems.analysis as ws}
{#if sense.gloss[ws.id] || sense.definition[ws.id]}
{#if sense.gloss[ws.wsId] || sense.definition[ws.wsId]}
<span class="ml-0.5">
<sub class="-mr-0.5">{ws.abbreviation}</sub>
{#if sense.gloss[ws.id]}
<span class={$wsColor(ws.id, 'analysis')}>{sense.gloss[ws.id]}</span>;
{#if sense.gloss[ws.wsId]}
<span class={$wsColor(ws.wsId, 'analysis')}>{sense.gloss[ws.wsId]}</span>;
{/if}
{#if sense.definition[ws.id]}
<span class={$wsColor(ws.id, 'analysis')}>{sense.definition[ws.id]}</span>
{#if sense.definition[ws.wsId]}
<span class={$wsColor(ws.wsId, 'analysis')}>{sense.definition[ws.wsId]}</span>
{/if}
</span>
{/if}
{/each}
</span>
{#each sense.exampleSentences as example (example.id)}
{@const usedVernacular = $allWritingSystems.vernacular.filter(ws => !!example.sentence[ws.id])}
{@const usedAnalysis = $allWritingSystems.analysis.filter(ws => !!example.translation[ws.id])}
{@const usedVernacular = $allWritingSystems.vernacular.filter(ws => !!example.sentence[ws.wsId])}
{@const usedAnalysis = $allWritingSystems.analysis.filter(ws => !!example.translation[ws.wsId])}
{#if usedVernacular.length || usedAnalysis.length}
<span class="-mr-0.5">[</span>
{#each usedVernacular as ws}
<span class={$wsColor(ws.id, 'vernacular')}>{example.sentence[ws.id]}</span>
<span class={$wsColor(ws.wsId, 'vernacular')}>{example.sentence[ws.wsId]}</span>
<span></span><!-- standardizes whitespace between texts -->
{/each}
<span></span>
{#each usedAnalysis as ws}
<span class={$wsColor(ws.id, 'analysis')}>{example.translation[ws.id]}</span>
<span class={$wsColor(ws.wsId, 'analysis')}>{example.translation[ws.wsId]}</span>
<span></span><!-- standardizes whitespace between texts -->
{/each}
<span class="-ml-0.5">]</span>
Expand Down
10 changes: 5 additions & 5 deletions frontend/viewer/src/lib/entry-data.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { IEntry, WritingSystems } from './mini-lcm';
import type {IEntry, WritingSystems} from './mini-lcm';

export const projectName = 'Sena 3';

export const writingSystems: WritingSystems = {
'analysis': [
{
'id': 'en',
'wsId': 'en',
'name': 'English',
'abbreviation': 'Eng',
'font': '???',
'exemplars': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
},
{
'id': 'pt',
'wsId': 'pt',
'name': 'Portuguese',
'abbreviation': 'Por',
'font': '???',
Expand All @@ -21,14 +21,14 @@ export const writingSystems: WritingSystems = {
],
'vernacular': [
{
'id': 'seh',
'wsId': 'seh',
'name': 'Sena',
'abbreviation': 'Sen',
'font': '???',
'exemplars': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
},
{
'id': 'seh-fonipa-x-etic',
'wsId': 'seh-fonipa-x-etic',
'name': 'Sena',
'abbreviation': 'seh',
'font': '???',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
let currentView = useCurrentView();
$: writingSystems = pickWritingSystems(wsType, $allWritingSystems);
$: empty = !writingSystems.some((ws) => value[ws.id] || unsavedChanges[ws.id]);
$: empty = !writingSystems.some((ws) => value[ws.wsId] || unsavedChanges[ws.wsId]);
$: collapse = empty && writingSystems.length > 1;
</script>

<div class="multi-field field" class:collapse-field={collapse} class:empty class:hidden={!$currentView.fields[id].show} style:grid-area={id}>
<FieldTitle {id} {name} />
<div class="fields">
{#each writingSystems as ws (ws.id)}
{#each writingSystems as ws (ws.wsId)}
<CrdtTextField
on:change={() => dispatch('change', { value })}
bind:value={value[ws.id]}
bind:unsavedChanges={unsavedChanges[ws.id]}
bind:value={value[ws.wsId]}
bind:unsavedChanges={unsavedChanges[ws.wsId]}
label={collapse ? undefined : ws.abbreviation}
labelPlacement={collapse ? undefined : 'left'}
placeholder={collapse ? ws.abbreviation : undefined}
Expand Down
2 changes: 1 addition & 1 deletion frontend/viewer/src/lib/in-memory-api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class InMemoryApiService implements LexboxApiClient {

private ApplyQueryOptions(entries: IEntry[], options: QueryOptions | undefined): IEntry[] {
if (!options) return entries;
const defaultWs = writingSystems.vernacular[0].id;
const defaultWs = writingSystems.vernacular[0].wsId;
if (options.exemplar?.value) {
const lowerExemplar = options.exemplar.value.toLowerCase();
const exemplarWs = pickWs(options.exemplar.writingSystem, defaultWs);
Expand Down
1 change: 1 addition & 0 deletions frontend/viewer/src/lib/mini-lcm/writing-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

export interface WritingSystem {
id: string;
wsId: string;
name: string;
abbreviation: string;
font: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/viewer/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function pickBestAlternative(value: IMultiString, firstChoice?: WritingSy
} else if (typeof firstChoice === 'object') {
ws = firstChoice;
}
const pick = ws ? value[ws.id] : undefined;
const pick = ws ? value[ws.wsId] : undefined;
return pick ?? firstVal(value) ?? '';
}

Expand Down

0 comments on commit 3f1dcc5

Please sign in to comment.