feat: add media list
This commit is contained in:
1 parent
0a6310380f
commit
29bfa9104a
7 files changed
+200
-6
No files matched your search
@@ -10,7 +10,8 @@
|
||||
|
||||
<nav
|
||||
class="flex flex-row items-center gap-1 p-1 rounded-full bg-[#fff]/60 dark:bg-neutral-800/60
|
||||
backdrop-blur-lg border border-gray-200/60 dark:border-neutral-800 shadow-lg overflow-auto
|
||||
backdrop-blur-lg border border-gray-200/60 dark:border-neutral-800 shadow-lg {$$props.class ??
|
||||
''}
|
||||
"
|
||||
>
|
||||
{#each routes as route}
|
||||
@@ -28,4 +29,5 @@
|
||||
{/if}
|
||||
</a>
|
||||
{/each}
|
||||
<slot />
|
||||
</nav>
|
||||
@@ -184,7 +184,13 @@
|
||||
"blocks": "Blocks",
|
||||
"credentials": "Credentials",
|
||||
"moderates": "Moderating",
|
||||
"favorites": "Favorites"
|
||||
"favorites": "Favorites",
|
||||
"upvoted": "Upvoted",
|
||||
"downvoted": "Downvoted",
|
||||
"media": {
|
||||
"title": "Media",
|
||||
"download": "Download"
|
||||
}
|
||||
},
|
||||
"translators": "Translators",
|
||||
"accounts": "Accounts",
|
||||
|
||||
@@ -6,6 +6,14 @@
|
||||
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
|
||||
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { Button, Menu, MenuButton } from 'mono-svelte'
|
||||
import {
|
||||
ArrowDown,
|
||||
ArrowUp,
|
||||
EllipsisHorizontal,
|
||||
Icon,
|
||||
Photo,
|
||||
} from 'svelte-hero-icons'
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -14,10 +22,11 @@
|
||||
|
||||
<div class="flex flex-col gap-4 h-full z-0">
|
||||
<div
|
||||
class="sticky mx-auto z-50 max-w-full"
|
||||
class="sticky mx-auto z-50 max-w-full min-w-0 flex items-center gap-2"
|
||||
style="top: max(1.5rem, {$contentPadding.top}px);"
|
||||
>
|
||||
<Tabs
|
||||
class="overflow-auto"
|
||||
routes={[
|
||||
{
|
||||
href: '/profile/user',
|
||||
@@ -40,6 +49,33 @@
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Menu class="flex-1" placement="bottom-end">
|
||||
<Button
|
||||
title={$t('post.actions.more.label')}
|
||||
slot="target"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
color="none"
|
||||
class="bg-[#fff]/60 dark:bg-neutral-800/60
|
||||
border border-gray-200/60 dark:border-neutral-800
|
||||
backdrop-blur-xl shadow-xl hover:bg-slate-100 hover:dark:bg-zinc-800
|
||||
flex-shrink-0"
|
||||
>
|
||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||
</Button>
|
||||
<MenuButton href="/profile/media">
|
||||
<Icon src={Photo} size="16" mini slot="prefix" />
|
||||
{$t('routes.profile.media.title')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/profile/voted/up">
|
||||
<Icon src={ArrowUp} size="16" micro slot="prefix" />
|
||||
{$t('routes.profile.upvoted')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/profile/voted/down">
|
||||
<Icon src={ArrowDown} size="16" micro slot="prefix" />
|
||||
{$t('routes.profile.downvoted')}
|
||||
</MenuButton>
|
||||
</Menu>
|
||||
</div>
|
||||
<slot />
|
||||
</div>
|
||||
@@ -1,16 +1,18 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { client, getClient } from '$lib/lemmy.js'
|
||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||
import type { SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ params, url, fetch }) {
|
||||
const my_user = (await getClient().getSite()).my_user
|
||||
const my_user =
|
||||
get(profile)?.user ??
|
||||
(await client({ auth: get(profile)?.jwt }).getSite()).my_user
|
||||
|
||||
return {
|
||||
my_user: my_user,
|
||||
community_blocks: my_user?.community_blocks,
|
||||
person_blocks: my_user?.person_blocks,
|
||||
follows: my_user?.follows
|
||||
follows: my_user?.follows,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { searchParam } from '$lib/util'
|
||||
import { flip } from 'svelte/animate'
|
||||
import PictrsImage from './PictrsImage.svelte'
|
||||
import { expoInOut, expoOut } from 'svelte/easing'
|
||||
|
||||
export let data
|
||||
</script>
|
||||
|
||||
<Header>{$t('routes.profile.media.title')}</Header>
|
||||
<div class="media-grid">
|
||||
{#each data.images as image (image.local_image.pictrs_delete_token)}
|
||||
<div animate:flip={{ duration: 500, easing: expoInOut }}>
|
||||
<PictrsImage
|
||||
image={image.local_image}
|
||||
on:delete={() => {
|
||||
data.images = data.images.toSpliced(
|
||||
data.images.findIndex(
|
||||
(i) =>
|
||||
i.local_image.pictrs_delete_token ==
|
||||
image.local_image.pictrs_delete_token
|
||||
),
|
||||
1
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if data.images.length == 20}
|
||||
<Pageination
|
||||
page={Number($page.url.searchParams.get('page')) || 1}
|
||||
on:change={(p) => {
|
||||
searchParam($page.url, 'page', p.detail.toString())
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.media-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 768px) {
|
||||
.media-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1024px) {
|
||||
.media-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,16 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { client } from '$lib/lemmy.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ fetch, url }) {
|
||||
const { jwt } = get(profile)
|
||||
|
||||
let page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
const res = await client({ func: fetch, auth: jwt }).listMedia({
|
||||
limit: 20,
|
||||
page: page,
|
||||
})
|
||||
|
||||
return { images: res.images }
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import { instance } from '$lib/instance'
|
||||
import { client } from '$lib/lemmy'
|
||||
import { t } from '$lib/translations'
|
||||
import { instanceToURL } from '$lib/util'
|
||||
import type { LocalImage } from 'lemmy-js-client'
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { ArrowDown, ArrowDownTray, Icon, Trash } from 'svelte-hero-icons'
|
||||
|
||||
const dispatch = createEventDispatcher<{ delete: boolean }>()
|
||||
|
||||
let loading = false
|
||||
|
||||
async function deleteImage(image: LocalImage) {
|
||||
if (!$profile?.jwt) return
|
||||
|
||||
try {
|
||||
loading = true
|
||||
const res = await client().deleteImage({
|
||||
token: image.pictrs_delete_token,
|
||||
filename: image.pictrs_alias,
|
||||
})
|
||||
|
||||
dispatch('delete', res)
|
||||
} catch (e) {
|
||||
toast({ content: e as any, type: 'error' })
|
||||
}
|
||||
loading = false
|
||||
}
|
||||
|
||||
export let image: LocalImage
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<img
|
||||
src="{instanceToURL($instance)}/pictrs/image/{image.pictrs_alias}"
|
||||
width="500"
|
||||
height="500"
|
||||
class="aspect-square w-full h-full object-cover rounded-xl"
|
||||
alt="pictrs"
|
||||
/>
|
||||
<div class="flex items-center gap-2">
|
||||
<RelativeDate
|
||||
class="text-sm text-slate-700 dark:text-zinc-300"
|
||||
date={publishedToDate(image.published)}
|
||||
/>
|
||||
<Button
|
||||
title={$t('routes.profile.media.download')}
|
||||
href="{instanceToURL($instance)}/pictrs/image/{image.pictrs_alias}"
|
||||
size="square-md"
|
||||
class="ml-auto"
|
||||
>
|
||||
<Icon src={ArrowDownTray} size="16" mini slot="prefix" />
|
||||
</Button>
|
||||
<Button
|
||||
title={$t('post.actions.more.delete')}
|
||||
on:click={() => deleteImage(image)}
|
||||
size="square-md"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
>
|
||||
<Icon src={Trash} size="16" mini slot="prefix" color="text-red-500" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
Reference in new issue
Block a user