mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-09 04:06:25 +01:00
web/updates: proper navigation buttons, refactor internal nav logic
This commit is contained in:
parent
3305bba28a
commit
678adfbda4
1 changed files with 102 additions and 20 deletions
|
@ -1,15 +1,19 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
|
||||||
import type { ChangelogImport } from '$lib/types/changelogs';
|
|
||||||
import { t } from '$lib/i18n/translations';
|
import { t } from '$lib/i18n/translations';
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
|
|
||||||
import { getAllChangelogs } from '$lib/changelogs';
|
import { getAllChangelogs } from '$lib/changelogs';
|
||||||
|
import type { ChangelogImport } from '$lib/types/changelogs';
|
||||||
|
|
||||||
|
import IconChevronLeft from '@tabler/icons-svelte/IconChevronLeft.svelte';
|
||||||
|
import IconChevronRight from '@tabler/icons-svelte/IconChevronRight.svelte';
|
||||||
|
|
||||||
const changelogs = getAllChangelogs();
|
const changelogs = getAllChangelogs();
|
||||||
const versions = Object.keys(changelogs);
|
const versions = Object.keys(changelogs);
|
||||||
|
|
||||||
let changelog: ChangelogImport & { version: string } | undefined;
|
let changelog: ChangelogImport & { version: string } | undefined;
|
||||||
let currentIndex = -1;
|
let currentIndex = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
const hash = $page.url.hash.replace("#", "");
|
const hash = $page.url.hash.replace("#", "");
|
||||||
const versionIndex = versions.indexOf(hash);
|
const versionIndex = versions.indexOf(hash);
|
||||||
|
@ -33,25 +37,72 @@
|
||||||
window.location.hash = version;
|
window.location.hash = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextChangelog = async () => {
|
const loadNext = () => {
|
||||||
++currentIndex;
|
if (currentIndex < versions.length - 1)
|
||||||
await loadChangelog();
|
++currentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
const loadPrev = () => {
|
||||||
if (versions.length > 0) {
|
if (currentIndex > 0)
|
||||||
await nextChangelog()
|
--currentIndex;
|
||||||
} else {
|
}
|
||||||
// TODO: handle if no changelogs are present
|
|
||||||
// (can this happen? maybe)
|
const preloadNext = () => {
|
||||||
}
|
if (!next) return;
|
||||||
});
|
changelogs[next]().catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
$: prev = versions[currentIndex - 1];
|
||||||
|
$: next = versions[currentIndex + 1];
|
||||||
|
$: currentIndex, loadChangelog();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.news {
|
.news {
|
||||||
max-width: 768px;
|
display: flex;
|
||||||
margin: 0 auto;
|
width: 100%;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-wrapper-desktop {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-wrapper-desktop button {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
background-color: transparent;
|
||||||
|
display: flex;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.changelog-wrapper {
|
||||||
|
max-width: 768pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
button[disabled] {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-wrapper-mobile {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 992pt) {
|
||||||
|
.button-wrapper-mobile {
|
||||||
|
display: flex;
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
margin-left: 1rem;
|
||||||
|
margin-right: 1rem;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-wrapper-desktop {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
@ -63,9 +114,40 @@
|
||||||
|
|
||||||
<div class="news">
|
<div class="news">
|
||||||
{#if changelog}
|
{#if changelog}
|
||||||
<svelte:component this={changelog.default} version={changelog.version} />
|
<div class="button-wrapper-desktop">
|
||||||
{/if}
|
<button on:click={loadPrev} disabled={!prev}>
|
||||||
{#if versions[currentIndex + 1]}
|
<IconChevronLeft />
|
||||||
<button on:click={nextChangelog}>next</button>
|
{ prev || '' }
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="changelog-wrapper">
|
||||||
|
<svelte:component this={changelog.default} version={changelog.version} />
|
||||||
|
<div class="button-wrapper-mobile">
|
||||||
|
<button on:click={loadPrev} disabled={!prev}>
|
||||||
|
<IconChevronLeft />
|
||||||
|
{ prev || '' }
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
on:click={loadNext}
|
||||||
|
on:focus={preloadNext}
|
||||||
|
on:mousemove={preloadNext}
|
||||||
|
disabled={!next}
|
||||||
|
>
|
||||||
|
{ next || '' }
|
||||||
|
<IconChevronRight />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="button-wrapper-desktop">
|
||||||
|
<button
|
||||||
|
on:click={loadNext}
|
||||||
|
on:focus={preloadNext}
|
||||||
|
on:mousemove={preloadNext}
|
||||||
|
disabled={!next}
|
||||||
|
>
|
||||||
|
{ next || '' }
|
||||||
|
<IconChevronRight />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
Loading…
Reference in a new issue