From 5c04bdb677aeb9df012bff5c47e27c00c920b3af Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Sat, 5 Aug 2023 12:48:15 -0700 Subject: [PATCH] feat: add placeholder component --- src/lib/components/lemmy/post/Post.svelte | 2 +- src/lib/components/lemmy/post/PostFeed.svelte | 23 +++++++++ src/lib/components/ui/Card.svelte | 1 + src/lib/components/ui/Placeholder.svelte | 8 ++++ src/lib/lemmy.ts | 8 +--- src/routes/+page.svelte | 48 +++++-------------- src/routes/post/[instance]/+page.ts | 2 +- .../post/[instance]/[id=integer]/+page.svelte | 6 +-- 8 files changed, 48 insertions(+), 50 deletions(-) create mode 100644 src/lib/components/lemmy/post/PostFeed.svelte create mode 100644 src/lib/components/ui/Placeholder.svelte diff --git a/src/lib/components/lemmy/post/Post.svelte b/src/lib/components/lemmy/post/Post.svelte index c68b78ff..aef83734 100644 --- a/src/lib/components/lemmy/post/Post.svelte +++ b/src/lib/components/lemmy/post/Post.svelte @@ -15,7 +15,7 @@ export let hideCommunity = false - +
+ import Post from '$lib/components/lemmy/post/Post.svelte' + import { userSettings } from '$lib/settings.js' + import type { PostView } from 'lemmy-js-client' + import { fly } from 'svelte/transition' + + export let posts: PostView[] + + +{#each posts as post, index (post.post.id)} + {#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)} +
+ +
+ {/if} +{/each} diff --git a/src/lib/components/ui/Card.svelte b/src/lib/components/ui/Card.svelte index 6c8fd2f5..6d229dbd 100644 --- a/src/lib/components/ui/Card.svelte +++ b/src/lib/components/ui/Card.svelte @@ -18,6 +18,7 @@
diff --git a/src/lib/components/ui/Placeholder.svelte b/src/lib/components/ui/Placeholder.svelte new file mode 100644 index 00000000..931374c9 --- /dev/null +++ b/src/lib/components/ui/Placeholder.svelte @@ -0,0 +1,8 @@ +
+ + {#if $$slots.title} +

{/if} + +
diff --git a/src/lib/lemmy.ts b/src/lib/lemmy.ts index b37f06d7..e30c762f 100644 --- a/src/lib/lemmy.ts +++ b/src/lib/lemmy.ts @@ -1,11 +1,5 @@ -import { - type GetSiteResponse, - LemmyHttp, - type MyUserInfo, - type PersonView, -} from 'lemmy-js-client' +import { type GetSiteResponse, LemmyHttp } from 'lemmy-js-client' import { get, writable } from 'svelte/store' -import { env } from '$env/dynamic/public' import { profile } from '$lib/auth.js' import { error } from '@sveltejs/kit' import { LINKED_INSTANCE_URL, instance } from '$lib/instance.js' diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index db3e6c50..a79c3d30 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -15,6 +15,8 @@ import Sort from '$lib/components/lemmy/Sort.svelte' import { searchParam } from '$lib/util.js' import { userSettings } from '$lib/settings.js' + import PostFeed from '$lib/components/lemmy/post/PostFeed.svelte' + import Placeholder from '$lib/components/ui/Placeholder.svelte' export let data @@ -49,48 +51,22 @@ options={['Subscribed', 'Local', 'All']} disabled={[$profile?.jwt == undefined]} selected={data.listingType} - on:select={(e) => { - $page.url.searchParams.set('type', e.detail) - $page.url.searchParams.delete('page') - goto($page.url.toString(), { - invalidateAll: true, - }) - }} + on:select={(e) => searchParam($page.url, 'type', e.detail, 'page')} />
{#if data.posts.posts.length == 0} -
- -

No posts

- {#if data.listingType == 'Subscribed'} - - {/if} -
+ + + No posts + + {/if} - {#each data.posts.posts as post, index (post.post.id)} - {#if - !($userSettings.hidePosts.deleted && post.post.deleted) && - !($userSettings.hidePosts.removed && post.post.removed) - } -
- -
- {/if} - {/each} +
- import { - buildCommentsTree, - buildCommentsTreeAsync, - } from '$lib/components/lemmy/comment/comments.js' + import { buildCommentsTreeAsync } from '$lib/components/lemmy/comment/comments.js' import Comments from '$lib/components/lemmy/comment/Comments.svelte' import { isImage, isVideo } from '$lib/ui/image.js' import { getClient } from '$lib/lemmy.js' @@ -13,7 +10,6 @@ import { page } from '$app/stores' import PostActions from '$lib/components/lemmy/post/PostActions.svelte' import { ExclamationTriangle, Icon } from 'svelte-hero-icons' - import Link from '$lib/components/input/Link.svelte' import Spinner from '$lib/components/ui/loader/Spinner.svelte' import Card from '$lib/components/ui/Card.svelte' import PostLink from '$lib/components/lemmy/post/PostLink.svelte'