feat: add card view

This commit is contained in:
Xyphyn committed 2023-08-23 18:15:04 -07:00
1 parent 22ce7bf39e
commit 861fb4949a
4 files changed
+111 -42

No files matched your search

+2
View File
@@ -49,6 +49,7 @@ interface Settings {
} }
newVote: boolean newVote: boolean
randomPlaceholders: boolean randomPlaceholders: boolean
modlogCardView: boolean | undefined
} }
export const defaultSettings: Settings = { export const defaultSettings: Settings = {
@@ -85,6 +86,7 @@ export const defaultSettings: Settings = {
}, },
newVote: toBool(env.PUBLIC_NEW_VOTE_BUTTONS) ?? false, newVote: toBool(env.PUBLIC_NEW_VOTE_BUTTONS) ?? false,
randomPlaceholders: toBool(env.PUBLIC_RANDOM_PLACEHOLDERS) ?? true, randomPlaceholders: toBool(env.PUBLIC_RANDOM_PLACEHOLDERS) ?? true,
modlogCardView: toBool(env.PUBLIC_MODLOG_CARD_VIEW) ?? undefined,
} }
export const userSettings = writable(defaultSettings) export const userSettings = writable(defaultSettings)
+52 -37
View File
@@ -1,13 +1,13 @@
<script lang="ts"> <script lang="ts">
import Card from '$lib/components/ui/Card.svelte'
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
import ModlogItem from './ModlogItem.svelte'
import Pageination from '$lib/components/ui/Pageination.svelte' import Pageination from '$lib/components/ui/Pageination.svelte'
import { searchParam } from '$lib/util.js' import { searchParam } from '$lib/util.js'
import { page } from '$app/stores' import { page } from '$app/stores'
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte' import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import MultiSelect from '$lib/components/input/MultiSelect.svelte' import MultiSelect from '$lib/components/input/MultiSelect.svelte'
import { userSettings } from '$lib/settings.js'
import ModlogItemCard from './item/ModlogItemCard.svelte'
import ModlogItemTable from './item/ModlogItemTable.svelte'
export let data export let data
</script> </script>
@@ -70,42 +70,57 @@
searchParam($page.url, 'community', e.detail?.id.toString(), 'page')} searchParam($page.url, 'community', e.detail?.id.toString(), 'page')}
/> />
</div> </div>
<MultiSelect
options={[false, true, undefined]}
optionNames={['Table', 'Cards', 'Default']}
selected={$userSettings.modlogCardView ??
!window.matchMedia('(min-width: 1600px)').matches}
on:select={(e) => ($userSettings.modlogCardView = e.detail)}
/>
</div> </div>
{#if data.modlog} {#if data.modlog}
<div style="width:100%; overflow-x: auto;"> {#if $userSettings.modlogCardView ?? !window.matchMedia('(min-width: 1600px)').matches}
<table <div class="flex flex-col gap-4">
class="table overflow-x-auto table-fixed relative" {#each data.modlog as modlog}
style="min-width: 800px;" <ModlogItemCard item={modlog} />
> {/each}
<colgroup class="table-fixed"> </div>
<col width="8%" /> {:else}
<col width="18%" /> <div style="width:100%; overflow-x: auto;">
<col width="12%" class="overflow-x-auto" /> <table
<col width="8%" /> class="table overflow-x-auto table-fixed relative"
<col width="10%" /> style="min-width: 800px;"
<col width="18%" /> >
<col width="20%" /> <colgroup class="table-fixed">
<col width="20%" /> <col width="8%" />
</colgroup> <col width="18%" />
<thead class="text-left sticky top-0"> <col width="12%" class="overflow-x-auto" />
<tr class="rounded-t-lg overflow-hidden"> <col width="8%" />
<th>Time</th> <col width="10%" />
<th>Moderator</th> <col width="18%" />
<th>Action</th> <col width="20%" />
<th>User</th> <col width="20%" />
<th>Community</th> </colgroup>
<th>Content</th> <thead class="text-left sticky top-0">
<th>Reason</th> <tr class="rounded-t-lg overflow-hidden">
<th>Link</th> <th>Time</th>
</tr> <th>Moderator</th>
</thead> <th>Action</th>
<tbody class="text-sm"> <th>User</th>
{#each data.modlog as modlog} <th>Community</th>
<ModlogItem item={modlog} /> <th>Content</th>
{/each} <th>Reason</th>
</tbody> <th>Link</th>
</table> </tr>
</div> </thead>
<tbody class="text-sm">
{#each data.modlog as modlog}
<ModlogItemTable item={modlog} />
{/each}
</tbody>
</table>
</div>
{/if}
{/if} {/if}
<Pageination <Pageination
page={data.page} page={data.page}
@@ -0,0 +1,55 @@
<script lang="ts">
import Link from '$lib/components/input/Link.svelte'
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Card from '$lib/components/ui/Card.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import type { ModLog } from '../+page.js'
import ModlogAction from '../ModlogAction.svelte'
export let item: ModLog
</script>
<Card elevation={0} class="p-5 flex flex-col gap-2 text-sm">
<div class="flex flex-row justify-between flex-wrap gap-2">
{#if item.community}
<CommunityLink community={item.community} avatar showInstance />
{/if}
<SectionTitle class="font-normal">
<RelativeDate date={new Date(item.timestamp)} />
</SectionTitle>
</div>
{#if item.actionName}
<SectionTitle class="mt-2">Action</SectionTitle>
<span class="text-base">
<ModlogAction action={item.actionName} />
</span>
{/if}
{#if item.moderator}
<SectionTitle class="mt-2">Moderator</SectionTitle>
<span
class="flex items-center gap-1 text-green-600 dark:text-green-400 font-medium"
>
<UserLink showInstance={true} avatar user={item.moderator} />
<ShieldIcon filled width={16} />
</span>
{/if}
{#if item.moderatee}
<SectionTitle class="mt-2">User</SectionTitle>
<UserLink showInstance={true} avatar user={item.moderatee} />
{/if}
{#if item.link || item.content}
<SectionTitle class="mt-2">Submission</SectionTitle>
{#if item.link && item.content}
<Link href={item.link} highlight>
{item.content}
</Link>
{:else if item.content}
<p class="text-xs">{item.content}</p>
{:else if item.link}
<Link href={item.link} highlight />
{/if}
{/if}
</Card>
@@ -2,12 +2,9 @@
import Link from '$lib/components/input/Link.svelte' import Link from '$lib/components/input/Link.svelte'
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte' import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte' import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Card from '$lib/components/ui/Card.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte' import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import { Icon, Trash, XCircle } from 'svelte-hero-icons' import type { ModLog } from '../+page.js'
import type { ModLog } from './+page.js' import ModlogAction from '../ModlogAction.svelte'
import ModlogAction from './ModlogAction.svelte'
export let item: ModLog export let item: ModLog
</script> </script>