-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Show a list of the user's apps
- Loading branch information
Showing
5 changed files
with
195 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import send from '@polka/send'; | ||
import { query } from '../../utils/db'; | ||
|
||
export async function get(req, res) { | ||
if (req.user) { | ||
const offset = req.params.offset || 0; | ||
const rows = await query(` | ||
select g.uid, g.name, coalesce(g.updated_at, g.created_at) as updated_at | ||
from gists g | ||
where g.user_id = $1 | ||
order by updated_at desc | ||
limit 100 | ||
offset $2 | ||
`, [req.user.id, offset]); | ||
|
||
rows.forEach(row => { | ||
row.uid = row.uid.replace(/-/g, ''); | ||
}); | ||
|
||
send(res, 200, rows); | ||
} else { | ||
send(res, 401); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<script context="module"> | ||
export async function preload(page, { user }) { | ||
let apps; | ||
if (user) { | ||
const r = await this.fetch('apps.json', { | ||
credentials: 'include' | ||
}); | ||
if (!r.ok) return this.error(r.status, await r.text()); | ||
apps = await r.json(); | ||
} | ||
return { user, apps }; | ||
} | ||
</script> | ||
|
||
<script> | ||
import { getContext } from 'svelte'; | ||
export let user; | ||
export let apps; | ||
const { login, logout } = getContext('app'); | ||
const formatter = new Intl.DateTimeFormat(undefined, { | ||
year: 'numeric', | ||
month: 'short', | ||
day: 'numeric', | ||
hour: 'numeric', | ||
minute: '2-digit' | ||
}); | ||
const format = str => formatter.format(new Date(str)); | ||
</script> | ||
|
||
<svelte:head> | ||
<title>Your apps • Svelte</title> | ||
</svelte:head> | ||
|
||
<div class="apps"> | ||
{#if user} | ||
<header> | ||
<h1>Your apps</h1> | ||
|
||
<div class="user"> | ||
<img class="avatar" alt="{user.name} avatar" src="{user.avatar}"> | ||
<span> | ||
{user.name} | ||
(<a on:click|preventDefault={logout} href="auth/logout">log out</a>) | ||
</span> | ||
</div> | ||
</header> | ||
|
||
<ul> | ||
{#each apps as app} | ||
<li> | ||
<a href="repl/{app.uid}"> | ||
<h2>{app.name}</h2> | ||
<span>updated {format(app.updated_at)}</span> | ||
</a> | ||
</li> | ||
{/each} | ||
</ul> | ||
{:else} | ||
<p>Please <a on:click|preventDefault={login} href="auth/login">log in</a> to see your saved apps.</p> | ||
{/if} | ||
</div> | ||
|
||
<style> | ||
.apps { | ||
padding: var(--top-offset) var(--side-nav) 6rem var(--side-nav); | ||
max-width: var(--main-width); | ||
margin: 0 auto; | ||
} | ||
header { | ||
margin: 0 0 1em 0; | ||
} | ||
h1 { | ||
font-size: 4rem; | ||
font-weight: 400; | ||
} | ||
.user { | ||
display: flex; | ||
padding: 0 0 0 3.2rem; | ||
position: relative; | ||
margin: 1rem 0 5rem 0; | ||
color: var(--text); | ||
} | ||
.avatar { | ||
position: absolute; | ||
left: 0; | ||
top: 0.1rem; | ||
width: 2.4rem; | ||
height: 2.4rem; | ||
border: 1px solid rgba(0,0,0,0.3); | ||
border-radius: 0.2rem; | ||
} | ||
ul { | ||
list-style: none; | ||
} | ||
li { | ||
margin: 0 0 1em 0; | ||
} | ||
h2 { | ||
color: var(--text); | ||
font-size: var(--h3); | ||
font-weight: 400; | ||
} | ||
li a { | ||
border: none; | ||
} | ||
li a:hover h2 { | ||
color: var(--flash); | ||
} | ||
li span { | ||
font-size: 14px; | ||
color: #999; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters