feat: add separate votes
This commit is contained in:
1 parent
ddb86800a0
commit
799b1fdbdc
4 files changed
+94
-49
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "1.19.0",
|
"version": "1.19.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
import { Button, Popover, toast } from 'mono-svelte'
|
import { Button, Popover, toast } from 'mono-svelte'
|
||||||
import { site } from '$lib/lemmy.js'
|
import { site } from '$lib/lemmy.js'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
import { userSettings } from '$lib/settings.js'
|
||||||
|
|
||||||
export let post: Post
|
export let post: Post
|
||||||
export let vote: number = 0
|
export let vote: number = 0
|
||||||
@@ -26,6 +27,16 @@
|
|||||||
const voteColor = (vote: number, border: boolean = false) =>
|
const voteColor = (vote: number, border: boolean = false) =>
|
||||||
vote == 1 ? `!text-blue-500` : vote == -1 ? `!text-red-500` : ''
|
vote == 1 ? `!text-blue-500` : vote == -1 ? `!text-red-500` : ''
|
||||||
|
|
||||||
|
const shouldShowVoteColor = (
|
||||||
|
vote: number,
|
||||||
|
type: 'upvotes' | 'downvotes'
|
||||||
|
): string =>
|
||||||
|
(vote == -1 && type == 'downvotes') ||
|
||||||
|
(vote == 1 && type == 'upvotes') ||
|
||||||
|
!$userSettings.separateVotes
|
||||||
|
? voteColor(vote)
|
||||||
|
: ''
|
||||||
|
|
||||||
const castVote = async (newVote: number) => {
|
const castVote = async (newVote: number) => {
|
||||||
if (!$profile?.jwt) {
|
if (!$profile?.jwt) {
|
||||||
toast({ content: 'You must be logged in to vote.', type: 'warning' })
|
toast({ content: 'You must be logged in to vote.', type: 'warning' })
|
||||||
@@ -41,58 +52,82 @@
|
|||||||
<slot {vote} {score}>
|
<slot {vote} {score}>
|
||||||
<!-- <Popover openOnHover placement="bottom"> -->
|
<!-- <Popover openOnHover placement="bottom"> -->
|
||||||
<div
|
<div
|
||||||
class=" flex items-center text-sm gap-1 rounded-md border border-slate-200
|
class="flex items-center text-sm rounded-md border border-slate-200
|
||||||
dark:border-zinc-800 bg-white dark:bg-zinc-900 px-1 h-8 cursor-pointer"
|
dark:border-zinc-800 bg-white dark:bg-zinc-900 px-1 h-8 cursor-pointer"
|
||||||
|
class:pr-2.5={$userSettings.separateVotes}
|
||||||
>
|
>
|
||||||
<Button
|
<div class="flex items-center">
|
||||||
aria-label="Upvote"
|
<Button
|
||||||
class={vote == 1
|
aria-label="Upvote"
|
||||||
? voteColor(vote)
|
class={vote == 1
|
||||||
: 'hover:dark:text-blue-600 hover:text-blue-500'}
|
? voteColor(vote)
|
||||||
on:click={async () => castVote(vote == 1 ? 0 : 1)}
|
: 'hover:dark:text-blue-600 hover:text-blue-500'}
|
||||||
size="square-sm"
|
on:click={async () => castVote(vote == 1 ? 0 : 1)}
|
||||||
color="tertiary"
|
size="square-sm"
|
||||||
alignment="center"
|
color="tertiary"
|
||||||
>
|
alignment="center"
|
||||||
<Icon src={ChevronUp} mini size="18" />
|
>
|
||||||
</Button>
|
<Icon src={ChevronUp} mini size="18" />
|
||||||
<span
|
</Button>
|
||||||
class="font-medium transition-colors duration-200 grid {voteColor(vote)}"
|
<span
|
||||||
class:hidden={$profile?.user?.local_user_view.local_user.show_scores ==
|
class="font-medium transition-colors duration-200 grid {shouldShowVoteColor(
|
||||||
false}
|
vote,
|
||||||
>
|
'upvotes'
|
||||||
{#key score}
|
)}"
|
||||||
|
class:hidden={$profile?.user?.local_user_view.local_user.show_scores ==
|
||||||
|
false}
|
||||||
|
>
|
||||||
|
{#key $userSettings.separateVotes ? upvotes : score}
|
||||||
|
<span
|
||||||
|
in:fly={{ y: -4, duration: 200 }}
|
||||||
|
out:fly={{ y: 4, duration: 200 }}
|
||||||
|
style="grid-column: 1; grid-row: 1;"
|
||||||
|
>
|
||||||
|
<FormattedNumber
|
||||||
|
number={$userSettings.separateVotes ? upvotes : score}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
{/key}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{#if $userSettings.separateVotes}
|
||||||
|
<div class="h-full py-1.5 pl-2 pr-0.5">
|
||||||
|
<div class="border-l dark:border-zinc-700 h-full" />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
<div class="flex items-center">
|
||||||
|
<Button
|
||||||
|
aria-label="Downvote"
|
||||||
|
class="{vote == -1 ? voteColor(vote) : ''} {$site?.site_view.local_site
|
||||||
|
.enable_downvotes
|
||||||
|
? 'hover:dark:text-red-600 hover:text-red-500'
|
||||||
|
: 'pointer-events-none opacity-50'}"
|
||||||
|
on:click={async () => castVote(vote == -1 ? 0 : -1)}
|
||||||
|
size="square-sm"
|
||||||
|
color="tertiary"
|
||||||
|
>
|
||||||
|
<Icon src={ChevronDown} mini size="18" />
|
||||||
|
</Button>
|
||||||
|
{#if $userSettings.separateVotes}
|
||||||
<span
|
<span
|
||||||
in:fly={{ y: score > oldScore ? 4 : -4, duration: 200 }}
|
class="font-medium transition-colors duration-200 grid {shouldShowVoteColor(
|
||||||
out:fly={{ y: score > oldScore ? -4 : 4, duration: 200 }}
|
vote,
|
||||||
style="grid-column: 1; grid-row: 1;"
|
'downvotes'
|
||||||
|
)}"
|
||||||
|
class:hidden={$profile?.user?.local_user_view.local_user
|
||||||
|
.show_scores == false}
|
||||||
>
|
>
|
||||||
<FormattedNumber number={score} />
|
{#key downvotes}
|
||||||
|
<span
|
||||||
|
in:fly={{ y: -4, duration: 200 }}
|
||||||
|
out:fly={{ y: 4, duration: 200 }}
|
||||||
|
style="grid-column: 1; grid-row: 1;"
|
||||||
|
>
|
||||||
|
<FormattedNumber number={downvotes} />
|
||||||
|
</span>
|
||||||
|
{/key}
|
||||||
</span>
|
</span>
|
||||||
{/key}
|
{/if}
|
||||||
</span>
|
</div>
|
||||||
<Button
|
|
||||||
aria-label="Downvote"
|
|
||||||
class="{vote == -1 ? voteColor(vote) : ''} {$site?.site_view.local_site
|
|
||||||
.enable_downvotes
|
|
||||||
? 'hover:dark:text-red-600 hover:text-red-500'
|
|
||||||
: 'pointer-events-none opacity-50'}"
|
|
||||||
on:click={async () => castVote(vote == -1 ? 0 : -1)}
|
|
||||||
size="square-sm"
|
|
||||||
color="tertiary"
|
|
||||||
>
|
|
||||||
<Icon src={ChevronDown} mini size="18" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="flex items-center gap-2">
|
|
||||||
<div class="flex items-center font-medium text-blue-500 gap-0.5">
|
|
||||||
<Icon src={ArrowUp} mini size="18" title="Upvotes" />
|
|
||||||
{upvotes}
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center font-medium text-red-500 gap-0.5">
|
|
||||||
<Icon src={ArrowDown} mini size="18" title="Downvotes" />
|
|
||||||
{downvotes}
|
|
||||||
</div>
|
|
||||||
</div> -->
|
|
||||||
<!-- </Popover> -->
|
|
||||||
</slot>
|
</slot>
|
||||||
@@ -71,6 +71,7 @@ interface Settings {
|
|||||||
|
|
||||||
newWidth: boolean
|
newWidth: boolean
|
||||||
markPostsAsRead: boolean
|
markPostsAsRead: boolean
|
||||||
|
separateVotes: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultSettings: Settings = {
|
export const defaultSettings: Settings = {
|
||||||
@@ -118,6 +119,7 @@ export const defaultSettings: Settings = {
|
|||||||
hidePhoton: toBool(env.PUBLIC_REMOVE_CREDIT) ?? false,
|
hidePhoton: toBool(env.PUBLIC_REMOVE_CREDIT) ?? false,
|
||||||
newWidth: true,
|
newWidth: true,
|
||||||
markPostsAsRead: true,
|
markPostsAsRead: true,
|
||||||
|
separateVotes: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const userSettings = writable(defaultSettings)
|
export const userSettings = writable(defaultSettings)
|
||||||
|
|||||||
@@ -159,6 +159,14 @@
|
|||||||
{$userSettings.markReadPosts ? 'Enabled' : 'Disabled'}
|
{$userSettings.markReadPosts ? 'Enabled' : 'Disabled'}
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting>
|
||||||
|
<span slot="title">Vote style</span>
|
||||||
|
<MultiSelect
|
||||||
|
options={[false, true]}
|
||||||
|
optionNames={['Combined', 'Separate']}
|
||||||
|
bind:selected={$userSettings.separateVotes}
|
||||||
|
/>
|
||||||
|
</Setting>
|
||||||
<Setting>
|
<Setting>
|
||||||
<span slot="title">NSFW blur</span>
|
<span slot="title">NSFW blur</span>
|
||||||
<span slot="description">
|
<span slot="description">
|
||||||
|
|||||||
Reference in new issue
Block a user