impr: rewrite Tabs selection detection
This commit is contained in:
14 files changed
+72
-39
No files matched your search
@@ -5,10 +5,13 @@
|
|||||||
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
|
import { client } from '$lib/lemmy.svelte'
|
||||||
import { addSubscription } from '$lib/lemmy/user.js'
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
|
import { settings } from '$lib/settings.svelte'
|
||||||
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
|
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
|
||||||
import type { CommunityView } from 'lemmy-js-client'
|
import type { CommunityView } from 'lemmy-js-client'
|
||||||
import { Button, Modal } from 'mono-svelte'
|
import { Button, modal } from 'mono-svelte'
|
||||||
|
import type { Snippet } from 'svelte'
|
||||||
import {
|
import {
|
||||||
Check,
|
Check,
|
||||||
ExclamationTriangle,
|
ExclamationTriangle,
|
||||||
@@ -20,11 +23,7 @@
|
|||||||
Trash,
|
Trash,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
|
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
|
||||||
import { settings } from '$lib/settings.svelte'
|
|
||||||
import type { Snippet } from 'svelte'
|
|
||||||
import { client } from '$lib/lemmy.svelte'
|
|
||||||
|
|
||||||
let showInfo = $state(false)
|
|
||||||
interface Props {
|
interface Props {
|
||||||
community: CommunityView
|
community: CommunityView
|
||||||
view?: 'cozy' | 'compact'
|
view?: 'cozy' | 'compact'
|
||||||
@@ -46,11 +45,9 @@
|
|||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if showInfo}
|
{#snippet communityInfo()}
|
||||||
<Modal title={$t('form.post.community')} bind:open={showInfo}>
|
|
||||||
<CommunityCard community_view={community} />
|
<CommunityCard community_view={community} />
|
||||||
</Modal>
|
{/snippet}
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class={clazz}>
|
<div class={clazz}>
|
||||||
<div
|
<div
|
||||||
@@ -154,7 +151,8 @@
|
|||||||
size="square-md"
|
size="square-md"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
color="ghost"
|
color="ghost"
|
||||||
onclick={() => (showInfo = !showInfo)}
|
onclick={() =>
|
||||||
|
modal({ title: $t('form.post.community'), snippet: communityInfo })}
|
||||||
>
|
>
|
||||||
<Icon src={InformationCircle} size="16" mini />
|
<Icon src={InformationCircle} size="16" mini />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
import { settings } from '$lib/settings.svelte.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import { Select } from 'mono-svelte'
|
import { Select } from 'mono-svelte'
|
||||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||||
|
import type { SelectProps } from 'mono-svelte/forms/select/Select.svelte'
|
||||||
import { Bars3, Icon, RectangleGroup, ViewColumns } from 'svelte-hero-icons'
|
import { Bars3, Icon, RectangleGroup, ViewColumns } from 'svelte-hero-icons'
|
||||||
|
|
||||||
interface Props {
|
interface Props extends SelectProps<string> {
|
||||||
showLabel?: boolean
|
showLabel?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
pageHeader &&
|
pageHeader &&
|
||||||
`w-[calc(100%+1.5rem)] sm:w-[calc(100%+3rem)]
|
`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
|
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`,
|
border-b border-slate-200 dark:border-zinc-900 margin z-0 mb-3 sm:mb-6`,
|
||||||
]}
|
]}
|
||||||
{style}
|
{style}
|
||||||
aria-label={$t('aria.element.pageHeader')}
|
aria-label={$t('aria.element.pageHeader')}
|
||||||
|
|||||||
@@ -23,22 +23,47 @@
|
|||||||
style = 'header',
|
style = 'header',
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
|
|
||||||
function isSelected(url: URL, href?: SvelteURL) {
|
let matchType = $derived<('search' | 'pathname')[]>(
|
||||||
if (href?.search != '') return href?.search == url.search
|
routes.map(i =>
|
||||||
else if (url.search == '') return href?.pathname == url.pathname
|
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>
|
</script>
|
||||||
|
|
||||||
<nav
|
<nav
|
||||||
class={[
|
class={[
|
||||||
'flex flex-row items-center justify-center sm:justify-start my-2 sm:mt-0 flex-wrap z-20',
|
'flex flex-row items-center my-2 sm:mt-0 flex-wrap z-20',
|
||||||
style == 'header' ? 'p-1 gap-x-8 gap-y-4' : 'gap-2',
|
style == 'header'
|
||||||
|
? 'p-1 gap-x-8 gap-y-4 justify-center sm:justify-start'
|
||||||
|
: 'gap-2',
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{#each routes as route (route.href)}
|
{#each routes as route, index (route.href)}
|
||||||
{@const selected = isSelected(
|
{@const selected = isSelected(
|
||||||
page.url,
|
page.url,
|
||||||
new SvelteURL(`${page.url.origin}${route.href}`),
|
new SvelteURL(`${page.url.origin}${route.href}`),
|
||||||
|
matchType[index],
|
||||||
)}
|
)}
|
||||||
{#if style == 'header'}
|
{#if style == 'header'}
|
||||||
<a
|
<a
|
||||||
@@ -61,3 +86,7 @@
|
|||||||
{/each}
|
{/each}
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
{#if style == 'subpage'}
|
||||||
|
<div class="h-3"></div>
|
||||||
|
{/if}
|
||||||
@@ -94,8 +94,9 @@
|
|||||||
}: Props<T> = $props()
|
}: Props<T> = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#snippet selectTarget()}
|
{#snippet selectTarget(attachment: Attachment)}
|
||||||
<select
|
<select
|
||||||
|
{@attach attachment}
|
||||||
{...rest}
|
{...rest}
|
||||||
{id}
|
{id}
|
||||||
bind:this={element}
|
bind:this={element}
|
||||||
|
|||||||
@@ -22,9 +22,7 @@
|
|||||||
placement?: Placement
|
placement?: Placement
|
||||||
middleware?: Middleware[]
|
middleware?: Middleware[]
|
||||||
strategy?: Strategy
|
strategy?: Strategy
|
||||||
manual?: boolean
|
|
||||||
popoverClass?: string
|
popoverClass?: string
|
||||||
class?: string
|
|
||||||
target?: import('svelte').Snippet<[Attachment]>
|
target?: import('svelte').Snippet<[Attachment]>
|
||||||
popover?: import('svelte').Snippet<[boolean]>
|
popover?: import('svelte').Snippet<[boolean]>
|
||||||
children?: import('svelte').Snippet<[boolean]>
|
children?: import('svelte').Snippet<[boolean]>
|
||||||
@@ -72,7 +70,6 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
const menuAttach: Attachment = element => {
|
const menuAttach: Attachment = element => {
|
||||||
console.log(element)
|
|
||||||
const e = element as HTMLButtonElement
|
const e = element as HTMLButtonElement
|
||||||
|
|
||||||
const mouseLeave = () => (openOnHover ? (open = false) : false)
|
const mouseLeave = () => (openOnHover ? (open = false) : false)
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
import PostFeed from '$lib/components/lemmy/post/feed/PostFeed.svelte'
|
import PostFeed from '$lib/components/lemmy/post/feed/PostFeed.svelte'
|
||||||
import VirtualFeed from '$lib/components/lemmy/post/feed/VirtualFeed.svelte'
|
import VirtualFeed from '$lib/components/lemmy/post/feed/VirtualFeed.svelte'
|
||||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||||
|
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
|
||||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||||
import { t } from '$lib/i18n/translations.js'
|
import { t } from '$lib/i18n/translations.js'
|
||||||
import { site } from '$lib/lemmy.svelte.js'
|
import { site } from '$lib/lemmy.svelte.js'
|
||||||
@@ -57,6 +59,15 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
|
<!-- <EndPlaceholder size="md">
|
||||||
|
{$t('cards.community.activeDay')}
|
||||||
|
{#snippet action()}
|
||||||
|
<span class="text-primary-900 dark:text-primary-100">
|
||||||
|
{site.data?.site_view.counts.users_active_day.toString()}
|
||||||
|
</span>
|
||||||
|
{/snippet}
|
||||||
|
</EndPlaceholder> -->
|
||||||
|
|
||||||
<FeedComponent
|
<FeedComponent
|
||||||
bind:posts={data.feed.value.posts.posts}
|
bind:posts={data.feed.value.posts.posts}
|
||||||
bind:feedData={() => data.feed.value, v => (postFeeds.value.main.data = v)}
|
bind:feedData={() => data.feed.value, v => (postFeeds.value.main.data = v)}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
{$t('nav.create.label')}
|
{$t('nav.create.label')}
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<div class="h-3 sm:h-6"></div>
|
|
||||||
<Tabs
|
<Tabs
|
||||||
style="subpage"
|
style="subpage"
|
||||||
routes={[
|
routes={[
|
||||||
@@ -24,6 +23,5 @@
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<div class="h-3 sm:h-6"></div>
|
|
||||||
|
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
@@ -73,8 +73,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<div class="h-3 sm:h-6"></div>
|
|
||||||
|
|
||||||
<div class="mb-3 sm:mb-6">
|
<div class="mb-3 sm:mb-6">
|
||||||
<Select
|
<Select
|
||||||
class=" w-max items-center"
|
class=" w-max items-center"
|
||||||
|
|||||||
@@ -131,7 +131,6 @@
|
|||||||
{@render startChat?.()}
|
{@render startChat?.()}
|
||||||
</Placeholder>
|
</Placeholder>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="h-3 sm:h-6"></div>
|
|
||||||
<CommonList items={previews}>
|
<CommonList items={previews}>
|
||||||
{#snippet item(preview)}
|
{#snippet item(preview)}
|
||||||
<a href="/inbox/messages/{preview.user.id}" class="flex flex-row gap-2">
|
<a href="/inbox/messages/{preview.user.id}" class="flex flex-row gap-2">
|
||||||
|
|||||||
@@ -15,5 +15,4 @@
|
|||||||
{ href: '/instances/blocked', name: 'Blocked' },
|
{ href: '/instances/blocked', name: 'Blocked' },
|
||||||
]}
|
]}
|
||||||
></Tabs>
|
></Tabs>
|
||||||
<div class="h-3 sm:h-6"></div>
|
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
@@ -61,8 +61,6 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<div class="h-3 sm:h-6"></div>
|
|
||||||
|
|
||||||
{#if !data.data || (data.data?.length ?? 0) == 0}
|
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||||
<Placeholder
|
<Placeholder
|
||||||
icon={Bookmark}
|
icon={Bookmark}
|
||||||
|
|||||||
@@ -54,10 +54,15 @@
|
|||||||
|
|
||||||
<Header pageHeader>
|
<Header pageHeader>
|
||||||
{$t('routes.search.title')}
|
{$t('routes.search.title')}
|
||||||
</Header>
|
{#snippet extended()}
|
||||||
<form method="get" action="/search" class="contents" bind:this={form}>
|
<form
|
||||||
|
method="get"
|
||||||
|
action="/search"
|
||||||
|
class="flex flex-col gap-4"
|
||||||
|
bind:this={form}
|
||||||
|
>
|
||||||
<SearchBar bind:query={data.filters.value.query} />
|
<SearchBar bind:query={data.filters.value.query} />
|
||||||
<div class="flex flex-row flex-wrap items-center gap-4 my-4 sm:my-6">
|
<div class="flex flex-row flex-wrap items-center gap-4">
|
||||||
<Select
|
<Select
|
||||||
name="type"
|
name="type"
|
||||||
bind:value={data.filters.value.type}
|
bind:value={data.filters.value.type}
|
||||||
@@ -91,7 +96,10 @@
|
|||||||
<Icon src={ChevronDoubleDown} size="20" mini />
|
<Icon src={ChevronDoubleDown} size="20" mini />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
{/snippet}
|
||||||
|
</Header>
|
||||||
|
|
||||||
{#if moreOptions}
|
{#if moreOptions}
|
||||||
<div
|
<div
|
||||||
transition:slide={{ axis: 'y', easing: expoOut, duration: 500 }}
|
transition:slide={{ axis: 'y', easing: expoOut, duration: 500 }}
|
||||||
|
|||||||
@@ -96,8 +96,6 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<div class="h-3 sm:h-6"></div>
|
|
||||||
|
|
||||||
<Tabs
|
<Tabs
|
||||||
routes={[
|
routes={[
|
||||||
{
|
{
|
||||||
@@ -122,8 +120,6 @@
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
style="subpage"
|
style="subpage"
|
||||||
></Tabs>
|
/>
|
||||||
|
|
||||||
<div class="h-3 sm:h-6"></div>
|
|
||||||
|
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
Reference in new issue
Block a user