From 267a203435d79a27485a15b820b2b0431aa62a3b Mon Sep 17 00:00:00 2001 From: kiosion Date: Sun, 1 Oct 2023 22:22:01 -0300 Subject: [PATCH] fix: Update consts, nav-link component - Remove unused consts - Fix nav-link not showing active state when i18n lang param present --- svelte-app/src/components/nav/nav-link.svelte | 5 +-- svelte-app/src/lib/consts.ts | 35 +++---------------- svelte-app/src/routes/[[lang=lang]]/+page.ts | 4 +-- .../src/routes/[[lang=lang]]/blog/+page.ts | 4 +-- .../src/routes/[[lang=lang]]/work/+page.ts | 7 +--- 5 files changed, 12 insertions(+), 43 deletions(-) diff --git a/svelte-app/src/components/nav/nav-link.svelte b/svelte-app/src/components/nav/nav-link.svelte index ef925c673..d30d9d701 100644 --- a/svelte-app/src/components/nav/nav-link.svelte +++ b/svelte-app/src/components/nav/nav-link.svelte @@ -30,9 +30,10 @@ goto($linkTo(link.url)).catch(() => undefined); }; - $: splitPath = $page?.url.pathname.split('/') || []; + $: splitPath = $page?.url?.pathname?.split('/') || []; $: (isActive = (() => { - let urlIncludesLink = $page?.url.pathname === link.url; + let urlIncludesLink = + ($isLocalized ? $page?.url?.pathname?.slice(3) : $page?.url?.pathname) === link.url; if (navigatingIsActive) { urlIncludesLink ||= $navigating?.to?.url.pathname === link.url; diff --git a/svelte-app/src/lib/consts.ts b/svelte-app/src/lib/consts.ts index 384e03e25..4beb1cc21 100644 --- a/svelte-app/src/lib/consts.ts +++ b/svelte-app/src/lib/consts.ts @@ -58,15 +58,14 @@ export const NAV_LINKS = TOP_LEVEL_ROUTES.filter((route) => !route.hidden)?.map( export const BASE_TRANSITION_DURATION = 200 as const; export const BASE_ANIMATION_DURATION = 300 as const; -export const PAGINATION_POSTS_PER_PAGE = 12; -export const PAGINATION_PROJECTS_PER_PAGE = 12; +export const HOMEPAGE_POSTS_NUM = 4 as const; +export const HOMEPAGE_PROJECTS_NUM = 1 as const; -// Disable pagination for now export const RECENT_POSTS_COUNT = 99; export const RECENT_PROJECTS_COUNT = 99; export const DEFAULT_POST_QUERY_PARAMS = { - limit: PAGINATION_POSTS_PER_PAGE, + limit: 99, skip: 0, sort: 'date', order: 'desc', @@ -74,10 +73,7 @@ export const DEFAULT_POST_QUERY_PARAMS = { tags: [] }; -export const DEFAULT_PROJECT_QUERY_PARAMS = { - ...DEFAULT_POST_QUERY_PARAMS, - limit: PAGINATION_PROJECTS_PER_PAGE -}; +export const DEFAULT_PROJECT_QUERY_PARAMS = DEFAULT_POST_QUERY_PARAMS; export const DEFAULT_DESKTOP_WIDTH = 768; export const DEFAULT_MOBILE_WIDTH = DEFAULT_DESKTOP_WIDTH - 1; @@ -85,11 +81,6 @@ export const DEFAULT_MOBILE_WIDTH = DEFAULT_DESKTOP_WIDTH - 1; export const DEFAULT_DESKTOP_BREAKPOINT = `(min-width: ${DEFAULT_DESKTOP_WIDTH}px)`; export const DEFAULT_MOBILE_BREAKPOINT = `(max-width: ${DEFAULT_MOBILE_WIDTH}px)`; -export const DEFAULT_BREAKPOINTS = { - sm: DEFAULT_MOBILE_BREAKPOINT, - lg: DEFAULT_DESKTOP_BREAKPOINT -}; - export const LANGUAGE_COLOURS = new Proxy( new Map([ ['asp', '#6a40fd'], @@ -157,21 +148,3 @@ export const LANGUAGE_COLOURS = new Proxy( } } ); - -export const LOADING_PHRASES = [ - 'Spinning violently around the y-axis', - 'Assembling from source', - 'Hunting for bugs', - 'Dusting the cobwebs', - 'Looking for missing semicolons', - ':3', - 'Calculating the airspeed velocity of an unladen swallow', - 'Brewing some coffee', - 'Browsing StackOverflow', - 'Warming up your CPU', - 'Rotating the earth', - 'Decompiling binaries', - 'RTFM-ing', - 'Parsing XML', - 'Grokking the hypersphere' -]; diff --git a/svelte-app/src/routes/[[lang=lang]]/+page.ts b/svelte-app/src/routes/[[lang=lang]]/+page.ts index da57b029d..15a840be8 100644 --- a/svelte-app/src/routes/[[lang=lang]]/+page.ts +++ b/svelte-app/src/routes/[[lang=lang]]/+page.ts @@ -1,4 +1,4 @@ -import { DEFAULT_APP_LANG } from '$lib/consts'; +import { DEFAULT_APP_LANG, HOMEPAGE_POSTS_NUM } from '$lib/consts'; import { find, findOne } from '$lib/store'; import { error } from '@sveltejs/kit'; @@ -11,7 +11,7 @@ export const load = (async ({ parent, fetch, params }) => { about = parentData.about, lang = params.lang || DEFAULT_APP_LANG, promiseArray = [ - find(fetch, 'post', { limit: 6, lang }), + find(fetch, 'post', { limit: HOMEPAGE_POSTS_NUM, lang }), findOne(fetch, 'project', { id: 'kio.dev', lang }) ]; diff --git a/svelte-app/src/routes/[[lang=lang]]/blog/+page.ts b/svelte-app/src/routes/[[lang=lang]]/blog/+page.ts index 67f12e9b6..1d61a10e9 100644 --- a/svelte-app/src/routes/[[lang=lang]]/blog/+page.ts +++ b/svelte-app/src/routes/[[lang=lang]]/blog/+page.ts @@ -1,11 +1,11 @@ -import { RECENT_POSTS_COUNT } from '$lib/consts'; +import { DEFAULT_POST_QUERY_PARAMS } from '$lib/consts'; import { find } from '$lib/store'; import type { PageLoad } from './$types'; export const load = (async ({ fetch, params }) => { const posts = await find(fetch, 'post', { - limit: RECENT_POSTS_COUNT, + ...DEFAULT_POST_QUERY_PARAMS, lang: params.lang ?? 'en' }); diff --git a/svelte-app/src/routes/[[lang=lang]]/work/+page.ts b/svelte-app/src/routes/[[lang=lang]]/work/+page.ts index e3faab903..81d3b2194 100644 --- a/svelte-app/src/routes/[[lang=lang]]/work/+page.ts +++ b/svelte-app/src/routes/[[lang=lang]]/work/+page.ts @@ -1,8 +1,4 @@ -import { - DEFAULT_APP_LANG, - DEFAULT_PROJECT_QUERY_PARAMS, - RECENT_PROJECTS_COUNT -} from '$lib/consts'; +import { DEFAULT_APP_LANG, DEFAULT_PROJECT_QUERY_PARAMS } from '$lib/consts'; import { find } from '$lib/store'; import { error } from '@sveltejs/kit'; @@ -14,7 +10,6 @@ export const load = (async ({ parent, fetch, params }) => { lang = params.lang || DEFAULT_APP_LANG, projects = await find(fetch, 'project', { ...DEFAULT_PROJECT_QUERY_PARAMS, - limit: RECENT_PROJECTS_COUNT, lang });