impr: rewrite Tabs selection detection

This commit is contained in:
James Xylight committed 2025-08-29 15:19:35 -07:00
1 parent 2891c68494
commit f105240559
14 files changed
+106 -73

No files matched your search

@@ -5,10 +5,13 @@
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations'
import { client } from '$lib/lemmy.svelte'
import { addSubscription } from '$lib/lemmy/user.js'
import { settings } from '$lib/settings.svelte'
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
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 {
Check,
ExclamationTriangle,
@@ -20,11 +23,7 @@
Trash,
} from 'svelte-hero-icons'
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 {
community: CommunityView
view?: 'cozy' | 'compact'
@@ -46,11 +45,9 @@
}: Props = $props()
</script>
{#if showInfo}
<Modal title={$t('form.post.community')} bind:open={showInfo}>
<CommunityCard community_view={community} />
</Modal>
{/if}
{#snippet communityInfo()}
<CommunityCard community_view={community} />
{/snippet}
<div class={clazz}>
<div
@@ -154,7 +151,8 @@
size="square-md"
rounding="pill"
color="ghost"
onclick={() => (showInfo = !showInfo)}
onclick={() =>
modal({ title: $t('form.post.community'), snippet: communityInfo })}
>
<Icon src={InformationCircle} size="16" mini />
</Button>
@@ -3,9 +3,10 @@
import { settings } from '$lib/settings.svelte.js'
import { Select } from 'mono-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'
interface Props {
interface Props extends SelectProps<string> {
showLabel?: boolean
}
@@ -32,7 +32,7 @@
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`,
border-b border-slate-200 dark:border-zinc-900 margin z-0 mb-3 sm:mb-6`,
]}
{style}
aria-label={$t('aria.element.pageHeader')}
+35 -6
View File
@@ -23,22 +23,47 @@
style = 'header',
}: Props = $props()
function isSelected(url: URL, href?: SvelteURL) {
if (href?.search != '') return href?.search == url.search
else if (url.search == '') return href?.pathname == url.pathname
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 justify-center sm:justify-start my-2 sm:mt-0 flex-wrap z-20',
style == 'header' ? 'p-1 gap-x-8 gap-y-4' : 'gap-2',
'flex flex-row items-center my-2 sm:mt-0 flex-wrap z-20',
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(
page.url,
new SvelteURL(`${page.url.origin}${route.href}`),
matchType[index],
)}
{#if style == 'header'}
<a
@@ -61,3 +86,7 @@
{/each}
{@render children?.()}
</nav>
{#if style == 'subpage'}
<div class="h-3"></div>
{/if}
+2 -1
View File
@@ -94,8 +94,9 @@
}: Props<T> = $props()
</script>
{#snippet selectTarget()}
{#snippet selectTarget(attachment: Attachment)}
<select
{@attach attachment}
{...rest}
{id}
bind:this={element}
-3
View File
@@ -22,9 +22,7 @@
placement?: Placement
middleware?: Middleware[]
strategy?: Strategy
manual?: boolean
popoverClass?: string
class?: string
target?: import('svelte').Snippet<[Attachment]>
popover?: import('svelte').Snippet<[boolean]>
children?: import('svelte').Snippet<[boolean]>
@@ -72,7 +70,6 @@
})
const menuAttach: Attachment = element => {
console.log(element)
const e = element as HTMLButtonElement
const mouseLeave = () => (openOnHover ? (open = false) : false)