2022-05-08 12:02:37 +00:00
< script >
import { onMount } from 'svelte';
2022-06-07 11:57:58 +00:00
import AppShell from "./AppShell.svelte"
2022-05-08 12:02:37 +00:00
import Home from "./Home.svelte"
2022-06-02 13:40:28 +00:00
import TreeMap from "./TreeMap.svelte"
2022-05-08 12:02:37 +00:00
import TopicList from "./TopicList.svelte"
import TopicDetail from "./TopicDetail.svelte"
import FormatList from "./FormatList.svelte"
import FormatDetail from "./FormatDetail.svelte"
import ItemDetail from "./ItemDetail.svelte"
2022-06-06 13:48:29 +00:00
import Settings from "./Settings.svelte"
2022-12-29 01:31:04 +00:00
import Roadmap from "./Roadmap.svelte"
import RoadmapList from "./RoadmapList.svelte"
2023-03-05 12:13:22 +00:00
import RoadmapAlt from './roadmapAlt.svelte';
2022-06-11 22:41:46 +00:00
2022-05-30 13:21:32 +00:00
import NavButtonWithLabel from './NavButtonWithLabel.svelte';
2022-12-29 01:31:04 +00:00
import { SearchIcon , LibraryIcon , ViewGridIcon , GiftIcon , CogIcon , BookmarkAltIcon , BookmarkIcon , SupportIcon , MapIcon } from "@rgossiaux/svelte-heroicons/outline";
2022-05-30 20:45:34 +00:00
import Bookmarks from './Bookmarks.svelte';
2022-07-10 15:01:35 +00:00
import { io_getRandomTopicName , io_getTopicByName , io_getTopicList , io_getRandomItemId } from "../db/jsonlines.js"
2022-05-08 12:02:37 +00:00
2024-11-24 13:14:00 +00:00
let currentView = $state("/topics");
let randomTopicName = $state();
let randomItemId = $state();
2022-05-08 12:02:37 +00:00
2024-11-24 13:14:00 +00:00
let alltopics = $derived(io_getTopicList());
2022-05-08 12:02:37 +00:00
2022-07-10 15:01:35 +00:00
function getRandomItemId() {
randomItemId = io_getRandomItemId();
2022-05-31 14:15:39 +00:00
}
2022-07-10 15:01:35 +00:00
function getRandomTopicName() {
randomTopicName = io_getRandomTopicName();
}
2022-05-23 17:17:44 +00:00
2022-05-08 12:02:37 +00:00
async function hashchange() {
// the poor man's router!
const path = window.location.hash.slice(1);
if (path.length > 0) {
currentView = path
} else {
window.location.hash = '/home';
currentView = '/home'
}
}
2022-05-31 14:15:39 +00:00
onMount(getRandomTopicName);
2022-07-10 15:01:35 +00:00
onMount(getRandomItemId);
2022-05-08 12:02:37 +00:00
onMount(hashchange);
< / script >
2024-11-24 13:14:00 +00:00
< svelte:window onhashchange = { hashchange } / >
2022-05-08 12:02:37 +00:00
2022-06-07 11:57:58 +00:00
< AppShell >
2024-11-24 13:14:00 +00:00
{ # snippet content ()}
{ #if currentView === "/home" || currentView === "/" }
< Home / >
{ :else if currentView === "/map" }
< TreeMap / >
{ :else if currentView === "/topics" }
< TopicList { alltopics } />
{ :else if currentView . startsWith ( "/topic/" )}
< TopicDetail topicname = { currentView . split ( "/" ). slice ( 2 ). join ( "/" )} { alltopics } / >
{ :else if currentView === "/formats" }
< FormatList / >
{ :else if currentView . startsWith ( "/format/" )}
< FormatDetail format = { currentView . split ( "/" )[ 2 ]} { alltopics } / >
{ :else if currentView . startsWith ( "/item/" )}
< ItemDetail itemid = { currentView . split ( "/" )[ 2 ]} / >
{ :else if currentView == "/randomtopic" }
{ #if randomTopicName } < TopicDetail topicname = { randomTopicName } { alltopics } / > { /if }
{ :else if currentView == "/randomitem" }
{ #if randomItemId } < ItemDetail itemid = { randomItemId } / > { /if }
{ :else if currentView === "/wanttolearn" }
< Bookmarks kind = { 0 } / >
{ :else if currentView === "/finishedlearning" }
< Bookmarks kind = { 1 } / >
{ :else if currentView === "/settings" }
< Settings / >
{ :else if currentView . startsWith ( "/roadmap/" )}
< Roadmap topic = { currentView . split ( "/" )[ 2 ]} / >
{ :else if currentView . startsWith ( "/roadmaps" )}
< RoadmapList / >
{ :else if currentView . startsWith ( "/roadmap-alternate/" )}
< RoadmapAlt topic = { currentView . split ( "/" )[ 2 ]} / >
{ /if }
2022-05-30 11:18:19 +00:00
2022-06-07 09:49:40 +00:00
2024-11-24 13:14:00 +00:00
{ /snippet }
2022-06-06 13:48:29 +00:00
2024-11-24 13:14:00 +00:00
{ # snippet nav ()}
< NavButtonWithLabel
isActive={ currentView === "/roadmaps" }
target="#/roadmaps"
label="Roadmaps"
>
< MapIcon class = " flex-shrink-0 h-6 w-6" / >
< / NavButtonWithLabel >
< NavButtonWithLabel
isActive={ currentView === "/map" }
target="#/map"
label="Explore the Map"
>
< LibraryIcon class = " flex-shrink-0 h-6 w-6" / >
< / NavButtonWithLabel >
< NavButtonWithLabel
isActive={ currentView === "/topics" }
target="#/topics"
label="Topics"
>
< LibraryIcon class = " flex-shrink-0 h-6 w-6" / >
< / NavButtonWithLabel >
< NavButtonWithLabel isActive = { currentView === "/formats" } target="#/formats" label = "Formats" >
< ViewGridIcon class = " flex-shrink-0 h-6 w-6" / >
< / NavButtonWithLabel >
< a href = "#/randomtopic" onclick = { getRandomTopicName } class= {( currentView === "/randomtopic" ? 'text-secondary' : '' ) + " w-full group flex justify-start gap-3 items-center py-5 pl-4 text-sm font-medium" } >
< GiftIcon class = " flex-shrink-0 h-6 w-6" / >
< div class = "flex flex-col items-start" >
< h3 class = "text-center" > Random Topic< / h3 >
< div class = {( currentView === "/randomtopic" ? 'bg-secondary w-full' : '' ) + " w-5 mt-0.25 h-0.5 bg-primary group-hover:w-full ease-in-out duration-300" } > </div >
< / div >
< / a >
< a href = "#/randomitem" onclick = { getRandomItemId } class= {( currentView === "/randomitem" ? 'text-secondary' : '' ) + " w-full group flex justify-start gap-3 items-center py-5 pl-4 text-sm font-medium" } >
< GiftIcon class = " flex-shrink-0 h-6 w-6" / >
< div class = "flex flex-col items-start" >
< h3 class = "text-center" > Random Item< / h3 >
< div class = {( currentView === "/randomitem" ? 'bg-secondary w-full' : '' ) + " w-5 mt-0.25 h-0.5 bg-primary group-hover:w-full ease-in-out duration-300" } > </div >
< / div >
< / a >
< NavButtonWithLabel isActive = { currentView === "/wanttolearn" } target="#/wanttolearn" label = "Want to learn" >
< BookmarkIcon class = " flex-shrink-0 h-6 w-6" / >
< / NavButtonWithLabel >
< NavButtonWithLabel isActive = { currentView === "/finishedlearning" } target="#/finishedlearning" label = "Finished learning" >
< BookmarkAltIcon class = " flex-shrink-0 h-6 w-6" / >
< / NavButtonWithLabel >
<!-- <NavButtonWithLabel isActive={currentView === "/settings"} target="#/settings" label="Settings">
< CogIcon class = " flex-shrink-0 h-6 w-6" / >
< / NavButtonWithLabel > -->
< NavButtonWithLabel target = "https://github.com/learn-awesome/learndb" label = "Contribute" >
< SupportIcon class = " flex-shrink-0 h-6 w-6" / >
< / NavButtonWithLabel >
2022-06-03 17:54:19 +00:00
2024-11-24 13:14:00 +00:00
{ /snippet }
2022-06-07 11:57:58 +00:00
< / AppShell >