misc: improve inbox tabs
This commit is contained in:
1 parent
5e45191565
commit
98767a41f5
4 files changed
+69
-44
No files matched your search
@@ -38,8 +38,6 @@
|
|||||||
import InfiniteScroll from 'svelte-infinite-scroll'
|
import InfiniteScroll from 'svelte-infinite-scroll'
|
||||||
import type { Readable } from 'svelte/motion'
|
import type { Readable } from 'svelte/motion'
|
||||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||||
import { postLink } from '../helpers'
|
|
||||||
import { writable } from 'svelte/store'
|
|
||||||
|
|
||||||
export let posts: PostView[]
|
export let posts: PostView[]
|
||||||
export let community: boolean = false
|
export let community: boolean = false
|
||||||
@@ -53,16 +51,7 @@
|
|||||||
estimateSize: () => 150,
|
estimateSize: () => 150,
|
||||||
overscan: 5,
|
overscan: 5,
|
||||||
measureElement: (element, entry, instance) => {
|
measureElement: (element, entry, instance) => {
|
||||||
const direction = instance.scrollDirection
|
|
||||||
if (direction === 'forward' || direction === null) {
|
|
||||||
return element.scrollHeight
|
return element.scrollHeight
|
||||||
} else {
|
|
||||||
const indexKey = Number(element.getAttribute('data-index'))
|
|
||||||
// didnt ask
|
|
||||||
// @ts-ignore
|
|
||||||
let cacheMeasurement = instance.itemSizeCache.get(indexKey)
|
|
||||||
return cacheMeasurement
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"
|
"
|
||||||
>
|
>
|
||||||
<h1
|
<h1
|
||||||
class="text-3xl font-medium flex items-center gap-2 w-full
|
class="text-3xl font-medium flex gap-2 w-full
|
||||||
{$userSettings.font == 'satoshi/nunito'
|
{$userSettings.font == 'satoshi/nunito'
|
||||||
? 'font-display'
|
? 'font-display'
|
||||||
: ''} {$$props.class ?? ''}"
|
: ''} {$$props.class ?? ''}"
|
||||||
|
|||||||
@@ -11,9 +11,15 @@
|
|||||||
export let isSelected: (
|
export let isSelected: (
|
||||||
url: URL,
|
url: URL,
|
||||||
currentRoute: string | undefined,
|
currentRoute: string | undefined,
|
||||||
route: string
|
route: string,
|
||||||
|
defaultRoute?: string
|
||||||
) => boolean = (url, currentRoute, route) =>
|
) => boolean = (url, currentRoute, route) =>
|
||||||
(currentRoute ?? url.pathname) == route
|
(currentRoute ?? url.pathname) == route
|
||||||
|
export let buildUrl: (
|
||||||
|
currentRoute: string | undefined,
|
||||||
|
href: string
|
||||||
|
) => string = (route, href) => href
|
||||||
|
export let defaultRoute: string | undefined
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<nav
|
<nav
|
||||||
@@ -25,12 +31,12 @@
|
|||||||
{#each routes as route}
|
{#each routes as route}
|
||||||
<a
|
<a
|
||||||
on:click={() => invalidate(route.href)}
|
on:click={() => invalidate(route.href)}
|
||||||
href={route.href}
|
href={buildUrl(currentRoute, route.href)}
|
||||||
class="font-medium rounded-full px-4 py-1 hover:bg-slate-200/40 hover:dark:bg-zinc-700/40
|
class="font-medium rounded-full px-4 py-1 hover:bg-slate-200/40 hover:dark:bg-zinc-700/40
|
||||||
transition-colors duration-100 relative z-0 flex-shrink-0"
|
transition-colors duration-100 relative z-0 flex-shrink-0"
|
||||||
>
|
>
|
||||||
{route.name}
|
{route.name}
|
||||||
{#if isSelected($page.url, currentRoute, route.href)}
|
{#if isSelected($page.url, currentRoute, route.href, defaultRoute)}
|
||||||
<div
|
<div
|
||||||
class="rounded-full bg-slate-100/60 dark:bg-zinc-700/60
|
class="rounded-full bg-slate-100/60 dark:bg-zinc-700/60
|
||||||
absolute inset-0 w-full h-full -z-10"
|
absolute inset-0 w-full h-full -z-10"
|
||||||
|
|||||||
@@ -48,6 +48,25 @@
|
|||||||
|
|
||||||
return response.replies
|
return response.replies
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addSearchParam(
|
||||||
|
currentSearchParams: URLSearchParams,
|
||||||
|
newParamString: string
|
||||||
|
) {
|
||||||
|
// Create a new URLSearchParams object from the current search params
|
||||||
|
const updatedParams = new URLSearchParams(currentSearchParams)
|
||||||
|
|
||||||
|
// Parse the new parameter string
|
||||||
|
const newParam = new URLSearchParams(newParamString)
|
||||||
|
|
||||||
|
// Get the key and value of the new parameter
|
||||||
|
const [key, value]: [string, string] = newParam.entries().next().value!
|
||||||
|
|
||||||
|
// Add the new parameter to the updated params
|
||||||
|
updatedParams.set(key, value)
|
||||||
|
|
||||||
|
return updatedParams
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -55,13 +74,14 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="flex flex-row gap-2">
|
<div class="flex flex-row gap-2">
|
||||||
<Header pageHeader class="sm:flex-row flex-col justify-between items-end">
|
<Header pageHeader class="sm:flex-row justify-between flex-col">
|
||||||
{$t('routes.inbox.title')}
|
{$t('routes.inbox.title')}
|
||||||
|
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
on:click={() => goto($page.url, { invalidateAll: true })}
|
on:click={() => goto($page.url, { invalidateAll: true })}
|
||||||
size="square-md"
|
size="square-lg"
|
||||||
|
rounding="xl"
|
||||||
title={$t('common.refresh')}
|
title={$t('common.refresh')}
|
||||||
>
|
>
|
||||||
<Icon src={ArrowPath} size="16" mini slot="prefix" />
|
<Icon src={ArrowPath} size="16" mini slot="prefix" />
|
||||||
@@ -70,8 +90,8 @@
|
|||||||
on:click={markAllAsRead}
|
on:click={markAllAsRead}
|
||||||
loading={markingAsRead}
|
loading={markingAsRead}
|
||||||
disabled={markingAsRead}
|
disabled={markingAsRead}
|
||||||
size="md"
|
size="lg"
|
||||||
class="h-8"
|
class="h-10"
|
||||||
>
|
>
|
||||||
<Icon src={Check} width={16} mini slot="prefix" />
|
<Icon src={Check} width={16} mini slot="prefix" />
|
||||||
{$t('routes.inbox.markAsRead')}
|
{$t('routes.inbox.markAsRead')}
|
||||||
@@ -82,21 +102,22 @@
|
|||||||
<div class="mt-4" />
|
<div class="mt-4" />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="mt-4 mb-0 sticky z-30 mx-auto max-w-full"
|
class="mt-4 mb-0 sticky z-30 mx-auto max-w-full flex gap-2 md:flex-row flex-col
|
||||||
|
items-center px-2"
|
||||||
style="top: max(1.5rem, {$contentPadding.top}px);"
|
style="top: max(1.5rem, {$contentPadding.top}px);"
|
||||||
>
|
>
|
||||||
<Tabs
|
<Tabs
|
||||||
routes={[
|
routes={[
|
||||||
{
|
{
|
||||||
href: '/inbox',
|
href: '?type=All',
|
||||||
name: $t('filter.location.all'),
|
name: $t('filter.location.all'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: '/inbox?type=Replies',
|
href: '?type=Replies',
|
||||||
name: $t('filter.inbox.replies'),
|
name: $t('filter.inbox.replies'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: '/inbox?type=Mentions',
|
href: '?type=Mentions',
|
||||||
name: $t('filter.inbox.mentions'),
|
name: $t('filter.inbox.mentions'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -104,28 +125,37 @@
|
|||||||
name: $t('filter.inbox.messages'),
|
name: $t('filter.inbox.messages'),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
currentRoute="{$page.url.pathname}{$page.url.search}"
|
currentRoute={$page.url.search}
|
||||||
class="overflow-auto"
|
isSelected={(url, current, route, def) =>
|
||||||
|
$page.url.search == route ||
|
||||||
|
($page.url.pathname == route && $page.url.search == '') ||
|
||||||
|
$page.url.searchParams.toString().includes(route.slice(1)) ||
|
||||||
|
($page.url.search == '' && route == def)}
|
||||||
|
class="overflow-auto w-full"
|
||||||
|
buildUrl={(route, href) =>
|
||||||
|
href.includes('?')
|
||||||
|
? '?' + addSearchParam($page.url.searchParams, href).toString()
|
||||||
|
: `${href}${$page.url.search}`}
|
||||||
|
defaultRoute="?type=All"
|
||||||
|
/>
|
||||||
|
<Tabs
|
||||||
|
routes={[
|
||||||
|
{
|
||||||
|
href: '?unreadOnly=false',
|
||||||
|
name: $t('filter.location.all'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: '?unreadOnly=true',
|
||||||
|
name: $t('filter.unread'),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
isSelected={(url, current, route, def) =>
|
||||||
|
$page.url.searchParams.toString().includes(route.slice(1)) ||
|
||||||
|
($page.url.search == '' && route == def)}
|
||||||
|
buildUrl={(route, href) =>
|
||||||
|
'?' + addSearchParam($page.url.searchParams, href).toString()}
|
||||||
|
defaultRoute="?unreadOnly=true"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<div class="flex flex-row gap-4 flex-wrap items-end">
|
|
||||||
<Select
|
|
||||||
bind:value={data.unreadOnly}
|
|
||||||
on:change={() =>
|
|
||||||
searchParam(
|
|
||||||
$page.url,
|
|
||||||
'unreadOnly',
|
|
||||||
data.unreadOnly?.toString() ?? 'false',
|
|
||||||
'page'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<span slot="label" class="flex items-center gap-1">
|
|
||||||
<Icon src={Funnel} size="15" mini />
|
|
||||||
{$t('filter.filter')}
|
|
||||||
</span>
|
|
||||||
<option value="false">{$t('filter.location.all')}</option>
|
|
||||||
<option value="true">{$t('filter.unread')}</option>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-4 list-none flex-1 h-full mt-4">
|
<div class="flex flex-col gap-4 list-none flex-1 h-full mt-4">
|
||||||
{#if !data.data || (data.data?.length ?? 0) == 0}
|
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||||
|
|||||||
Reference in new issue
Block a user