feat: add posts to dock as well
This commit is contained in:
1 parent
eb00921060
commit
a5b1591d74
7 files changed
+96
-29
No files matched your search
+2
-2
@@ -16,7 +16,7 @@ import { get, writable } from 'svelte/store'
|
|||||||
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
import type { ResumableCommunity } from './lemmy/item'
|
import type { ResumableItem } from './lemmy/item'
|
||||||
|
|
||||||
const getDefaultProfile = (): Profile => ({
|
const getDefaultProfile = (): Profile => ({
|
||||||
id: -1,
|
id: -1,
|
||||||
@@ -43,7 +43,7 @@ export interface Profile {
|
|||||||
user?: PersonData
|
user?: PersonData
|
||||||
username?: string
|
username?: string
|
||||||
avatar?: string
|
avatar?: string
|
||||||
favorites?: ResumableCommunity[]
|
favorites?: ResumableItem[]
|
||||||
color?: string
|
color?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<Button
|
<Button
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
class="rounded-full w-9 h-9 {isSelected
|
class="rounded-full w-10 h-10 flex-shrink-0 {isSelected
|
||||||
? 'bg-slate-200 dark:bg-zinc-900'
|
? 'bg-slate-200 dark:bg-zinc-900'
|
||||||
: ''} {$$props.class ?? ''}"
|
: ''} {$$props.class ?? ''}"
|
||||||
size="custom"
|
size="custom"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
<nav
|
<nav
|
||||||
class="flex flex-row gap-2 items-center w-full mx-auto z-50 box-border h-16
|
class="flex flex-row gap-2 items-center w-full mx-auto z-50 box-border h-16
|
||||||
p-1 duration-150
|
p-1 duration-150 overflow-x-auto overflow-y-hidden
|
||||||
{$$props.class}
|
{$$props.class}
|
||||||
"
|
"
|
||||||
style={$$props.style}
|
style={$$props.style}
|
||||||
@@ -44,11 +44,12 @@
|
|||||||
{#if $profile}
|
{#if $profile}
|
||||||
<div
|
<div
|
||||||
class="px-2 border-r border-l border-slate-200 dark:border-zinc-900
|
class="px-2 border-r border-l border-slate-200 dark:border-zinc-900
|
||||||
flex flex-row items-center gap-2 flex-shrink overflow-hidden max-[500px]:hidden"
|
flex flex-row items-center gap-2 [&>*]:flex-shrink-0 overflow-x-auto overflow-y-hidden
|
||||||
|
md:max-w-64 sm:max-w-48 max-w-36 w-full"
|
||||||
>
|
>
|
||||||
{#each $profile.favorites ?? [] as favorite (favorite.id)}
|
{#each $profile.favorites ?? [] as favorite (favorite.id)}
|
||||||
<div
|
<div
|
||||||
class="h-9 w-9 flex"
|
class="h-10 w-10 flex"
|
||||||
transition:scale|global={{
|
transition:scale|global={{
|
||||||
start: 0.7,
|
start: 0.7,
|
||||||
easing: backOut,
|
easing: backOut,
|
||||||
@@ -62,18 +63,46 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<NavButton
|
<NavButton
|
||||||
class="w-full h-full bg-slate-100 dark:bg-zinc-900"
|
class="w-full h-full bg-slate-100 dark:bg-zinc-900 relative"
|
||||||
title={favorite.name}
|
title={favorite.name}
|
||||||
href={favorite.url.toString()}
|
href={favorite.url.toString()}
|
||||||
label="Community"
|
label={favorite.name}
|
||||||
>
|
>
|
||||||
<Avatar
|
{#if favorite.type == 'post'}
|
||||||
alt={favorite.name}
|
<div
|
||||||
url={favorite.avatar}
|
class="relative w-full h-full grid place-items-center overflow-visible"
|
||||||
res={64}
|
>
|
||||||
width={28}
|
{#if favorite.subdivision}
|
||||||
class="w-full"
|
<Avatar
|
||||||
/>
|
alt={favorite.subdivision.name}
|
||||||
|
url={favorite.subdivision.avatar}
|
||||||
|
width={28}
|
||||||
|
res={64}
|
||||||
|
class=""
|
||||||
|
/>
|
||||||
|
<Icon
|
||||||
|
src={PencilSquare}
|
||||||
|
mini
|
||||||
|
size="20"
|
||||||
|
class="absolute -bottom-1 -right-1 rounded-full bg-zinc-900 p-0.5"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<Avatar
|
||||||
|
alt={favorite.name}
|
||||||
|
url={favorite.avatar}
|
||||||
|
res={64}
|
||||||
|
width={28}
|
||||||
|
class="w-full"
|
||||||
|
/>
|
||||||
|
<Icon
|
||||||
|
src={Newspaper}
|
||||||
|
mini
|
||||||
|
size="20"
|
||||||
|
class="absolute -bottom-1 -right-1 rounded-full bg-zinc-900 p-0.5"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
</NavButton>
|
</NavButton>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -21,11 +21,11 @@
|
|||||||
? ''
|
? ''
|
||||||
: 'max-lg:!p-1 [&>*]:max-lg:!justify-center'} {$$props.class}"
|
: 'max-lg:!p-1 [&>*]:max-lg:!justify-center'} {$$props.class}"
|
||||||
>
|
>
|
||||||
{#if icon}
|
<slot {selected} name="icon" slot="prefix">
|
||||||
<Icon src={icon} solid={selected} size="20" />
|
{#if icon}
|
||||||
{:else}
|
<Icon src={icon} solid={selected} size="20" />
|
||||||
<slot {selected} name="icon" />
|
{/if}
|
||||||
{/if}
|
</slot>
|
||||||
<slot />
|
<slot />
|
||||||
<div class={$userSettings.expandSidebar ? 'contents' : 'max-lg:hidden'}>
|
<div class={$userSettings.expandSidebar ? 'contents' : 'max-lg:hidden'}>
|
||||||
<slot name="label" />
|
<slot name="label" />
|
||||||
|
|||||||
+23
-1
@@ -1,3 +1,4 @@
|
|||||||
|
import { profile } from '$lib/auth'
|
||||||
import type {
|
import type {
|
||||||
CommentReportView,
|
CommentReportView,
|
||||||
CommentView,
|
CommentView,
|
||||||
@@ -10,6 +11,7 @@ import type {
|
|||||||
PrivateMessageReportView,
|
PrivateMessageReportView,
|
||||||
PrivateMessageView,
|
PrivateMessageView,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export type Result =
|
export type Result =
|
||||||
| PostView
|
| PostView
|
||||||
@@ -67,9 +69,29 @@ export const isPrivateMessageReport = (
|
|||||||
item: Result
|
item: Result
|
||||||
): item is PrivateMessageReportView => 'private_message_report' in item
|
): item is PrivateMessageReportView => 'private_message_report' in item
|
||||||
|
|
||||||
export interface ResumableCommunity {
|
export interface ResumableItem {
|
||||||
url: URL
|
url: URL
|
||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
avatar?: string
|
avatar?: string
|
||||||
|
type: 'community' | 'post'
|
||||||
|
subdivision?: {
|
||||||
|
avatar?: string
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addResumable(item: ResumableItem) {
|
||||||
|
const p = get(profile)
|
||||||
|
if (!p) return
|
||||||
|
|
||||||
|
let favs = p.favorites ?? []
|
||||||
|
if (favs.map((fav) => fav.url.toString()).includes(item.url.toString()))
|
||||||
|
return
|
||||||
|
if (favs.length >= 5) favs.pop()
|
||||||
|
favs.unshift(item)
|
||||||
|
profile.update(() => ({
|
||||||
|
...p,
|
||||||
|
favorites: favs
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||||
import { profile } from '$lib/auth'
|
import { profile } from '$lib/auth'
|
||||||
|
import { addResumable } from '$lib/lemmy/item.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -36,18 +37,13 @@
|
|||||||
|
|
||||||
afterNavigate(() => {
|
afterNavigate(() => {
|
||||||
if ($profile) {
|
if ($profile) {
|
||||||
let favs = $profile?.favorites ?? []
|
addResumable({
|
||||||
if (favs.map((fav) => fav.url.toString()).includes($page.url.toString()))
|
|
||||||
return
|
|
||||||
|
|
||||||
if (favs.length >= 3) favs.pop()
|
|
||||||
favs.unshift({
|
|
||||||
avatar: data.community.community_view.community.icon,
|
avatar: data.community.community_view.community.icon,
|
||||||
id: data.community.community_view.community.id,
|
id: data.community.community_view.community.id,
|
||||||
url: $page.url,
|
url: $page.url,
|
||||||
name: data.community.community_view.community.title,
|
name: data.community.community_view.community.title,
|
||||||
|
type: 'community',
|
||||||
})
|
})
|
||||||
$profile.favorites = favs
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -46,9 +46,14 @@
|
|||||||
import { feature } from '$lib/version.js'
|
import { feature } from '$lib/version.js'
|
||||||
import { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
||||||
import { mediaType } from '$lib/components/lemmy/post/helpers.js'
|
import {
|
||||||
|
bestImageURL,
|
||||||
|
mediaType,
|
||||||
|
optimizeImageURL,
|
||||||
|
} from '$lib/components/lemmy/post/helpers.js'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||||
|
import { addResumable } from '$lib/lemmy/item.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -80,6 +85,21 @@
|
|||||||
duration: 9999 * 1000,
|
duration: 9999 * 1000,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if ($profile) {
|
||||||
|
addResumable({
|
||||||
|
avatar: post.post_view.post.thumbnail_url
|
||||||
|
? optimizeImageURL(post.post_view.post.thumbnail_url, 64)
|
||||||
|
: undefined,
|
||||||
|
id: post.post_view.post.id,
|
||||||
|
url: $page.url,
|
||||||
|
name: post.post_view.post.name,
|
||||||
|
type: 'post',
|
||||||
|
subdivision: {
|
||||||
|
name: post.post_view.community.name,
|
||||||
|
avatar: post.post_view.community.icon,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const fetchOnHome = async (jwt: string) => {
|
const fetchOnHome = async (jwt: string) => {
|
||||||
|
|||||||
Reference in new issue
Block a user