feat: add community cards with a hacky slot parameter

This commit is contained in:
Xyphyn committed 2023-10-09 16:21:50 -07:00
1 parent b65d78b973
commit d2b27803b4
9 files changed
+78 -39

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "photon-lemmy", "name": "photon-lemmy",
"version": "1.17.4", "version": "1.18.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
+11 -1
View File
@@ -1,4 +1,7 @@
// See https://kit.svelte.dev/docs/types#app // See https://kit.svelte.dev/docs/types#app
import type { ComponentType, SvelteComponent } from 'svelte'
// for information about these interfaces // for information about these interfaces
declare global { declare global {
namespace App { namespace App {
@@ -6,7 +9,14 @@ declare global {
interface Locals { interface Locals {
instance?: string instance?: string
} }
// interface PageData {} interface PageData {
slots?: {
sidebar?: {
component?: ComponentType
props?: any
}
}
}
// interface Platform {} // interface Platform {}
} }
declare const __VERSION__: string declare const __VERSION__: string
+1 -1
View File
@@ -253,8 +253,8 @@ instance.subscribe(async (i) => {
export async function setUserID(id: number) { export async function setUserID(id: number) {
const pd = get(profileData) const pd = get(profileData)
if (id == -1) { if (id == -1) {
instance.set(DEFAULT_INSTANCE_URL)
resetProfile() resetProfile()
instance.set(DEFAULT_INSTANCE_URL)
return return
} }
+5 -6
View File
@@ -25,7 +25,7 @@
export let version: string | undefined = undefined export let version: string | undefined = undefined
</script> </script>
<StickyCard> <StickyCard class="w-full {$$props.class}">
<div class="flex flex-row gap-3 items-center"> <div class="flex flex-row gap-3 items-center">
{#if site.site.icon} {#if site.site.icon}
<Avatar width={42} url={site.site.icon} alt={site.site.name} /> <Avatar width={42} url={site.site.icon} alt={site.site.name} />
@@ -59,20 +59,19 @@
<FormattedNumber number={site.counts.communities} /> <FormattedNumber number={site.counts.communities} />
</span> </span>
</div> </div>
<div class="flex flex-row items-center"> <div class="flex flex-col 3xl:flex-row 3xl:items-center gap-2 3xl:gap-0">
<Button href="/modlog" size="sm" class="rounded-r-none"> <Button href="/modlog" class="3xl:rounded-r-none">
<Icon src={Newspaper} size="16" mini /> <Icon src={Newspaper} size="16" mini />
Modlog Modlog
</Button> </Button>
<Button <Button
href="/legal" href="/legal"
size="sm" class="3xl:rounded-l-none 3xl:rounded-r-none 3xl:border-x-0"
class="rounded-l-none rounded-r-none border-x-0"
> >
<Icon src={BuildingOffice} size="16" mini /> <Icon src={BuildingOffice} size="16" mini />
Legal Legal
</Button> </Button>
<Button href="/instances" size="sm" class="rounded-l-none"> <Button href="/instances" class="3xl:rounded-l-none">
<Icon src={ServerStack} size="16" mini /> <Icon src={ServerStack} size="16" mini />
Instances Instances
</Button> </Button>
@@ -141,18 +141,21 @@
</Modal> </Modal>
{/if} {/if}
<StickyCard> <StickyCard class="min-w-full {$$props.class}">
<div class="flex flex-row gap-3 items-center"> <div class="flex flex-row gap-3 items-center">
<div class="flex-shrink-0"> <div class="flex-shrink-0">
<Avatar <Avatar
width={48} width={42}
url={community_view.community.icon} url={community_view.community.icon}
alt={community_view.community.name} alt={community_view.community.name}
/> />
</div> </div>
<div class="flex flex-col gap-0"> <div class="flex flex-col gap-0">
<h1 class="font-bold text-xl">{community_view.community.title}</h1> <h1 class="font-bold text-xl">{community_view.community.title}</h1>
<span class="dark:text-zinc-400 text-slate-600 text-sm"> <span
class="dark:text-zinc-400 text-slate-600 text-sm break-words max-w-full"
style="word-break: break-all;"
>
!{community_view.community.name}@{new URL( !{community_view.community.name}@{new URL(
community_view.community.actor_id community_view.community.actor_id
).hostname} ).hostname}
@@ -209,7 +212,6 @@
<div class="w-full mt-2 flex flex-col gap-2"> <div class="w-full mt-2 flex flex-col gap-2">
<Button <Button
href="/create/post" href="/create/post"
color="ghost"
size="lg" size="lg"
disabled={community_view.community.posting_restricted_to_mods} disabled={community_view.community.posting_restricted_to_mods}
> >
@@ -219,7 +221,6 @@
<Button <Button
disabled={loading.subscribing} disabled={loading.subscribing}
loading={loading.subscribing} loading={loading.subscribing}
color="ghost"
size="lg" size="lg"
on:click={subscribe} on:click={subscribe}
> >
+6 -6
View File
@@ -29,8 +29,8 @@
> >
<slot <slot
name="sidebar" name="sidebar"
class="hidden md:flex sticky top-16 justify-self-end left-0 w-full max-w-full" class="hidden md:flex sticky top-16 left-0 w-full max-w-full"
style="grid-area: sidebar; max-width: 20rem;" style="grid-area: sidebar; width: 100% !important;"
/> />
<slot <slot
name="main" name="main"
@@ -39,8 +39,8 @@
/> />
<slot <slot
name="suffix" name="suffix"
class="hidden xl:flex w-full justify-self-start" class="max-xl:hidden w-full"
style="grid-area: suffix; max-width: 20rem;" style="grid-area: suffix;"
/> />
</div> </div>
</div> </div>
@@ -76,13 +76,13 @@
@media (min-width: 1280px) { @media (min-width: 1280px) {
.content { .content {
grid-template-columns: 1fr 3fr 1fr; grid-template-columns: 20% 1fr 20%;
justify-items: end center start; justify-items: end center start;
grid-template-areas: 'sidebar main suffix'; grid-template-areas: 'sidebar main suffix';
} }
} }
.limit-width { .limit-width {
max-width: 96rem; max-width: 100rem;
} }
</style> </style>
+7 -1
View File
@@ -112,7 +112,13 @@
<slot /> <slot />
</main> </main>
<div slot="suffix" let:class={c} let:style={s} class={c} style={s}> <div slot="suffix" let:class={c} let:style={s} class={c} style={s}>
{#if $site} {#if $page.data.slots?.sidebar?.component}
<svelte:component
this={$page.data.slots.sidebar.component}
{...$page.data.slots.sidebar.props}
class={c}
/>
{:else if $site}
<SiteCard <SiteCard
site={$site.site_view} site={$site.site_view}
taglines={$site.taglines} taglines={$site.taglines}
+14 -18
View File
@@ -1,29 +1,25 @@
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
import { getClient } from '$lib/lemmy.js' import { getClient } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import type { ListingType, SortType } from 'lemmy-js-client' import type { ListingType, SortType } from 'lemmy-js-client'
import { get } from 'svelte/store' import { get } from 'svelte/store'
export async function load(req: any) { export async function load(req: any) {
const cursor: string | undefined = req.url.searchParams.get('cursor') const community = await getClient(undefined, req.fetch).getCommunity({
const page = Number(req.url.searchParams.get('page')) || undefined name: req.params.name,
})
const sort: SortType =
(req.url.searchParams.get('sort') as SortType) ||
get(userSettings).defaultSort.sort
return { return {
sort: sort, community: community,
page: page || 1, slots: {
posts: getClient(undefined, req.fetch).getPosts({ sidebar: {
limit: 40, component: CommunityCard,
community_name: req.params.name, props: {
page: page, community_view: community.community_view,
sort: sort, moderators: community.moderators,
page_cursor: cursor },
}), },
community: getClient(undefined, req.fetch).getCommunity({ },
name: req.params.name,
}),
} }
} }
+27
View File
@@ -0,0 +1,27 @@
import { client } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js'
import type { SortType } from 'lemmy-js-client'
import { get } from 'svelte/store'
export async function load({ params, fetch, url }) {
const cursor: string | undefined = url.searchParams.get('cursor') as
| string
| undefined
const page = Number(url.searchParams.get('page')) || undefined
const sort: SortType =
(url.searchParams.get('sort') as SortType) ||
get(userSettings).defaultSort.sort
return {
sort: sort,
page: page || 1,
posts: client({ func: fetch }).getPosts({
limit: 40,
community_name: params.name,
page: page,
sort: sort,
page_cursor: cursor,
}),
}
}