feat: design tweaks

This commit is contained in:
Xyphyn committed 2023-09-10 13:05:58 -07:00
1 parent 6660c53878
commit 6afb03ea2b
11 files changed
+238 -298

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "photon-lemmy",
"version": "1.4.3",
"version": "1.4.5",
"private": true,
"scripts": {
"dev": "vite dev",
+4 -7
View File
@@ -2,17 +2,14 @@
import { userSettings } from '$lib/settings.js'
import { Select } from 'mono-svelte'
import { Icon, ViewColumns } from 'svelte-hero-icons'
let value = `${$userSettings.showCompactPosts}`
$: $userSettings.showCompactPosts = value == 'true'
</script>
<Select bind:value>
<Select bind:value={$userSettings.view}>
<span slot="label" class="flex items-center gap-1">
<Icon src={ViewColumns} size="14" mini />
View
</span>
<option value="true">List</option>
<option value="false">Cards</option>
<option value="list">List</option>
<option value="card">Cards</option>
<option value="compact">Compact</option>
</Select>
@@ -80,66 +80,26 @@
`
</script>
{#if $userSettings.newVote}
<div
class="flex flex-row items-center rounded-md transition-colors
cursor-pointer h-[26px] gap-0.5 !text-slate-600 dark:!text-zinc-300"
>
<Button
on:click={upvote}
class={vote == 1
? voteColor(vote)
: '!text-slate-600 dark:!text-zinc-300'}
aria-label="Upvote"
size="square-sm"
color="tertiary"
>
<Icon src={ArrowUpCircle} width={19} mini={vote == 1} />
</Button>
<span class="text-sm font-medium {voteColor(vote)}">
<FormattedNumber number={score} />
</span>
<Button
on:click={downvote}
class={vote == -1
? voteColor(vote)
: '!text-slate-600 dark:!text-zinc-300'}
aria-label="Downvote"
size="square-sm"
color="tertiary"
>
<Icon src={ArrowDownCircle} width={19} mini={vote == -1} />
</Button>
</div>
{:else}<div
class="flex flex-row items-center rounded-md transition-colors
<div
class="flex flex-row items-center rounded-md transition-all
cursor-pointer h-[26px] border border-slate-200
dark:border-zinc-800"
>
<button
on:click={upvote}
class="px-1.5 {vote == 1 ? 'dark:text-blue-500 text-blue-600' : ''}"
aria-label="Upvote"
>
<button
on:click={upvote}
class="px-1.5 {vote == 1
? $userSettings.revertColors
? 'text-orange-500'
: 'dark:text-blue-500 text-blue-600'
: ''}"
aria-label="Upvote"
>
<Icon src={ChevronUp} width={19} mini />
</button>
<span class="text-sm font-medium {voteColor(vote)}">
<FormattedNumber number={score} />
</span>
<button
on:click={downvote}
class="px-1.5 {vote == -1
? $userSettings.revertColors
? 'dark:text-blue-500 text-blue-600'
: 'text-red-400'
: ''}"
aria-label="Downvote"
>
<Icon src={ChevronDown} width={19} mini />
</button>
</div>
{/if}
<Icon src={ChevronUp} width={19} mini />
</button>
<span class="text-sm font-medium {voteColor(vote)}">
<FormattedNumber number={score} />
</span>
<button
on:click={downvote}
class="px-1.5 {vote == -1 ? 'text-red-400' : ''}"
aria-label="Downvote"
>
<Icon src={ChevronDown} width={19} mini />
</button>
</div>
@@ -99,7 +99,7 @@
in:fly={{ opacity: 0, y: -4 }}
class={isParent
? 'divide-y dark:divide-zinc-800 divide-slate-200'
: 'pl-3.5 border-l-2 border-slate-200 dark:border-zinc-800 my-1'}
: 'pl-3.5 border-l border-slate-200 dark:border-zinc-800 my-1'}
>
{#each nodes as node (node.comment_view.comment.id)}
<Comment
@@ -123,15 +123,15 @@
loading={node.loading}
disabled={node.loading}
size="sm"
color="tertiary"
color="none"
alignment="left"
loaderWidth={18}
class="text-xs"
on:click={() => {
node.loading = true
fetchChildren(node).then(() => (node.loading = false))
}}
>
<Icon src={Plus} width={18} mini slot="prefix" />
<Icon src={PlusCircle} width={16} slot="prefix" />
{node.comment_view.counts.child_count} more
</Button>
</button>
@@ -86,9 +86,10 @@
<Menu origin="bottom-right">
<Button
class="hover:text-green-500 dark:text-zinc-400 text-slate-500"
class="hover:!text-green-500 dark:text-zinc-400 text-slate-500"
slot="target"
size="square-md"
color="ghost"
loading={acting}
{...$$restProps}
>
+147 -124
View File
@@ -11,155 +11,178 @@
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
import { bestImageURL, postLink } from '$lib/components/lemmy/post/helpers.js'
import Empty from '$lib/components/helper/Empty.svelte'
import { goto } from '$app/navigation'
export let post: PostView
export let actions: boolean = true
export let hideCommunity = false
export let compact: boolean = false
export let view: 'card' | 'list' | 'compact' = 'list'
let loaded = false
// hack because you cant use typescript types in svelte markup
const onclick = (e: any) => {
if (e.target?.id == post.post.id) {
goto(postLink(post.post))
}
}
</script>
<Material
color="distinct"
padding="none"
class="flex flex-col max-w-full min-w-0 w-full gap-2.5 {compact
? '!bg-transparent !border-0 py-5'
: 'p-5'}"
id={post.post.id}
class="relative max-w-full min-w-0 w-full group
{view == 'list' || view == 'compact'
? '!bg-transparent !border-0'
: 'p-5'} {view == 'list' ? 'py-5' : view == 'compact' ? 'py-4' : ''}"
>
<div class="flex flex-row gap-2 max-w-full w-full">
<div class="flex flex-col w-full gap-2">
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
id={post.post.id.toString()}
on:click={onclick}
class="relative flex flex-col gap-2.5 cursor-pointer"
>
{#if view == 'list' || view == 'compact'}
<div
class="absolute -inset-1 group-hover:-inset-4
transition-all -z-10 rounded-xl group-hover:bg-slate-100 group-hover:dark:bg-zinc-900"
/>
{/if}
<div class="flex flex-row gap-2 max-w-full w-full">
<div class="flex flex-col w-full gap-2">
<PostMeta
community={hideCommunity ? undefined : post.community}
user={post.creator}
published={new Date(post.post.published + 'Z')}
upvotes={post.counts.upvotes}
downvotes={post.counts.downvotes}
deleted={post.post.deleted}
removed={post.post.removed}
locked={post.post.locked}
featured={post.post.featured_local || post.post.featured_community}
nsfw={post.post.nsfw}
saved={post.saved}
/>
<a
href="/post/{getInstance()}/{post.post.id}"
class="font-medium max-w-full w-full break-words text-base"
style="word-break: break-word;"
class:text-slate-500={post.read && $userSettings.markReadPosts}
class:dark:text-zinc-400={post.read && $userSettings.markReadPosts}
>
<Markdown source={post.post.name} inline />
</a>
</div>
{#if !$userSettings.showCompactPosts}
{#if isImage(post.post.url)}
<!--disabled preloads here since most people will hover over every image while scrolling-->
<svelte:component
this={$userSettings.expandImages ? ExpandableImage : Empty}
url={bestImageURL(post.post, false, 2048)}
class="self-start max-w-full"
<div class="flex flex-col w-full gap-2">
<PostMeta
community={hideCommunity ? undefined : post.community}
user={post.creator}
published={new Date(post.post.published + 'Z')}
upvotes={post.counts.upvotes}
downvotes={post.counts.downvotes}
deleted={post.post.deleted}
removed={post.post.removed}
locked={post.post.locked}
featured={post.post.featured_local || post.post.featured_community}
nsfw={post.post.nsfw}
saved={post.saved}
/>
<a
href="/post/{getInstance()}/{post.post.id}"
class="font-medium max-w-full w-full break-words text-base"
style="word-break: break-word;"
class:text-slate-500={post.read && $userSettings.markReadPosts}
class:dark:text-zinc-400={post.read && $userSettings.markReadPosts}
>
<svelte:element
this={$userSettings.expandImages ? 'div' : 'a'}
href={postLink(post.post)}
class="self-start overflow-hidden z-10 relative bg-slate-200 dark:bg-zinc-800 rounded-md max-w-full"
data-sveltekit-preload-data="off"
aria-label={post.post.name}
<Markdown source={post.post.name} inline />
</a>
</div>
{#if $userSettings.view == 'card'}
{#if isImage(post.post.url)}
<!--disabled preloads here since most people will hover over every image while scrolling-->
<svelte:component
this={$userSettings.expandImages ? ExpandableImage : Empty}
url={bestImageURL(post.post, false, 2048)}
class="self-start max-w-full"
>
<picture
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
<svelte:element
this={$userSettings.expandImages ? 'div' : 'a'}
href={postLink(post.post)}
class="self-start overflow-hidden z-10 relative bg-slate-200 dark:bg-zinc-800 rounded-md max-w-full"
data-sveltekit-preload-data="off"
aria-label={post.post.name}
>
<source
srcset={bestImageURL(post.post, false, 512)}
media="(max-width: 256px)"
/>
<source
srcset={bestImageURL(post.post, false, 512)}
media="(max-width: 512px)"
/>
<picture
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
>
<source
srcset={bestImageURL(post.post, false, 512)}
media="(max-width: 256px)"
/>
<source
srcset={bestImageURL(post.post, false, 512)}
media="(max-width: 512px)"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src={bestImageURL(post.post, false, 1024)}
loading="lazy"
class="max-w-full w-max object-cover rounded-md max-h-[80vh] h-auto z-30 opacity-0 transition-opacity duration-300"
class:opacity-100={loaded}
width={512}
height={300}
class:blur-3xl={post.post.nsfw && $userSettings.nsfwBlur}
on:load={() => (loaded = true)}
/>
</picture>
</svelte:element>
</svelte:component>
{:else if post.post.url}
<PostLink
url={post.post.url}
thumbnail_url={post.post.thumbnail_url
? `${post.post.thumbnail_url}?format=webp&thumbnail=512`
: undefined}
nsfw={post.post.nsfw}
/>
{/if}
{/if}
{#if post.post.body && !post.post.nsfw && (view == 'list' || view == 'card')}
<div
class="text-sm relative overflow-hidden {view == 'list'
? `text-zinc-600 dark:text-zinc-400 max-h-24`
: 'text-slate-600 dark:text-zinc-400 max-h-48'}"
>
<Markdown inline source={post.post.body.slice(0, 400)} />
{#if post.post.body.length > (view == 'list' ? 200 : 600)}
<div
class="absolute bottom-0 w-full h-16 bg-gradient-to-b {view ==
'list'
? 'dark:from-zinc-950/0 dark:to-zinc-950 from-slate-50/0 to-slate-50'
: 'dark:from-zinc-900/0 dark:to-zinc-900 from-white/0 to-white'} "
/>
{/if}
</div>
{/if}
</div>
{#if ($userSettings.view == 'list' || $userSettings.view == 'compact') && (post.post.thumbnail_url || isImage(post.post.url))}
<div class="flex-none w-24 h-24">
{#if !$userSettings.expandImages || (post.post.thumbnail_url && !isImage(post.post.url))}
<a href={postLink(post.post)}>
{#if post.post.thumbnail_url}
<!-- svelte-ignore a11y-missing-attribute -->
<img
src={bestImageURL(post.post, false, 1024)}
src={bestImageURL(post.post, true)}
loading="lazy"
class="max-w-full w-max object-cover rounded-md max-h-[80vh] h-auto z-30 opacity-0 transition-opacity duration-300"
class:opacity-100={loaded}
width={512}
height={300}
class:blur-3xl={post.post.nsfw && $userSettings.nsfwBlur}
on:load={() => (loaded = true)}
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
</picture>
</svelte:element>
</svelte:component>
{:else if post.post.url}
<PostLink
url={post.post.url}
thumbnail_url={post.post.thumbnail_url
? `${post.post.thumbnail_url}?format=webp&thumbnail=512`
: undefined}
nsfw={post.post.nsfw}
/>
{/if}
{/if}
{#if post.post.body && !post.post.nsfw}
<div
class="text-sm relative overflow-hidden {compact
? `text-zinc-600 dark:text-zinc-400 max-h-24`
: 'text-slate-600 dark:text-zinc-400 max-h-48'}"
>
<Markdown inline source={post.post.body.slice(0, 400)} />
{#if post.post.body.length > (compact ? 200 : 600)}
<div
class="absolute bottom-0 w-full h-16 bg-gradient-to-b {compact
? 'dark:from-zinc-950/0 dark:to-zinc-950 from-slate-50/0 to-slate-50'
: 'dark:from-zinc-900/0 dark:to-zinc-900 from-white/0 to-white'} "
/>
{/if}
</a>
{:else}
<ExpandableImage url={bestImageURL(post.post, false, 2048)}>
{#if post.post.thumbnail_url}
<!-- svelte-ignore a11y-missing-attribute -->
<img
src={bestImageURL(post.post, true)}
loading="lazy"
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
{/if}
</ExpandableImage>
{/if}
</div>
{/if}
</div>
{#if $userSettings.showCompactPosts && (post.post.thumbnail_url || isImage(post.post.url))}
<div class="flex-none w-24 h-24">
{#if !$userSettings.expandImages || (post.post.thumbnail_url && !isImage(post.post.url))}
<a href={postLink(post.post)}>
{#if post.post.thumbnail_url}
<!-- svelte-ignore a11y-missing-attribute -->
<img
src={bestImageURL(post.post, true)}
loading="lazy"
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
{/if}
</a>
{:else}
<ExpandableImage url={bestImageURL(post.post, false, 2048)}>
{#if post.post.thumbnail_url}
<!-- svelte-ignore a11y-missing-attribute -->
<img
src={bestImageURL(post.post, true)}
loading="lazy"
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
{/if}
</ExpandableImage>
{/if}
{#if actions}
<div class="w-full" class:mt-2={view == 'list'}>
<PostActions
bind:post
on:edit={(e) => {
toast({
content: 'The post was edited successfully.',
type: 'success',
})
}}
/>
</div>
{/if}
</div>
{#if actions}
<div class="w-full" class:mt-2={compact}>
<PostActions
bind:post
on:edit={(e) => {
toast({
content: 'The post was edited successfully.',
type: 'success',
})
}}
/>
</div>
{/if}
</Material>
@@ -106,7 +106,12 @@
<DebugObject object={post} bind:open={debug} />
{/await}
{/if}
<Button on:click={() => (debug = true)} size="square-md">
<Button
on:click={() => (debug = true)}
size="square-md"
color="ghost"
class="text-slate-600 dark:text-zinc-400"
>
<Icon src={BugAnt} mini size="16" slot="prefix" />
</Button>
{/if}
@@ -122,7 +127,7 @@
<Button
slot="target"
aria-label="Post actions"
class="hover:text-inherit h-8"
color="ghost"
size="square-md"
>
<Icon slot="prefix" src={EllipsisHorizontal} width={16} mini />
@@ -11,10 +11,11 @@
</script>
<div
class="flex flex-col {!$userSettings.showCompactPosts
class="flex flex-col {$userSettings.view == 'card'
? 'gap-3 md:gap-4'
: ''} divide-slate-200 dark:divide-zinc-800"
class:divide-y={$userSettings.showCompactPosts}
class:divide-y={$userSettings.view == 'compact' ||
$userSettings.view == 'list'}
>
{#if posts.length == 0}
<div class="h-full grid place-items-center">
@@ -40,7 +41,7 @@
delay: index < 4 ? index * 100 : 0,
}}
>
<Post compact={$userSettings.showCompactPosts} {post} />
<Post view={$userSettings.view} {post} />
</div>
{/if}
{/each}
+28 -71
View File
@@ -21,36 +21,34 @@
export let downvotes: number = 0
export let score: number
const voteColor = (vote: number) =>
vote == 1
? $userSettings.revertColors
? '!text-orange-500'
: '!text-blue-500 dark:!text-blue-400'
: vote == -1
? $userSettings.revertColors
? '!text-blue-500'
: '!text-red-500'
: ''
const voteColor = (vote: number, border: boolean = false) =>
vote == 1 ? `!text-blue-500` : vote == -1 ? `!text-red-500` : ''
</script>
<slot {vote} {score}>
{#if $userSettings.newVote}
<div class="flex items-center text-sm rounded-md border-zinc-800">
<Popover targetClass="h-8" openOnHover>
<div
class=" flex items-center text-sm gap-1 rounded-md border border-slate-200
dark:border-zinc-700 px-1 h-8 duration-200 dark:bg-zinc-900"
slot="target"
>
<Button
aria-label="Upvote"
class={vote == 1 ? voteColor(vote) : ''}
on:click={async () => {
if (!$profile?.jwt) return
score = await voteItem(post, vote == 1 ? 0 : 1, $profile.jwt)
vote = vote == 1 ? 0 : 1
score = await voteItem(post, vote == 1 ? 0 : 1, $profile.jwt)
}}
size="square-md"
size="square-sm"
color="tertiary"
alignment="center"
>
<Icon src={ArrowUpCircle} mini={vote == 1} size="20" />
<Icon src={ChevronUp} mini size="18" />
</Button>
<span class="font-medium {voteColor(vote)}">
<span
class="font-medium transition-colors duration-200 {voteColor(vote)}"
>
<FormattedNumber number={score} />
</span>
<Button
@@ -58,65 +56,24 @@
class={vote == -1 ? voteColor(vote) : ''}
on:click={async () => {
if (!$profile?.jwt) return
score = await voteItem(post, vote == -1 ? 0 : -1, $profile.jwt)
vote = vote == -1 ? 0 : -1
score = await voteItem(post, vote == -1 ? 0 : -1, $profile.jwt)
}}
size="square-md"
size="square-sm"
color="tertiary"
>
<Icon src={ArrowDownCircle} mini={vote == -1} size="20" />
<Icon src={ChevronDown} mini size="18" />
</Button>
</div>
{:else}
<Popover targetClass="h-8" openOnHover>
<div
class="flex items-center text-sm gap-1 rounded-md border border-slate-200
dark:border-zinc-700 px-1 h-8 duration-200 dark:bg-zinc-900"
slot="target"
>
<Button
aria-label="Upvote"
class={vote == 1 ? voteColor(vote) : ''}
on:click={async () => {
if (!$profile?.jwt) return
score = await voteItem(post, vote == 1 ? 0 : 1, $profile.jwt)
vote = vote == 1 ? 0 : 1
}}
size="square-sm"
color="tertiary"
alignment="center"
>
<Icon src={ChevronUp} mini size="18" />
</Button>
<span
class="font-medium transition-colors duration-200 {voteColor(vote)}"
>
<FormattedNumber number={score} />
</span>
<Button
aria-label="Downvote"
class={vote == -1 ? voteColor(vote) : ''}
on:click={async () => {
if (!$profile?.jwt) return
score = await voteItem(post, vote == -1 ? 0 : -1, $profile.jwt)
vote = vote == -1 ? 0 : -1
}}
size="square-sm"
color="tertiary"
>
<Icon src={ChevronDown} mini size="18" />
</Button>
</div>
<div class="flex flex-row items-center gap-2">
<span class="flex items-center gap-1 text-blue-500 font-medium">
<Icon src={ArrowUp} mini size="18" />
<FormattedNumber number={upvotes} />
</span>
<span class="flex items-center gap-1 text-red-500 font-medium">
<Icon src={ArrowDown} mini size="18" />
<FormattedNumber number={downvotes} />
</span>
</div>
</Popover>
{/if}
<div class="flex flex-row items-center gap-2">
<span class="flex items-center gap-1 text-blue-500 font-medium">
<Icon src={ArrowUp} mini size="18" />
<FormattedNumber number={upvotes} />
</span>
<span class="flex items-center gap-1 text-red-500 font-medium">
<Icon src={ArrowDown} mini size="18" />
<FormattedNumber number={downvotes} />
</span>
</div>
</Popover>
</slot>
+7 -6
View File
@@ -16,17 +16,21 @@ const toBool = (str: string | undefined) => {
}
interface Settings {
newComments: boolean
expandableImages: boolean
// should have been named "fade" read posts
markReadPosts: boolean
// ???
instance?: string
revertColors: boolean
showInstances: {
user: boolean
community: boolean
comments: boolean
}
// deprecated
showCompactPosts: boolean
view: 'card' | 'list' | 'compact'
defaultSort: {
sort: SortType
feed: 'All' | 'Subscribed' | 'Local'
@@ -36,7 +40,6 @@ interface Settings {
deleted: boolean
removed: boolean
}
fullWidthLayout: boolean
expandSidebar: boolean
notifications: {
enabled: boolean
@@ -58,10 +61,8 @@ interface Settings {
}
export const defaultSettings: Settings = {
newComments: true,
expandableImages: toBool(env.PUBLIC_EXPANDABLE_IMAGES) ?? true,
markReadPosts: toBool(env.PUBLIC_MARK_READ_POSTS) ?? true,
revertColors: toBool(env.PUBLIC_REVERT_VOTE_COLORS) ?? false,
showInstances: {
user: toBool(env.PUBLIC_SHOW_INSTANCES_USER) ?? false,
community: toBool(env.PUBLIC_SHOW_INSTANCES_COMMUNITY) ?? true,
@@ -77,7 +78,6 @@ export const defaultSettings: Settings = {
deleted: toBool(env.PUBLIC_HIDE_DELETED) ?? true,
removed: toBool(env.PUBLIC_HIDE_REMOVED) ?? false,
},
fullWidthLayout: toBool(env.PUBLIC_FULL_WIDTH_LAYOUT) ?? false,
expandSidebar: toBool(env.PUBLIC_EXPAND_SIDEBAR) ?? true,
notifications: {
enabled: false,
@@ -95,6 +95,7 @@ export const defaultSettings: Settings = {
debugInfo: false,
systemUI: true,
expandImages: true,
view: 'list',
}
export const userSettings = writable(defaultSettings)
+14 -19
View File
@@ -75,6 +75,19 @@
</div>
</div>
</Setting>
<Setting>
<span slot="title">Post style</span>
<ViewSelect />
<p>
{#if $userSettings.view == 'list'}
Show posts in a list, with post bodies and compact images.
{:else if $userSettings.view == 'compact'}
Show posts in a list, without post bodies and with tighter spacing.
{:else if $userSettings.view == 'card'}
Show posts in cards, with large images.
{/if}
</p>
</Setting>
<Setting>
<span slot="title">Hide Posts</span>
<span slot="description">
@@ -117,34 +130,16 @@
<SectionTitle class="mt-4">UI</SectionTitle>
<Setting>
<Checkbox bind:checked={$userSettings.markReadPosts} slot="title">
Mark read posts
Fade read posts
</Checkbox>
<span slot="description">Fade the title of posts you've already read.</span>
</Setting>
<Setting>
<Checkbox bind:checked={$userSettings.revertColors} slot="title">
Revert vote colors
</Checkbox>
<span slot="description">
Make upvotes orange and downvotes blue, like Reddit used to do.
</span>
</Setting>
<Setting>
<span slot="title">Post style</span>
<ViewSelect />
</Setting>
<Setting>
<Checkbox bind:checked={$userSettings.nsfwBlur} slot="title">
NSFW blur
</Checkbox>
<span slot="description">Blur images of NSFW content.</span>
</Setting>
<Setting>
<Checkbox bind:checked={$userSettings.newVote} slot="title">
New vote design
</Checkbox>
<span slot="description">Alternate vote design</span>
</Setting>
<Setting>
<Checkbox bind:checked={$userSettings.expandImages} slot="title">
Expand Images