feat: add posts to dock as well

This commit is contained in:
Xylight committed 2024-04-13 19:43:19 -07:00
1 parent eb00921060
commit a5b1591d74
7 files changed
+96 -29

No files matched your search

+2 -2
View File
@@ -16,7 +16,7 @@ import { get, writable } from 'svelte/store'
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
import { browser } from '$app/environment'
import { env } from '$env/dynamic/public'
import type { ResumableCommunity } from './lemmy/item'
import type { ResumableItem } from './lemmy/item'
const getDefaultProfile = (): Profile => ({
id: -1,
@@ -43,7 +43,7 @@ export interface Profile {
user?: PersonData
username?: string
avatar?: string
favorites?: ResumableCommunity[]
favorites?: ResumableItem[]
color?: string
}
@@ -13,7 +13,7 @@
<Button
color="tertiary"
{...$$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'
: ''} {$$props.class ?? ''}"
size="custom"
+41 -12
View File
@@ -28,7 +28,7 @@
<nav
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}
"
style={$$props.style}
@@ -44,11 +44,12 @@
{#if $profile}
<div
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)}
<div
class="h-9 w-9 flex"
class="h-10 w-10 flex"
transition:scale|global={{
start: 0.7,
easing: backOut,
@@ -62,18 +63,46 @@
}}
>
<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}
href={favorite.url.toString()}
label="Community"
label={favorite.name}
>
<Avatar
alt={favorite.name}
url={favorite.avatar}
res={64}
width={28}
class="w-full"
/>
{#if favorite.type == 'post'}
<div
class="relative w-full h-full grid place-items-center overflow-visible"
>
{#if favorite.subdivision}
<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>
</div>
{/each}
@@ -21,11 +21,11 @@
? ''
: 'max-lg:!p-1 [&>*]:max-lg:!justify-center'} {$$props.class}"
>
{#if icon}
<Icon src={icon} solid={selected} size="20" />
{:else}
<slot {selected} name="icon" />
{/if}
<slot {selected} name="icon" slot="prefix">
{#if icon}
<Icon src={icon} solid={selected} size="20" />
{/if}
</slot>
<slot />
<div class={$userSettings.expandSidebar ? 'contents' : 'max-lg:hidden'}>
<slot name="label" />
+23 -1
View File
@@ -1,3 +1,4 @@
import { profile } from '$lib/auth'
import type {
CommentReportView,
CommentView,
@@ -10,6 +11,7 @@ import type {
PrivateMessageReportView,
PrivateMessageView,
} from 'lemmy-js-client'
import { get } from 'svelte/store'
export type Result =
| PostView
@@ -67,9 +69,29 @@ export const isPrivateMessageReport = (
item: Result
): item is PrivateMessageReportView => 'private_message_report' in item
export interface ResumableCommunity {
export interface ResumableItem {
url: URL
id: number
name: 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
}))
}
+3 -7
View File
@@ -21,6 +21,7 @@
} from 'svelte-hero-icons'
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { profile } from '$lib/auth'
import { addResumable } from '$lib/lemmy/item.js'
export let data
@@ -36,18 +37,13 @@
afterNavigate(() => {
if ($profile) {
let favs = $profile?.favorites ?? []
if (favs.map((fav) => fav.url.toString()).includes($page.url.toString()))
return
if (favs.length >= 3) favs.pop()
favs.unshift({
addResumable({
avatar: data.community.community_view.community.icon,
id: data.community.community_view.community.id,
url: $page.url,
name: data.community.community_view.community.title,
type: 'community',
})
$profile.favorites = favs
}
})
@@ -46,9 +46,14 @@
import { feature } from '$lib/version.js'
import { publishedToDate } from '$lib/components/util/date.js'
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 Expandable from '$lib/components/ui/Expandable.svelte'
import { addResumable } from '$lib/lemmy/item.js'
export let data
@@ -80,6 +85,21 @@
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) => {