Skip to content

Commit

Permalink
Quiz: switch from book.type to url in events
Browse files Browse the repository at this point in the history
* Have one place that converts book.type to url
* Pass url around
* Add url to history when navigating
* Use url in history
  • Loading branch information
chrisvire committed Jun 6, 2024
1 parent f1a7c0c commit ac1d54e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
26 changes: 16 additions & 10 deletions src/lib/components/BookSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ The navbar component.
async function navigateReference(e) {
// Handle special book navigation first
if (e.detail.tab === b && e.detail?.type === 'quiz'){
if (e.detail.tab === b && e.detail?.url){
const book = e.detail.text;
addHistory({
collection: $refs.collection,
book,
chapter: "1"
chapter: "",
url: e.detail.url
});
goto(`${base}/quiz/${$refs.collection}/${book}`);
goto(e.detail.url);
return;
}
if (!showChapterSelector) {
Expand Down Expand Up @@ -135,6 +136,14 @@ The navbar component.
/**list of chapters in current book*/
$: chapters = books.find((d) => d.bookCode === book).versesByChapters;
function getBookUrl(book) {
let url;
if (book.type === 'quiz') {
url = `${base}/quiz/${$refs.collection}/${book.id}`
}
return url;
}
let bookGridGroup = ({ colId, bookLabel = 'abbreviation' }) => {
let groups = [];
var lastGroup = null;
Expand All @@ -143,10 +152,10 @@ The navbar component.
config.bookCollections
.find((x) => x.id === colId)
.books.forEach((book) => {
let label = book[bookLabel] || book.name;
let cell = { label: label, id: book.id, type: book.type};
// Include books only in the catalog (i.e. only supported book types)
if (books.find((x) => x.bookCode === book.id)) {
const url = getBookUrl(book);
if (books.find((x) => x.bookCode === book.id) || url) {
let label = book[bookLabel] || book.name;
let cell = { label, id: book.id, url};
let group = book.testament || '';
if ((lastGroup == null || group !== lastGroup) && config.mainFeatures['book-group-titles']) {
// Create new group
Expand All @@ -164,9 +173,6 @@ The navbar component.
let cells = groups.at(-1).cells;
groups.at(-1).cells = [...cells, cell];
}
} else if (book.type.toLowerCase() === 'quiz') {
let cells = groups.at(-1).cells;
groups.at(-1).cells = [...cells, cell]
}
});
Expand Down
29 changes: 19 additions & 10 deletions src/lib/components/HistoryCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TODO:
import { formatDateAndTime } from '$lib/scripts/dateUtils';
import { base } from '$app/paths';
import config from '$lib/data/config';
import { goto } from '$app/navigation';
export let history: HistoryItem;
$: bc = config.bookCollections.find((x) => x.id === history.collection);
Expand All @@ -22,21 +23,29 @@ TODO:
: history.chapter;
$: dateFormat = formatDateAndTime(new Date(history.date));
$: textDirection = bc.style.textDirection;
</script>
<!-- history cards are alway LTR with the reference following the text direction -->
<div class="history-item-block dy-card w-100 bg-base-100 shadow-lg my-4" style:direction="ltr">
<!-- svelte-ignore a11y-click-events-have-key-events -->
<a
style="text-decoration:none;"
href="{base}/"
on:click={() =>
function onHistoryClick() {
if (history.url) {
goto(history.url);
} else {
refs.set({
docSet,
book: history.book,
chapter: history.chapter,
verse: history.verse
})}
})
goto(`${base}/`);
}
}
</script>

<!-- history cards are alway LTR with the reference following the text direction -->
<div class="history-item-block dy-card w-100 bg-base-100 shadow-lg my-4" style:direction="ltr">
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
style="text-decoration:none;"
on:click={onHistoryClick}
>
<div
class="history-card grid grid-cols-1"
Expand All @@ -55,5 +64,5 @@ TODO:
</div>
<div class="history-item-date justify-self-start">{dateFormat}</div>
</div>
</a>
</div>
</div>
4 changes: 2 additions & 2 deletions src/lib/components/SelectGrid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ A component to display menu options in a grid.
function handleClick(opt: any) {
const text = opt.id;
const type = opt?.type;
const url = opt?.url;
dispatch('menuaction', {
text,
type
url
});
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/SelectList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ A component to display menu options in a list.
function handleClick(opt: any) {
const text = opt.id;
const type = opt?.type;
const url = opt?.url;
dispatch('menuaction', {
text,
type
url
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/TabsMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A component to display tabbed menus.
function handleMenuaction({ detail }: CustomEvent) {
dispatch('menuaction', {
text: detail.text,
type: detail?.type,
url: detail?.url,
tab: active
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/data/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface HistoryItem {
book: string;
chapter: string;
verse?: string;
url?: string;
}
interface History extends DBSchema {
history: {
Expand Down Expand Up @@ -39,6 +40,7 @@ export async function addHistory(item: {
book: string;
chapter: string;
verse?: string;
url?: string;
}) {
let history = await openHistory();
if (nextTimer) {
Expand Down

0 comments on commit ac1d54e

Please sign in to comment.