Skip to content

Commit 8dce99c

Browse files
author
Sebastian Flick
committed
fix navigation bugs and get active-page onload
1 parent da6470a commit 8dce99c

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/+page.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function load({ fetch, params }) {
5454
if (selectedIndex > 0) {
5555
returnObjects.push(data[witnes][selectedIndex - 1] ?? {});
5656
}
57-
returnObjects.push(data[witnes][selectedIndex] ?? {});
57+
returnObjects.push({ ...data[witnes][selectedIndex], active: true } ?? {});
5858
if (selectedIndex <= data[witnes].length - 1) {
5959
returnObjects.push(data[witnes][selectedIndex + 1] ?? {});
6060
}
@@ -84,11 +84,7 @@ export async function load({ fetch, params }) {
8484
}
8585
return returnObject;
8686
});
87-
return returnObjects.length
88-
? returnObjects.map((returnObject) => {
89-
return { tpData: returnObject.tpData, iiif: returnObject.iiif, page: returnObject.id };
90-
})
91-
: [{ tpData: false, iiif: false, page: false }];
87+
return returnObjects.length ? returnObjects : [{ tpData: false, iiif: false, page: false }];
9288
});
9389

9490
return {

src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/+page.svelte

+15-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import TextzeugenContent, { setTarget } from './TextzeugenContent.svelte';
55
import { base } from '$app/paths';
66
import { page } from '$app/stores';
7-
import { replaceState } from '$app/navigation';
7+
import { afterNavigate, replaceState } from '$app/navigation';
88
import { iiif, teipb } from '$lib/constants';
99
1010
/** @type {import('./$types').PageData} */
@@ -66,11 +66,18 @@
6666
let localVerses = Array(data.content?.length).fill(`${data.thirties}.${data.verse}`);
6767
let localPages = Array(data.content?.length).fill([]);
6868
let currentIiif = Array(data.content?.length).fill({});
69-
//fill the data from the load-function into the localPages array
70-
data.content?.forEach((c, i) => {
71-
c.meta.then((meta) => {
72-
localPages[i] = [...localPages[i], ...meta];
73-
currentIiif[i] = meta[1]?.iiif;
69+
70+
afterNavigate(() => {
71+
//fill the data from the load-function into the localPages array
72+
data.content?.forEach((c, i) => {
73+
c.meta.then((meta) => {
74+
localPages[i] = [...meta];
75+
meta
76+
.find((m) => m.active)
77+
?.iiif.then((iiif) => {
78+
currentIiif[i] = iiif;
79+
});
80+
});
7481
});
7582
});
7683
@@ -79,13 +86,13 @@
7986
/** @type {number} */ i,
8087
/** @type {string} */ sigla
8188
) => {
82-
const indexCurrent = localPages[i].findIndex((p) => p.page === e.detail.id);
89+
const indexCurrent = localPages[i].findIndex((p) => p.id === e.detail.id);
8390
localPages[i][indexCurrent]?.iiif.then((iiif) => {
8491
currentIiif[i] = iiif;
8592
});
8693
const createObject = (/** @type {string} */ id) => {
8794
return {
88-
page: id,
95+
id: id,
8996
tpData: fetch(`${teipb}/parts/${sigla}.xml/json?&view=page&id=${id}&odd=parzival.odd`).then(
9097
(r) => r.json()
9198
),

src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/TextzeugenContent.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@
139139
on:scrollend={onScrollEnd}
140140
bind:this={scrollContainer}
141141
>
142-
{#each pages as pageObject, i (pageObject.page)}
142+
{#each pages as pageObject (pageObject.id)}
143143
{#await pageObject.tpData}
144144
Lade Seite...
145145
{:then tpData}
146146
{@const pageColumns = tpData.content.split('<br class="tei-cb">')}
147147
<div
148148
class="page grid grid-cols-[repeat(auto-fit,minmax(12rem,1fr))] gap-4"
149-
data-id={pageObject.page}
149+
data-id={pageObject.id}
150150
data-next={tpData.nextId}
151151
data-previous={tpData.previousId}
152152
use:scrollToVerse={$targetVerse}

0 commit comments

Comments
 (0)