Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon Scherer authored and Leon Scherer committed Apr 8, 2024
1 parent 75cb0ca commit 343e874
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ vite.config.ts.timestamp-*

/output
.vscode

docs/
Binary file added bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@sveltejs/adapter-auto": "^1.0.0",
"@sveltejs/adapter-static": "^3.0.0",
"@sveltejs/adapter-static": "^1.0.0",
"@sveltejs/kit": "^1.0.0",
"@sveltejs/package": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
Expand Down
80 changes: 48 additions & 32 deletions src/lib/Navigation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,75 @@
import { page } from '$app/stores'
import { pageNavigateDirection } from '$lib/Page.svelte'
const links: { url: string, text?: string, imageUrl?: string }[] = [
{ url: "/", text: "/" },
{ url: "https://github.com/fruup/svelte-ticker-board", imageUrl: "/github-mark-white.svg" },
interface Link {
url: string
text?: string
imageUrl?: string
}
const links: { url: string; text?: string; imageUrl?: string }[] = [
{ url: '/', text: '/' },
{ url: 'https://github.com/fruup/svelte-ticker-board', imageUrl: '/github-mark-white.svg' },
]
let xDown: number | null = null
let yDown: number | null = null
// let xDown: number | null = null
// let yDown: number | null = null
const handleTouchStart = (e: TouchEvent) => {
const firstTouch = e.touches[0]
xDown = firstTouch.clientX
yDown = firstTouch.clientY
}
// const handleTouchStart = (e: TouchEvent) => {
// const firstTouch = e.touches[0]
// xDown = firstTouch.clientX
// yDown = firstTouch.clientY
// }
const handleTouchMove = (e: TouchEvent) => {
if (!xDown || !yDown) return
// const handleTouchMove = (e: TouchEvent) => {
// if (!xDown || !yDown) return
const xUp = e.touches[0].clientX
const yUp = e.touches[0].clientY
// const xUp = e.touches[0].clientX
// const yUp = e.touches[0].clientY
const xDiff = xDown - xUp
const yDiff = yDown - yUp
// const xDiff = xDown - xUp
// const yDiff = yDown - yUp
if (Math.abs(xDiff) > Math.abs(yDiff) && Math.abs(xDiff) > 10) {
const offset = xDiff > 0 ? 1 : -1
const index = links.indexOf($page.url.pathname.substring(1))
const dst = links[((index >= 0 ? index : 0) + links.length + offset) % links.length]
// if (Math.abs(xDiff) > Math.abs(yDiff) && Math.abs(xDiff) > 10) {
// const offset = xDiff > 0 ? 1 : -1
// const index = links.indexOf($page.url.pathname.substring(1))
// const dst = links[((index >= 0 ? index : 0) + links.length + offset) % links.length]
$pageNavigateDirection = xDiff > 0 ? 'l' : 'r'
// $pageNavigateDirection = xDiff > 0 ? 'l' : 'r'
goto('/' + dst)
// goto('/' + dst)
xDown = null
yDown = null
}
}
// xDown = null
// yDown = null
// }
// }
const handleClickLink = (link: string) => {
const fromIndex = links.indexOf($page.url.pathname.substring(1))
const handleClickLink = (link: Link) => {
const fromIndex = links.findIndex(({ url }) => url === $page.url.pathname)
const toIndex = links.indexOf(link)
$pageNavigateDirection = fromIndex < toIndex ? 'l' : 'r'
}
</script>

<svelte:window on:touchstart={handleTouchStart} on:touchmove={handleTouchMove} />
<!-- <svelte:window on:touchstart={handleTouchStart} on:touchmove={handleTouchMove} /> -->

<nav>
{#each links as { url, text, imageUrl }}
<a class:active={$page.url.pathname === href} href={url} on:click={() => handleClickLink(link)}>
{#each links as link}
{@const url = link.url}
{@const text = link.text}
{@const imageUrl = link.imageUrl}
{@const isInternal = url.startsWith('/')}

<a
class:active={$page.url.pathname === url}
href={url}
on:click={() => handleClickLink(link)}
target={isInternal ? '_blank' : undefined}
>
{#if text}
{text}
{:else if imageUrl}
<img src={imageUrl}>
<img src={imageUrl} />
{/if}
</a>
{/each}
Expand Down
4 changes: 0 additions & 4 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<script lang="ts">
import '../styles/index.css'
import { page } from '$app/stores'
import { setContext } from 'svelte'
import Navigation from '$lib/Navigation.svelte'
$: setContext('isDynamic', $page.url.searchParams.has('dynamic'))
</script>

<header>
Expand Down
1 change: 1 addition & 0 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const prerender = true
7 changes: 4 additions & 3 deletions svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const config = {
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),

outDir: 'docs',
adapter: adapter({
pages: 'docs',
assets: 'docs',
}),
},
};

Expand Down

0 comments on commit 343e874

Please sign in to comment.