Fix RandomItem link

pull/4/head
Nilesh 2022-05-22 19:40:55 +01:00
rodzic d6a59538b0
commit 941fccd782
1 zmienionych plików z 12 dodań i 3 usunięć

Wyświetl plik

@ -15,9 +15,13 @@
import { SearchIcon } from "@rgossiaux/svelte-heroicons/outline";
let currentView = "/topics";
let randomItemId;
function handleTabChanged(event) {
currentView = event.detail.tab;
function getRandomItemId(){
fetch('/learn.json?_shape=array&sql=select+rowid+from+items+order+by+random()+limit+1').then(r => r.json())
.then(data => {
randomItemId = data[0].rowid;
});
}
async function hashchange() {
@ -32,8 +36,11 @@
}
}
onMount(getRandomItemId);
onMount(hashchange);
</script>
<svelte:window on:hashchange={hashchange}/>
@ -56,6 +63,8 @@
<CourseList/>
{:else if currentView.startsWith("/item/")}
<ItemDetail itemid={currentView.split("/")[2]}/>
{:else if currentView == "/random"}
{#if randomItemId}<ItemDetail itemid={randomItemId}/>{/if}
{:else if currentView === "/search"}
<AdvancedSearch/>
{:else if currentView === "/wanttolearn"}
@ -74,7 +83,7 @@
<SearchIcon class="mr-4 flex-shrink-0 h-6 w-6 text-indigo-300"/>
Formats
</a>
<a href="#/item/1" class="text-indigo-100 hover:bg-indigo-600 w-full group flex items-center px-2 py-2 text-sm font-medium rounded-md">
<a href="#/random" on:click={getRandomItemId} class="text-indigo-100 hover:bg-indigo-600 w-full group flex items-center px-2 py-2 text-sm font-medium rounded-md">
<SearchIcon class="mr-4 flex-shrink-0 h-6 w-6 text-indigo-300"/>
Random Item
</a>