impr: restructure src/lib
This commit is contained in:
376 files changed
+1000
-1033
No files matched your search
@@ -0,0 +1,56 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
|
||||
const sizes = {
|
||||
sm: 'text-2xl',
|
||||
md: 'text-3xl',
|
||||
lg: 'text-4xl',
|
||||
xl: 'text-6xl',
|
||||
}
|
||||
|
||||
interface Props {
|
||||
pageHeader?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
size?: keyof typeof sizes
|
||||
children?: import('svelte').Snippet
|
||||
extended?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
pageHeader = false,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
size = 'lg',
|
||||
children,
|
||||
extended,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<header
|
||||
class={[
|
||||
pageHeader &&
|
||||
`w-[calc(100%+1.5rem)] sm:w-[calc(100%+3rem)]
|
||||
bg-slate-100 dark:bg-zinc-950 -mx-3 sm:-mx-6 sm:px-6 sm:pb-6 px-4 pb-4 -mt-64 pt-64
|
||||
border-b border-slate-200 dark:border-zinc-900 margin z-0 mb-3 sm:mb-6`,
|
||||
]}
|
||||
{style}
|
||||
aria-label={$t('aria.element.pageHeader')}
|
||||
>
|
||||
{#if children}
|
||||
<h1
|
||||
class={[
|
||||
sizes[size],
|
||||
'flex gap-2 w-full tracking-tight font-medium',
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{@render children?.()}
|
||||
</h1>
|
||||
{/if}
|
||||
{#if extended}
|
||||
<div class="flex flex-col gap-3 mt-3">
|
||||
{@render extended?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</header>
|
||||
@@ -0,0 +1,114 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import { page } from '$app/state'
|
||||
import type { GetPosts, ListingType, PostView } from '$lib/api/types'
|
||||
import Location from '$lib/feature/filter/Location.svelte'
|
||||
import Sort from '$lib/feature/filter/Sort.svelte'
|
||||
import ViewSelect from '$lib/feature/filter/ViewSelect.svelte'
|
||||
import PostFeed from '$comp/lemmy/post/feed/PostFeed.svelte'
|
||||
import VirtualFeed from '$comp/lemmy/post/feed/VirtualFeed.svelte'
|
||||
import { Header } from '$comp/ui/layout'
|
||||
import Pageination from '$comp/ui/layout/Pageination.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type { SortType } from 'lemmy-js-client'
|
||||
import Button from 'mono-svelte/button/Button.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { ArrowRight, Icon } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
cursor?: string
|
||||
params: {
|
||||
location?: ListingType
|
||||
sort?: SortType
|
||||
}
|
||||
title?: string
|
||||
extended?: Snippet
|
||||
getParams: GetPosts
|
||||
client: {
|
||||
lastSeen?: number
|
||||
itemHeights?: (number | null)[]
|
||||
}
|
||||
header?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
params,
|
||||
posts = $bindable(),
|
||||
cursor = $bindable(),
|
||||
title,
|
||||
extended: passedExtended,
|
||||
getParams,
|
||||
client = $bindable(),
|
||||
header = true,
|
||||
}: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
if (params.sort) settings.defaultSort.sort = params.sort
|
||||
})
|
||||
|
||||
const FeedComponent = $derived(
|
||||
settings.infiniteScroll && browser && !settings.posts.noVirtualize
|
||||
? VirtualFeed
|
||||
: PostFeed,
|
||||
)
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-2 max-w-full w-full min-w-0">
|
||||
{#if header}
|
||||
<Header pageHeader>
|
||||
{#if title}
|
||||
{title}
|
||||
{/if}
|
||||
{#snippet extended()}
|
||||
{@render passedExtended?.()}
|
||||
<form class="" method="get" action={page.url.pathname}>
|
||||
<div class="flex flex-row gap-2">
|
||||
{#if params.location}
|
||||
<Location name="type" navigate bind:selected={params.location} />
|
||||
{/if}
|
||||
{#if params.sort}
|
||||
<Sort
|
||||
placement="bottom"
|
||||
name="sort"
|
||||
navigate
|
||||
bind:selected={params.sort}
|
||||
/>
|
||||
{/if}
|
||||
<ViewSelect placement="bottom" />
|
||||
|
||||
<noscript>
|
||||
<Button
|
||||
class="self-end h-[34px] aspect-square"
|
||||
size="custom"
|
||||
submit
|
||||
>
|
||||
<Icon src={ArrowRight} size="16" micro />
|
||||
</Button>
|
||||
</noscript>
|
||||
</div>
|
||||
</form>
|
||||
{/snippet}
|
||||
</Header>
|
||||
{/if}
|
||||
|
||||
<FeedComponent
|
||||
bind:posts
|
||||
bind:lastSeen={() => client.lastSeen ?? 0, (v) => (client.lastSeen = v)}
|
||||
bind:params={getParams}
|
||||
virtualList={{ itemHeights: client?.itemHeights ?? [] }}
|
||||
/>
|
||||
<svelte:element
|
||||
this={settings.infiniteScroll && !settings.posts.noVirtualize
|
||||
? 'noscript'
|
||||
: 'div'}
|
||||
class="mt-auto flex flex-col"
|
||||
>
|
||||
<Pageination
|
||||
cursor={{ next: cursor }}
|
||||
href={(page) =>
|
||||
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
||||
back={false}
|
||||
/>
|
||||
</svelte:element>
|
||||
</div>
|
||||
@@ -0,0 +1,92 @@
|
||||
<script lang="ts">
|
||||
import { invalidateAll } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import TabButton from '$comp/input/TabButton.svelte'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
interface Props {
|
||||
routes: {
|
||||
href: string
|
||||
name: string
|
||||
}[]
|
||||
currentRoute?: SvelteURL | undefined
|
||||
buildUrl?: (currentRoute: SvelteURL | undefined, href: string) => string
|
||||
children?: import('svelte').Snippet
|
||||
style?: 'header' | 'subpage'
|
||||
margin?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
routes,
|
||||
currentRoute = undefined,
|
||||
buildUrl = (_, href) => href,
|
||||
children,
|
||||
style = 'header',
|
||||
margin = true,
|
||||
}: Props = $props()
|
||||
|
||||
let matchType = $derived<('search' | 'pathname')[]>(
|
||||
routes.map((i) =>
|
||||
new URL(`https://example.com${i.href}`)?.search != ''
|
||||
? 'search'
|
||||
: 'pathname',
|
||||
),
|
||||
)
|
||||
|
||||
// i am on 2 hours of sleep i apologize
|
||||
function isSelected(url: URL, href: SvelteURL, type: 'search' | 'pathname') {
|
||||
const currentSearch = new Set(url.searchParams.values())
|
||||
const hrefSearch = new Set(href.searchParams.values())
|
||||
// checks if there is any
|
||||
const usePathname = !routes.some(
|
||||
(i) =>
|
||||
new Set(
|
||||
new URL(`https://example.com${i.href}`).searchParams.values(),
|
||||
).intersection(currentSearch).size > 0,
|
||||
)
|
||||
|
||||
const hasSearchParam = hrefSearch.intersection(currentSearch).size > 0
|
||||
|
||||
if (hasSearchParam && !usePathname) return hasSearchParam
|
||||
else if ((url.search == '' || usePathname) && type == 'pathname')
|
||||
return href.pathname == url.pathname
|
||||
}
|
||||
</script>
|
||||
|
||||
<nav
|
||||
class={[
|
||||
'flex flex-row items-center sm:mt-0 flex-wrap z-20',
|
||||
style == 'header'
|
||||
? 'p-1 gap-x-8 gap-y-4 justify-center sm:justify-start'
|
||||
: 'gap-2',
|
||||
margin && 'my-2',
|
||||
margin && style == 'subpage' && 'mb-3',
|
||||
]}
|
||||
>
|
||||
{#each routes as route, index (route.href)}
|
||||
{@const selected = isSelected(
|
||||
page.url,
|
||||
new SvelteURL(`${page.url.origin}${route.href}`),
|
||||
matchType[index],
|
||||
)}
|
||||
{#if style == 'header'}
|
||||
<a
|
||||
onclick={() => invalidateAll()}
|
||||
href={buildUrl(currentRoute, route.href)}
|
||||
class={[
|
||||
'rounded-full font-medium transition-colors duration-100 relative z-0 shrink-0 hover:text-slate-900 hover:dark:text-zinc-100',
|
||||
selected
|
||||
? 'text-primary-900 dark:text-primary-100'
|
||||
: 'text-slate-500 dark:text-zinc-500',
|
||||
]}
|
||||
>
|
||||
{route.name}
|
||||
</a>
|
||||
{:else}
|
||||
<TabButton href={buildUrl(currentRoute, route.href)} {selected}>
|
||||
{route.name}
|
||||
</TabButton>
|
||||
{/if}
|
||||
{/each}
|
||||
{@render children?.()}
|
||||
</nav>
|
||||
Reference in new issue
Block a user