feat [1/2]: add topics & feeds listing
This commit is contained in:
1 parent
1a948281a8
commit
5ed8346027
22 files changed
+426
-124
No files matched your search
@@ -1,46 +1,5 @@
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte.js'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { ReactiveState } from '$lib/util.svelte'
|
||||
import { type ListingType, type SortType } from '$lib/client/types'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
const typeParam = url.searchParams.get('type')
|
||||
const typeInstance = typeParam?.split('instance-')[1]
|
||||
|
||||
const type = typeInstance
|
||||
? 'Local'
|
||||
: (typeParam as ListingType) || (LINKED_INSTANCE_URL ? 'Local' : 'All')
|
||||
|
||||
const sort = (url.searchParams.get('sort') as SortType) || 'TopDay'
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const query = url.searchParams.get('q') || ''
|
||||
|
||||
const communities =
|
||||
query != ''
|
||||
? await client({ func: fetch, instanceURL: typeInstance }).search({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: 'Communities',
|
||||
listing_type: type,
|
||||
q: query,
|
||||
})
|
||||
: await client({
|
||||
func: fetch,
|
||||
instanceURL: typeInstance,
|
||||
}).listCommunities({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: type,
|
||||
show_nsfw: true,
|
||||
})
|
||||
|
||||
return {
|
||||
communities: new ReactiveState(communities.communities),
|
||||
type: typeParam ?? type,
|
||||
sort: sort,
|
||||
query: query,
|
||||
page: page,
|
||||
}
|
||||
export function load() {
|
||||
redirect(302, '/explore/communities')
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte.js'
|
||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||
import { Header, SearchBar, Tabs } from '$lib/components/ui/layout'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||
import { Option } from 'mono-svelte'
|
||||
import { ServerStack } from 'svelte-hero-icons/dist'
|
||||
|
||||
let { data, children } = $props()
|
||||
|
||||
let search = $state(page.data.query || '')
|
||||
let form = $state<HTMLFormElement>()
|
||||
</script>
|
||||
|
||||
{#if client().getTopics && client().getFeeds}
|
||||
<Tabs
|
||||
routes={[
|
||||
{
|
||||
href: '/explore/communities',
|
||||
name: $t('routes.communities.title'),
|
||||
},
|
||||
{
|
||||
href: '/explore/feeds',
|
||||
name: $t('routes.explore.feeds'),
|
||||
},
|
||||
{
|
||||
href: '/explore/topics',
|
||||
name: $t('routes.explore.topics'),
|
||||
},
|
||||
]}
|
||||
></Tabs>
|
||||
{/if}
|
||||
|
||||
<svelte:head>
|
||||
<title>{$t('routes.explore.title')}</title>
|
||||
</svelte:head>
|
||||
|
||||
<Header pageHeader>
|
||||
{$t('routes.explore.title')}
|
||||
{#snippet extended()}
|
||||
{#if page.route.id == '/explore/communities'}
|
||||
<form
|
||||
method="get"
|
||||
action={page.url.pathname}
|
||||
class="contents"
|
||||
bind:this={form}
|
||||
>
|
||||
<SearchBar bind:query={search} />
|
||||
|
||||
<div class="flex flex-row flex-wrap gap-4 items-center">
|
||||
<Location
|
||||
name="type"
|
||||
selected={data.type}
|
||||
onchange={() => form?.requestSubmit()}
|
||||
>
|
||||
{#if !LINKED_INSTANCE_URL}
|
||||
{@const instanceSet = new Set(
|
||||
profile.meta.profiles.map((i) => i.instance),
|
||||
)}
|
||||
{#if instanceSet.size > 1}
|
||||
<Option disabled data-label="true">—</Option>
|
||||
{#each instanceSet as instance}
|
||||
<Option
|
||||
icon={ServerStack}
|
||||
value={encodeURIComponent(`instance-${instance}`)}
|
||||
>
|
||||
{instance}
|
||||
</Option>
|
||||
{/each}
|
||||
{/if}
|
||||
{/if}
|
||||
</Location>
|
||||
<Sort
|
||||
name="sort"
|
||||
selected={data.sort}
|
||||
onchange={() => form?.requestSubmit()}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Header>
|
||||
|
||||
{@render children?.()}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { ListingType, SortType } from '$lib/client/types'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||
|
||||
export function load({ url }) {
|
||||
const sort = (url.searchParams.get('sort') as SortType) || 'TopDay'
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const query = url.searchParams.get('q') || ''
|
||||
|
||||
const typeParam = url.searchParams.get('type')
|
||||
const typeInstance = typeParam?.split('instance-')[1]
|
||||
|
||||
const type = (
|
||||
typeInstance
|
||||
? 'Local'
|
||||
: typeParam || (LINKED_INSTANCE_URL ? 'Local' : 'All')
|
||||
) as ListingType
|
||||
|
||||
return {
|
||||
sort: sort,
|
||||
page: page,
|
||||
query: query,
|
||||
type: type,
|
||||
typeInstance: typeInstance,
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { navigating, page } from '$app/state'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||
import { CommunityItem } from '$lib/components/lemmy/community'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import Fixate from '$lib/components/ui/generic/Fixate.svelte'
|
||||
import Skeleton from '$lib/components/ui/generic/Skeleton.svelte'
|
||||
import CommonList from '$lib/components/ui/layout/CommonList.svelte'
|
||||
import { Header } from '$lib/components/ui/layout'
|
||||
import Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||
import { Material, Option } from 'mono-svelte'
|
||||
import { QuestionMarkCircle, ServerStack } from 'svelte-hero-icons'
|
||||
import { Material } from 'mono-svelte'
|
||||
import { QuestionMarkCircle } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly } from 'svelte/transition'
|
||||
import SearchBar from '../../lib/components/ui/layout/SearchBar.svelte'
|
||||
import Fixate from '$lib/components/ui/generic/Fixate.svelte'
|
||||
import { CommunityItem } from '$lib/components/lemmy/community'
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
let search = $state(data.query || '')
|
||||
let searchElement = $state<HTMLInputElement>()
|
||||
let form = $state<HTMLFormElement>()
|
||||
|
||||
let showTop = $derived(
|
||||
(data.query ?? '' != '') &&
|
||||
data.communities.value.length > 0 &&
|
||||
@@ -32,55 +22,6 @@
|
||||
)
|
||||
</script>
|
||||
|
||||
<svelte:window
|
||||
onkeydown={(e) => {
|
||||
if (e.target == document.body) searchElement?.focus()
|
||||
}}
|
||||
/>
|
||||
|
||||
<svelte:head>
|
||||
<title>{$t('routes.communities.title')}</title>
|
||||
</svelte:head>
|
||||
|
||||
<Header pageHeader>
|
||||
{$t('routes.communities.title')}
|
||||
{#snippet extended()}
|
||||
<form method="get" action="/communities" class="contents" bind:this={form}>
|
||||
<SearchBar bind:query={search} />
|
||||
|
||||
<div class="flex flex-row flex-wrap gap-4 items-center">
|
||||
<Location
|
||||
name="type"
|
||||
selected={data.type}
|
||||
onchange={() => form?.requestSubmit()}
|
||||
>
|
||||
{#if !LINKED_INSTANCE_URL}
|
||||
{@const instanceSet = new Set(
|
||||
profile.meta.profiles.map((i) => i.instance),
|
||||
)}
|
||||
{#if instanceSet.size > 1}
|
||||
<Option disabled data-label="true">—</Option>
|
||||
{#each instanceSet as instance}
|
||||
<Option
|
||||
icon={ServerStack}
|
||||
value={encodeURIComponent(`instance-${instance}`)}
|
||||
>
|
||||
{instance}
|
||||
</Option>
|
||||
{/each}
|
||||
{/if}
|
||||
{/if}
|
||||
</Location>
|
||||
<Sort
|
||||
name="sort"
|
||||
selected={data.sort}
|
||||
onchange={() => form?.requestSubmit()}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
{/snippet}
|
||||
</Header>
|
||||
|
||||
{#if navigating.to?.route.id == '/communities'}
|
||||
<div class="flex flex-col gap-3">
|
||||
{#each new Array(5) as _, index}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { ReactiveState } from '$lib/util.svelte'
|
||||
|
||||
export async function load({ fetch, parent }) {
|
||||
const { page, query, sort, type, typeInstance } = await parent()
|
||||
|
||||
const communities =
|
||||
query != ''
|
||||
? await client({ func: fetch, instanceURL: typeInstance }).search({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: 'Communities',
|
||||
listing_type: type,
|
||||
q: query,
|
||||
})
|
||||
: await client({
|
||||
func: fetch,
|
||||
instanceURL: typeInstance,
|
||||
}).listCommunities({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: type,
|
||||
show_nsfw: true,
|
||||
})
|
||||
|
||||
return {
|
||||
communities: new ReactiveState(communities.communities),
|
||||
type: type,
|
||||
sort: sort,
|
||||
query: query,
|
||||
page: page,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { CommonList } from '$lib/components/ui/layout'
|
||||
import FeedItem from './FeedItem.svelte'
|
||||
|
||||
let { data } = $props()
|
||||
</script>
|
||||
|
||||
<CommonList items={data.feeds.value}>
|
||||
{#snippet item(feed)}
|
||||
<FeedItem {feed} />
|
||||
{/snippet}
|
||||
</CommonList>
|
||||
@@ -0,0 +1,15 @@
|
||||
import { client } from '$lib/client/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/util.svelte'
|
||||
import { error } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ fetch }) {
|
||||
const piefed = client({ func: fetch })
|
||||
|
||||
if (!piefed.getFeeds) error(404, 'unsupported')
|
||||
|
||||
const feeds = await piefed.getFeeds({ include_communities: false })
|
||||
|
||||
return {
|
||||
feeds: new ReactiveState(feeds.feeds),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<script lang="ts">
|
||||
import type { FeedView } from '$lib/client/types'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Entity from '$lib/components/ui/Entity.svelte'
|
||||
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
||||
import CommonItem from '$lib/components/ui/layout/CommonItem.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { Button, modal } from 'mono-svelte'
|
||||
import { InformationCircle } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
feed: FeedView
|
||||
}
|
||||
|
||||
let { feed }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#snippet feedModal()}
|
||||
<Entity icon={feed.icon} name={feed.title} label={feed.name}></Entity>
|
||||
<Markdown source={feed.description} />
|
||||
<LabelStat
|
||||
label={$t('cards.community.members')}
|
||||
content={feed.subscriptions_count}
|
||||
/>
|
||||
{/snippet}
|
||||
|
||||
<CommonItem
|
||||
icon={feed.icon}
|
||||
title={feed.title}
|
||||
detail="{feed.name} • {feed.subscriptions_count}"
|
||||
href="/f/{feed.id}"
|
||||
>
|
||||
<Button
|
||||
onclick={() => modal({ title: $t('common.info'), snippet: feedModal })}
|
||||
color="ghost"
|
||||
size="custom"
|
||||
rounding="xl"
|
||||
class="h-8.5 aspect-square"
|
||||
icon={InformationCircle}
|
||||
aria-label={$t('common.info')}
|
||||
/>
|
||||
</CommonItem>
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { CommonList } from '$lib/components/ui/layout'
|
||||
import TopicItem from './TopicItem.svelte'
|
||||
|
||||
let { data } = $props()
|
||||
</script>
|
||||
|
||||
<CommonList items={data.topics.value}>
|
||||
{#snippet item(topic)}
|
||||
<TopicItem {topic} />
|
||||
{/snippet}
|
||||
</CommonList>
|
||||
@@ -0,0 +1,15 @@
|
||||
import { client } from '$lib/client/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/util.svelte'
|
||||
import { error } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ fetch }) {
|
||||
const piefed = client({ func: fetch })
|
||||
|
||||
if (!piefed.getTopics) error(404, 'unsupported')
|
||||
|
||||
const topics = await piefed.getTopics({ include_communities: false })
|
||||
|
||||
return {
|
||||
topics: new ReactiveState(topics.topics),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import type { TopicView } from '$lib/client/types'
|
||||
import CommonItem from '$lib/components/ui/layout/CommonItem.svelte'
|
||||
|
||||
interface Props {
|
||||
topic: TopicView
|
||||
}
|
||||
|
||||
let { topic }: Props = $props()
|
||||
</script>
|
||||
|
||||
<CommonItem title={topic.title ?? topic.name} href="/t/{topic.id}" />
|
||||
Reference in new issue
Block a user