|
1 | 1 | --- |
2 | | -import doAuth from "../../lib/actions/do-auth"; |
| 2 | +import { Image } from "astro:assets"; |
| 3 | +import doAuth from "../../lib/actions/do-auth.js"; |
3 | 4 | import BaseLayout from "../../layouts/base.astro"; |
4 | | -import Navbar from "../../components/navbar.astro"; |
5 | | -import { $userData } from "../../lib/stores/user.js"; |
| 5 | +import { PROJECT_REPO_DETAILS } from "../../../constants.js"; |
| 6 | +import doContributionStats from "../../lib/actions/do-contribution-stats.js"; |
6 | 7 |
|
7 | 8 | const { url: { pathname }, redirect } = Astro; |
8 | 9 |
|
9 | 10 | const { isAuthed, authedData: userData } = await doAuth(Astro); |
10 | 11 | if (!isAuthed) return redirect(`/login?return_to=${encodeURIComponent(pathname)}`); |
11 | | -// @ts-expect-error |
12 | | -$userData.set(userData); |
| 12 | +
|
| 13 | +const { newWords, editedWords, pendingWords } = await doContributionStats(Astro); |
| 14 | +const totalWords = { |
| 15 | + count: newWords.count + editedWords.count, |
| 16 | + url: `https://github.com/${PROJECT_REPO_DETAILS.repoFullname}/pulls?q=${encodeURIComponent(`is:pr is:closed is:merged author:@me label:":computer: via word-editor"`)}` |
| 17 | +}; |
13 | 18 | --- |
14 | 19 |
|
15 | 20 | <BaseLayout |
16 | | - pageTitle="Dictionry" |
17 | | - class="flex flex-col w-full min-h-screen overflow-hidden" |
| 21 | + pageTitle="Jargons Editor" |
| 22 | + class="flex flex-col w-full min-h-screen" |
18 | 23 | > |
19 | | - <Navbar> |
20 | | - |
21 | | - </Navbar> |
22 | | - |
23 | | - <main class="flex flex-col grow px-5 md:px-6 pb-4"> |
24 | | - <h1> |
25 | | - The Jargons Editor - Your Dashboard |
26 | | - </h1> |
27 | | - |
28 | | - <a href="/editor/new">Add New Word</a> |
| 24 | + <main class="w-full max-w-screen-lg mx-auto flex flex-col grow p-5 space-y-3"> |
| 25 | + <!-- Profile Section --> |
| 26 | + <section class="mt-10 flex w-full items-center justify-between md:px-6"> |
| 27 | + <div class="flex flex-col space-y-6 justify-center h-full py-6"> |
| 28 | + <span class="relative flex shrink-0 overflow-hidden rounded-full w-20 h-20 border"> |
| 29 | + <!-- src="https://images.unsplash.com/profile-1606728664311-4bcc76a40e98image?bg=fff&crop=faces&dpr=2&h=150&w=150&auto=format&fit=crop&q=60&ixlib=rb-4.0.3" --> |
| 30 | + <Image |
| 31 | + src={ userData.avatar_url } |
| 32 | + alt={ (userData.name || userData.login) ?? "User avatar" } |
| 33 | + width={100} |
| 34 | + height={100} |
| 35 | + loading="eager" |
| 36 | + /> |
| 37 | + </span> |
| 38 | + <div class="space-y-2"> |
| 39 | + <h3 class="text-2xl tracking-tight font-semibold">Hey, { userData.login }👋</h3> |
| 40 | + <p class="text-base text-gray-500">Welcome to the Jargons Editor, we're super excited to see you here.</p> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + </section> |
| 44 | + |
| 45 | + <!-- Contribution CTA --> |
| 46 | + <section class="rounded-lg border shadow-sm"> |
| 47 | + <div class="space-y-1.5 p-3 md:p-6 flex flex-col lg:flex-row lg:items-center justify-between gap-4"> |
| 48 | + <div class="space-y-1"> |
| 49 | + <h3 class="font-semibold tracking-tight text-2xl">Contribute Words</h3> |
| 50 | + <p class="text-sm"> |
| 51 | + You can contribute new words to the jargons.dev dictionary. |
| 52 | + </p> |
| 53 | + </div> |
| 54 | + <a |
| 55 | + class="flex items-center w-fit justify-center no-underline px-4 py-2 rounded-md border border-gray-200 bg-white hover:bg-gray-100 text-sm shadow-sm hover:shadow transition-colors" |
| 56 | + href="/editor/new" |
| 57 | + > |
| 58 | + <span>Start Now</span> |
| 59 | + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width={1.5} stroke="currentColor" class="w-4 h-4"> |
| 60 | + <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 19.5 15-15m0 0H8.25m11.25 0v11.25" /> |
| 61 | + </svg> |
| 62 | + </a> |
| 63 | + </div> |
| 64 | + </section> |
| 65 | + |
| 66 | + <!-- Contribution Stats --> |
| 67 | + <section class=""> |
| 68 | + <div class="flex-col space-y-1 p-6 flex"> |
| 69 | + <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-6 h-6"> |
| 70 | + <path d="M22 12h-4l-3 9L9 3l-3 9H2"></path> |
| 71 | + </svg> |
| 72 | + <div class=""> |
| 73 | + <h3 class="text-2xl font-semibold tracking-tight">Contribution Stats</h3> |
| 74 | + <p class="text-sm">Your Words contributed to jargons.dev so far...</p> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + |
| 78 | + <div class="grid md:grid-cols-2 gap-2"> |
| 79 | + <!-- Total Words --> |
| 80 | + <div class="p-6 space-y-2 rounded-lg border shadow-sm"> |
| 81 | + <div class="w-full flex justify-between"> |
| 82 | + <div class="text-3xl font-bold tracking-tighter"> |
| 83 | + { totalWords.count } |
| 84 | + </div> |
| 85 | + {!!totalWords.count && ( |
| 86 | + <a class="text-sm" href={totalWords.url}> |
| 87 | + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width={1.5} stroke="currentColor" class="w-4 h-4"> |
| 88 | + <title>See all Words Contributed</title> |
| 89 | + <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 19.5 15-15m0 0H8.25m11.25 0v11.25" /> |
| 90 | + </svg> |
| 91 | + </a> |
| 92 | + )} |
| 93 | + </div> |
| 94 | + <div class="flex items-center gap-2 text-sm"> |
| 95 | + <svg class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"> |
| 96 | + <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.5 11.5 11 14l4-4m6 2a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"/> |
| 97 | + </svg> |
| 98 | + <span class="text-gray-500 dark:text-gray-400"> |
| 99 | + Contributed Words |
| 100 | + </span> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + |
| 104 | + <!-- Pending Words --> |
| 105 | + <div class="p-6 space-y-2 rounded-lg border shadow-sm"> |
| 106 | + <div class="w-full flex justify-between"> |
| 107 | + <div class="text-3xl font-bold tracking-tighter"> |
| 108 | + { pendingWords.count } |
| 109 | + </div> |
| 110 | + {!!pendingWords.count && ( |
| 111 | + <a class="text-sm" href={pendingWords.url}> |
| 112 | + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width={1.5} stroke="currentColor" class="w-4 h-4"> |
| 113 | + <title>See all Pending Word Contribution</title> |
| 114 | + <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 19.5 15-15m0 0H8.25m11.25 0v11.25" /> |
| 115 | + </svg> |
| 116 | + </a> |
| 117 | + )} |
| 118 | + </div> |
| 119 | + <div class="flex items-center gap-2 text-sm"> |
| 120 | + <svg class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"> |
| 121 | + <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"/> |
| 122 | + </svg> |
| 123 | + <span class="text-gray-500 dark:text-gray-400"> |
| 124 | + Pending Words |
| 125 | + </span> |
| 126 | + </div> |
| 127 | + </div> |
| 128 | + |
| 129 | + <!-- New Words --> |
| 130 | + <div class="p-6 space-y-2 rounded-lg border shadow-sm"> |
| 131 | + <div class="w-full flex justify-between"> |
| 132 | + <div class="text-3xl font-bold tracking-tighter"> |
| 133 | + { newWords.count } |
| 134 | + </div> |
| 135 | + {!!newWords.count && ( |
| 136 | + <a class="text-sm" href={newWords.url}> |
| 137 | + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width={1.5} stroke="currentColor" class="w-4 h-4"> |
| 138 | + <title>See all New Words Contributed</title> |
| 139 | + <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 19.5 15-15m0 0H8.25m11.25 0v11.25" /> |
| 140 | + </svg> |
| 141 | + </a> |
| 142 | + )} |
| 143 | + </div> |
| 144 | + <div class="flex items-center gap-2 text-sm"> |
| 145 | + <svg class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"> |
| 146 | + <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 21a9 9 0 1 1 0-18c1.052 0 2.062.18 3 .512M7 9.577l3.923 3.923 8.5-8.5M17 14v6m-3-3h6"/> |
| 147 | + </svg> |
| 148 | + <span class="text-gray-500 dark:text-gray-400"> |
| 149 | + New Words Contributed |
| 150 | + </span> |
| 151 | + </div> |
| 152 | + </div> |
| 153 | + |
| 154 | + <!-- Edited Word --> |
| 155 | + <div class="p-6 space-y-2 rounded-lg border shadow-sm"> |
| 156 | + <div class="w-full flex justify-between"> |
| 157 | + <div class="text-3xl font-bold tracking-tighter"> |
| 158 | + { editedWords.count } |
| 159 | + </div> |
| 160 | + {!!editedWords.count && ( |
| 161 | + <a class="text-sm" href={editedWords.url}> |
| 162 | + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width={1.5} stroke="currentColor" class="w-4 h-4"> |
| 163 | + <title>See all Edited Word Contributed</title> |
| 164 | + <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 19.5 15-15m0 0H8.25m11.25 0v11.25" /> |
| 165 | + </svg> |
| 166 | + </a> |
| 167 | + )} |
| 168 | + </div> |
| 169 | + <div class="flex items-center gap-2 text-sm"> |
| 170 | + <svg class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"> |
| 171 | + <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m14.304 4.844 2.852 2.852M7 7H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-4.5m2.409-9.91a2.017 2.017 0 0 1 0 2.853l-6.844 6.844L8 14l.713-3.565 6.844-6.844a2.015 2.015 0 0 1 2.852 0Z"/> |
| 172 | + </svg> |
| 173 | + <span class="text-gray-500 dark:text-gray-400"> |
| 174 | + Edited Words Contribution |
| 175 | + </span> |
| 176 | + </div> |
| 177 | + </div> |
| 178 | + </div> |
| 179 | + </section> |
29 | 180 | </main> |
30 | 181 | </BaseLayout> |
0 commit comments