feat: add voting animations, close #155

This commit is contained in:
Xyphyn committed 2023-09-24 14:31:59 -07:00
1 parent 380fa48ffb
commit 11f5bb10be
4 files changed
+31 -17

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "photon-lemmy", "name": "photon-lemmy",
"version": "1.11.1", "version": "1.11.2",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
@@ -8,6 +8,7 @@
import { fly } from 'svelte/transition' import { fly } from 'svelte/transition'
export let posts: PostView[] export let posts: PostView[]
export let community: boolean = false
</script> </script>
<div <div
@@ -40,7 +41,7 @@
delay: index < 4 ? index * 100 : 0, delay: index < 4 ? index * 100 : 0,
}} }}
> >
<Post view={$userSettings.view} bind:post /> <Post hideCommunity={community} view={$userSettings.view} bind:post />
</div> </div>
{/if} {/if}
{/each} {/each}
+27 -14
View File
@@ -1,18 +1,31 @@
<script lang="ts"> <script lang="ts">
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte' import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import type { Post } from 'lemmy-js-client' import type { Post } from 'lemmy-js-client'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons' import { ChevronDown, ChevronUp, Icon, Key } from 'svelte-hero-icons'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import { vote as voteItem } from '$lib/lemmy/contentview.js' import { vote as voteItem } from '$lib/lemmy/contentview.js'
import { Button } from 'mono-svelte' import { Button, toast } from 'mono-svelte'
import { site } from '$lib/lemmy.js' import { site } from '$lib/lemmy.js'
import { fly } from 'svelte/transition'
export let post: Post export let post: Post
export let vote: number = 0 export let vote: number = 0
export let score: number export let score: number
let oldScore = score
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 castVote = async (newVote: number) => {
if (!$profile?.jwt) {
toast({ content: 'You must be logged in to vote.', type: 'warning' })
return
}
oldScore = score
vote = newVote
score = await voteItem(post, newVote, $profile.jwt)
}
</script> </script>
<slot {vote} {score}> <slot {vote} {score}>
@@ -23,11 +36,7 @@
<Button <Button
aria-label="Upvote" aria-label="Upvote"
class={vote == 1 ? voteColor(vote) : ''} class={vote == 1 ? voteColor(vote) : ''}
on:click={async () => { on:click={async () => castVote(vote == 1 ? 0 : 1)}
if (!$profile?.jwt) return
vote = vote == 1 ? 0 : 1
score = await voteItem(post, vote, $profile.jwt)
}}
size="square-sm" size="square-sm"
color="tertiary" color="tertiary"
alignment="center" alignment="center"
@@ -35,11 +44,19 @@
<Icon src={ChevronUp} mini size="18" /> <Icon src={ChevronUp} mini size="18" />
</Button> </Button>
<span <span
class="font-medium transition-colors duration-200 {voteColor(vote)}" class="font-medium transition-colors duration-200 grid {voteColor(vote)}"
class:hidden={$profile?.user?.local_user_view.local_user.show_scores == class:hidden={$profile?.user?.local_user_view.local_user.show_scores ==
false} false}
> >
<FormattedNumber number={score} /> {#key score}
<span
in:fly={{ y: score > oldScore ? 4 : -4, duration: 200 }}
out:fly={{ y: score > oldScore ? -4 : 4, duration: 200 }}
style="grid-column: 1; grid-row: 1;"
>
<FormattedNumber number={score} />
</span>
{/key}
</span> </span>
<Button <Button
aria-label="Downvote" aria-label="Downvote"
@@ -47,11 +64,7 @@
.enable_downvotes .enable_downvotes
? '' ? ''
: 'pointer-events-none opacity-50'}" : 'pointer-events-none opacity-50'}"
on:click={async () => { on:click={async () => castVote(vote == -1 ? 0 : -1)}
if (!$profile?.jwt) return
vote = vote == -1 ? 0 : -1
score = await voteItem(post, vote, $profile.jwt)
}}
size="square-sm" size="square-sm"
color="tertiary" color="tertiary"
> >
+1 -1
View File
@@ -81,7 +81,7 @@
</Button> </Button>
</div> </div>
</div> </div>
<PostFeed posts={data.posts.posts} /> <PostFeed community={true} posts={data.posts.posts} />
<Pageination <Pageination
page={data.page} page={data.page}