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

Display Lexical Words #745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@
},
"volta": {
"node": "20.9.0"
},
"dependencies": {
"sql.js": "^1.12.0"
}
}
14 changes: 10 additions & 4 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import contents from '$lib/data/contents';
import { isFirstLaunch, audioActive } from '$lib/data/stores';
import { navigateToTextReference } from '$lib/navigate';
import config from '$lib/data/config';

onMount(async () => {
if (config.programType === 'DAB') {
await goto(`${base}/lexicon`);
return;
}

onMount(() => {
const launchAction = contents?.features?.['launch-action'];
if ($page.data?.audio) {
$audioActive = $page.data.audio === '1';
}
if ($page.data?.ref) {
navigateToTextReference($page.data.ref);
await navigateToTextReference($page.data.ref);
} else if (launchAction === 'contents' || ($isFirstLaunch && launchAction)) {
goto(`${base}/contents/1`);
await goto(`${base}/contents/1`);
} else {
goto(`${base}/text`);
await goto(`${base}/text`);
}
});
</script>
37 changes: 37 additions & 0 deletions src/routes/lexicon/+page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { base } from '$app/paths';
import initSqlJs from 'sql.js';

export async function load({ fetch }) {
const SQL = await initSqlJs({
locateFile: (file) => `https://sql.js.org/dist/${file}`
});

// Fetch the database file
const response = await fetch(`${base}/data.sqlite`);
const buffer = await response.arrayBuffer();

// Load the database into sql.js
const db = new SQL.Database(new Uint8Array(buffer));
console.log('Database loaded:', db);

// Example: Running a simple query
const results = db.exec(
'SELECT id, name, homonym_index, type, num_senses, summary FROM entries'
);
const result = results[0];
console.log(result);

const entries = [];
for (let value of result.values) {
const entry = {};
for (let i = 0; i < result.columns.length; ++i) {
entry[result.columns[i]] = value[i];
}
entries.push(entry);
}
console.log(entries);

return {
entries
};
}
32 changes: 32 additions & 0 deletions src/routes/lexicon/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script lang="ts">
import { page } from '$app/stores';
import Navbar from '$lib/components/Navbar.svelte';
import config from '$lib/data/config';

const { entries } = $page.data;
</script>

<div class="grid grid-rows-[auto,1fr]" style="height:100vh;height:100dvh;">
<div class="navbar">
<Navbar showBackButton={false}>
<!-- <div slot="left-buttons" /> -->
<label for="sidebar" slot="center">
<div class="btn btn-ghost normal-case text-xl">{config.name}</div>
</label>
<!-- <div slot="right-buttons" /> -->
</Navbar>
</div>
<div class="overflow-y-auto max-w-screen-md">
<div id="container" class="lexicon">
<ul>
{#if entries.length > 0}
{#each entries as entry}
<li>{entry.name}</li>
{/each}
{:else}
<li>No entries available or table 'entries' not found.</li>
{/if}
</ul>
</div>
</div>
</div>
Loading