Skip to content

Commit f335b0b

Browse files
feat: add reactions to releases, change button location
1 parent 374dc14 commit f335b0b

File tree

1 file changed

+58
-20
lines changed

1 file changed

+58
-20
lines changed

src/routes/package/[...package]/ReleaseCard.svelte

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import semver from "semver";
55
import MarkdownRenderer from "$lib/components/MarkdownRenderer.svelte";
66
import type { GitHubRelease } from "$lib/server/github-cache";
7+
import type { Entries } from "$lib/types";
78
import { Badge } from "$lib/components/ui/badge";
89
import { Button } from "$lib/components/ui/button";
910
import * as Accordion from "$lib/components/ui/accordion";
@@ -87,6 +88,28 @@
8788
}
8889
return formatter.format(0 - diff, "second");
8990
}
91+
92+
type Reaction = Exclude<keyof NonNullable<(typeof release)["reactions"]>, "url" | "total_count">;
93+
const reactionsEmojis: Record<Reaction, string> = {
94+
"+1": "👍",
95+
"-1": "👎",
96+
laugh: "😄",
97+
confused: "😕",
98+
heart: "❤️",
99+
hooray: "🎉",
100+
rocket: "🚀",
101+
eyes: "👀"
102+
};
103+
const sortedEmojis: Reaction[] = [
104+
"+1",
105+
"-1",
106+
"laugh",
107+
"hooray",
108+
"confused",
109+
"heart",
110+
"rocket",
111+
"eyes"
112+
];
90113
</script>
91114

92115
{#snippet badges()}
@@ -216,31 +239,46 @@
216239
</div>
217240
</Accordion.Trigger>
218241
<Accordion.Content class="rounded-b-xl bg-accent/30 px-6">
219-
<div class="relative mt-4 flex flex-col gap-4 sm:flex-row sm:justify-between sm:gap-0">
242+
<div class="relative mt-4 flex flex-col gap-2">
220243
<MarkdownRenderer
221244
markdown={releaseBody}
222245
additionalPlugins={[{ renderer: { li: ListElementRenderer } }]}
223246
class="prose-sm max-w-full prose-p:my-0"
224247
/>
225-
<!-- Open the release on GitHub in a new tab -->
226-
<Button variant="outline" size="sm" class="invisible mr-6">this is a long long text</Button>
227-
<Button
228-
href={release.html_url}
229-
variant="outline"
230-
size="sm"
231-
target="_blank"
232-
class="group absolute right-0 bottom-1 shrink-0 gap-0 transition-colors duration-500"
233-
>
234-
<span class="-mr-6 hidden group-hover:block">Open on GitHub</span>
235-
<img
236-
src="/github.svg"
237-
alt="GitHub"
238-
class="size-5 transition-opacity duration-300 group-hover:opacity-0 dark:invert"
239-
/>
240-
<ArrowUpRight
241-
class="ml-2 size-4 transition-transform duration-300 group-hover:translate-x-1 group-hover:-translate-y-1"
242-
/>
243-
</Button>
248+
<div class="flex items-end-safe justify-between gap-8">
249+
<!-- Reactions -->
250+
{#if release.reactions}
251+
{@const reactionEntries = Object.entries(release.reactions)
252+
.filter(([k, v]) => !["url", "total_count"].includes(k) && !!v)
253+
.toSorted(([a], [b]) => sortedEmojis.indexOf(a) - sortedEmojis.indexOf(b)) as Entries<
254+
Record<Reaction, number>
255+
>}
256+
<div class="flex flex-wrap gap-1.5">
257+
{#each reactionEntries as [key, value] (key)}
258+
<Badge variant="outline" class="text-sm">{reactionsEmojis[key]} {value}</Badge>
259+
{/each}
260+
</div>
261+
{/if}
262+
<!-- Open the release on GitHub in a new tab -->
263+
<Button variant="outline" size="sm" class="invisible w-16 sm:w-36" />
264+
<Button
265+
href={release.html_url}
266+
variant="outline"
267+
size="sm"
268+
target="_blank"
269+
class="group absolute right-0 bottom-0 shrink-0 gap-0 transition-colors duration-500"
270+
>
271+
<span class="-mr-6 hidden sm:group-hover:block">Open on GitHub</span>
272+
<img
273+
src="/github.svg"
274+
alt="GitHub"
275+
class="size-5 transition-opacity duration-300 sm:group-hover:opacity-0 dark:invert"
276+
/>
277+
<ArrowUpRight
278+
class="ml-2 size-4 transition-transform duration-300 sm:group-hover:translate-x-1 sm:group-hover:-translate-y-1"
279+
/>
280+
</Button>
281+
</div>
244282
</div>
245283
</Accordion.Content>
246284
</Accordion.Item>

0 commit comments

Comments
 (0)