mirror of
https://github.com/ivabus/gui
synced 2025-06-08 00:00:27 +03:00
#134 prev next buttons in topbar are working due to recorded path history store
This commit is contained in:
parent
3e38c231fa
commit
5127397738
9 changed files with 69 additions and 20 deletions
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import ProfileNavButton from './ProfileNavButton.svelte';
|
import ProfileNavButton from './ProfileNavButton.svelte';
|
||||||
|
|
||||||
let backLink = navStore.backLink;
|
let { nextPath, prevPath } = navStore;
|
||||||
|
|
||||||
const onSearch = (term: string) => {
|
const onSearch = (term: string) => {
|
||||||
searchStore.search(term);
|
searchStore.search(term);
|
||||||
|
@ -23,9 +23,9 @@
|
||||||
<a href="/">
|
<a href="/">
|
||||||
<img width="40" height="40" src="/images/tea-icon.png" alt="tea" />
|
<img width="40" height="40" src="/images/tea-icon.png" alt="tea" />
|
||||||
</a>
|
</a>
|
||||||
<ul id="PrevNextButtons" class="flex h-10 gap-4 pl-4 align-middle leading-10 text-gray">
|
<ul class="flex h-10 gap-4 pl-4 align-middle leading-10 text-gray">
|
||||||
<a href={$backLink} class={currentPath !== '/' ? 'active' : ''}>←</a>
|
<button on:click={navStore.back} class={$prevPath ? 'active' : ''}>←</button>
|
||||||
<a href={$backLink} class={currentPath === '/' ? 'active' : ''}>→</a>
|
<button on:click={navStore.next} class={$nextPath ? 'active' : ''}>→</button>
|
||||||
</ul>
|
</ul>
|
||||||
<SearchInput
|
<SearchInput
|
||||||
class="flex-grow border border-none py-4"
|
class="flex-grow border border-none py-4"
|
||||||
|
@ -64,7 +64,12 @@
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
#PrevNextButtons a.active {
|
ul button {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul button.active {
|
||||||
color: white;
|
color: white;
|
||||||
|
pointer-events: all;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,10 +1,55 @@
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
export default function initNavStore() {
|
export default function initNavStore() {
|
||||||
const backLink = writable<string>('/');
|
const historyStore = writable<string[]>(['/']);
|
||||||
|
let history = ['/'];
|
||||||
|
|
||||||
|
historyStore.subscribe((v) => (history = v));
|
||||||
|
|
||||||
|
const prevPathStore = writable<string>('');
|
||||||
|
const nextPathStore = writable<string>('');
|
||||||
|
|
||||||
|
let currentIndex = 0; // if non next/back click
|
||||||
|
|
||||||
|
let isMovingNext = false;
|
||||||
|
let isMovingBack = false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
backLink,
|
historyStore,
|
||||||
set: (newlink: string) => backLink.set(newlink)
|
prevPath: prevPathStore,
|
||||||
|
nextPath: nextPathStore,
|
||||||
|
next: () => {
|
||||||
|
if (currentIndex < history.length - 1) {
|
||||||
|
isMovingNext = true;
|
||||||
|
goto(history[currentIndex + 1]);
|
||||||
|
prevPathStore.set(history[currentIndex]);
|
||||||
|
currentIndex++;
|
||||||
|
if (currentIndex >= history.length - 1) nextPathStore.set('');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
back: () => {
|
||||||
|
if (currentIndex > 0) {
|
||||||
|
isMovingBack = true;
|
||||||
|
goto(history[currentIndex - 1]);
|
||||||
|
nextPathStore.set(history[currentIndex]);
|
||||||
|
currentIndex--;
|
||||||
|
if (currentIndex === 0) prevPathStore.set('');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setNewPath: (newNextPath: string, newPrevPath: string) => {
|
||||||
|
const oldCurrentPath = history[currentIndex];
|
||||||
|
const isNavArrows = isMovingBack || isMovingNext;
|
||||||
|
if (!isNavArrows && newNextPath !== oldCurrentPath) {
|
||||||
|
historyStore.update((history) => {
|
||||||
|
const cleanHistory = history.filter((_v, i) => i <= currentIndex);
|
||||||
|
currentIndex = cleanHistory.length;
|
||||||
|
prevPathStore.set(cleanHistory[currentIndex - 1]);
|
||||||
|
return [...cleanHistory, newNextPath];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
isMovingNext = false;
|
||||||
|
isMovingBack = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,24 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import { navigating } from '$app/stores';
|
import { navigating } from '$app/stores';
|
||||||
|
import { afterNavigate } from '$app/navigation';
|
||||||
import TopBar from '$components/TopBar/TopBar.svelte';
|
import TopBar from '$components/TopBar/TopBar.svelte';
|
||||||
import FooterLinks from '$components/FooterLinks/FooterLinks.svelte';
|
import FooterLinks from '$components/FooterLinks/FooterLinks.svelte';
|
||||||
|
import { navStore } from '$libs/stores';
|
||||||
|
|
||||||
import SearchPopupResults from '$components/SearchPopupResults/SearchPopupResults.svelte';
|
import SearchPopupResults from '$components/SearchPopupResults/SearchPopupResults.svelte';
|
||||||
|
|
||||||
let view: HTMLElement;
|
let view: HTMLElement;
|
||||||
|
|
||||||
$: if ($navigating) view.scrollTop = 0;
|
$: if ($navigating) view.scrollTop = 0;
|
||||||
|
|
||||||
|
afterNavigate(({ from, to }) => {
|
||||||
|
if (to?.route.id) {
|
||||||
|
const nextPath = to.url.href.replace(to.url.origin, '');
|
||||||
|
const fromPath = from?.url.href.replace(from.url.origin, '');
|
||||||
|
navStore.setNewPath(nextPath, fromPath || '/');
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="main-layout" class="w-full">
|
<div id="main-layout" class="w-full">
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
<!-- home / discover / welcome page -->
|
<!-- home / discover / welcome page -->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import { backLink } from '$libs/stores';
|
|
||||||
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
||||||
import FeaturedPackages from '$components/FeaturedPackages/FeaturedPackages.svelte';
|
import FeaturedPackages from '$components/FeaturedPackages/FeaturedPackages.svelte';
|
||||||
import GettingStarted from '$components/GettingStarted/GettingStarted.svelte';
|
import GettingStarted from '$components/GettingStarted/GettingStarted.svelte';
|
||||||
import TopPackages from '$components/TopPackages/TopPackages.svelte';
|
import TopPackages from '$components/TopPackages/TopPackages.svelte';
|
||||||
import News from '$components/News/News.svelte';
|
import News from '$components/News/News.svelte';
|
||||||
import CategorizedPackages from '$components/CategorizedPackages/CategorizedPackages.svelte';
|
import CategorizedPackages from '$components/CategorizedPackages/CategorizedPackages.svelte';
|
||||||
backLink.set('');
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
||||||
import CliBanner from '$components/CliBanner/CliBanner.svelte';
|
import CliBanner from '$components/CliBanner/CliBanner.svelte';
|
||||||
import BigBlackSpace from '$components/BigBlackSpace/BigBlackSpace.svelte';
|
import BigBlackSpace from '$components/BigBlackSpace/BigBlackSpace.svelte';
|
||||||
import { navStore } from '$libs/stores';
|
|
||||||
navStore.set('/');
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
||||||
import FeaturedCourses from '$components/FeaturedCourses/FeaturedCourses.svelte';
|
import FeaturedCourses from '$components/FeaturedCourses/FeaturedCourses.svelte';
|
||||||
import EssentialWorkshops from '$components/EssentialWorkshops/EssentialWorkshops.svelte';
|
import EssentialWorkshops from '$components/EssentialWorkshops/EssentialWorkshops.svelte';
|
||||||
import { navStore } from '$libs/stores';
|
|
||||||
navStore.set('/');
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
||||||
import SearchPackages from '$components/SearchPackages/SearchPackages.svelte';
|
import SearchPackages from '$components/SearchPackages/SearchPackages.svelte';
|
||||||
import { navStore } from '$libs/stores';
|
|
||||||
navStore.set('/');
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
import PageHeader from '$components/PageHeader/PageHeader.svelte';
|
||||||
import { navStore, packagesReviewStore } from '$libs/stores';
|
import { packagesReviewStore } from '$libs/stores';
|
||||||
import PackageBanner from '$components/PackageBanner/PackageBanner.svelte';
|
import PackageBanner from '$components/PackageBanner/PackageBanner.svelte';
|
||||||
import PackageReviews from '$components/PackageReviews/PackageReviews.svelte';
|
import PackageReviews from '$components/PackageReviews/PackageReviews.svelte';
|
||||||
import type { Review } from '@tea/ui/types';
|
import type { Review } from '@tea/ui/types';
|
||||||
import SuggestedPackages from '$components/SuggestedPackages/SuggestedPackages.svelte';
|
import SuggestedPackages from '$components/SuggestedPackages/SuggestedPackages.svelte';
|
||||||
navStore.set('/packages');
|
|
||||||
|
|
||||||
/** @type {import('./$types').PageData} */
|
/** @type {import('./$types').PageData} */
|
||||||
export let data;
|
export let data;
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
import Preflight from '$components/Preflight/Preflight.svelte';
|
import Preflight from '$components/Preflight/Preflight.svelte';
|
||||||
import Badges from '$components/Badges/Badges.svelte';
|
import Badges from '$components/Badges/Badges.svelte';
|
||||||
import InstalledPackages from '$components/InstalledPackages/InstalledPackages.svelte';
|
import InstalledPackages from '$components/InstalledPackages/InstalledPackages.svelte';
|
||||||
import { navStore } from '$libs/stores';
|
|
||||||
navStore.set('/');
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
Loading…
Reference in a new issue