kopia lustrzana https://github.com/learn-awesome/learndb
Fix RandomItem link
rodzic
d6a59538b0
commit
941fccd782
|
@ -15,9 +15,13 @@
|
||||||
import { SearchIcon } from "@rgossiaux/svelte-heroicons/outline";
|
import { SearchIcon } from "@rgossiaux/svelte-heroicons/outline";
|
||||||
|
|
||||||
let currentView = "/topics";
|
let currentView = "/topics";
|
||||||
|
let randomItemId;
|
||||||
|
|
||||||
function handleTabChanged(event) {
|
function getRandomItemId(){
|
||||||
currentView = event.detail.tab;
|
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() {
|
async function hashchange() {
|
||||||
|
@ -32,8 +36,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(getRandomItemId);
|
||||||
onMount(hashchange);
|
onMount(hashchange);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window on:hashchange={hashchange}/>
|
<svelte:window on:hashchange={hashchange}/>
|
||||||
|
@ -56,6 +63,8 @@
|
||||||
<CourseList/>
|
<CourseList/>
|
||||||
{:else if currentView.startsWith("/item/")}
|
{:else if currentView.startsWith("/item/")}
|
||||||
<ItemDetail itemid={currentView.split("/")[2]}/>
|
<ItemDetail itemid={currentView.split("/")[2]}/>
|
||||||
|
{:else if currentView == "/random"}
|
||||||
|
{#if randomItemId}<ItemDetail itemid={randomItemId}/>{/if}
|
||||||
{:else if currentView === "/search"}
|
{:else if currentView === "/search"}
|
||||||
<AdvancedSearch/>
|
<AdvancedSearch/>
|
||||||
{:else if currentView === "/wanttolearn"}
|
{:else if currentView === "/wanttolearn"}
|
||||||
|
@ -74,7 +83,7 @@
|
||||||
<SearchIcon class="mr-4 flex-shrink-0 h-6 w-6 text-indigo-300"/>
|
<SearchIcon class="mr-4 flex-shrink-0 h-6 w-6 text-indigo-300"/>
|
||||||
Formats
|
Formats
|
||||||
</a>
|
</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"/>
|
<SearchIcon class="mr-4 flex-shrink-0 h-6 w-6 text-indigo-300"/>
|
||||||
Random Item
|
Random Item
|
||||||
</a>
|
</a>
|
||||||
|
|
Ładowanie…
Reference in New Issue