pull/1890/head
Rich Harris 7 years ago
parent 7390bcdfb5
commit 590304cece

@ -102,4 +102,39 @@
<polyline points='17 21 17 13 7 13 7 21' /> <polyline points='17 21 17 13 7 13 7 21' />
<polyline points='7 3 7 8 15 8' /> <polyline points='7 3 7 8 15 8' />
</symbol> </symbol>
<symbol id="link" class="icon" viewBox="0 0 24 24">
<!-- <path d="
M10.5,13.5
C8.5,11.5 9.5,11.5 9.5,10.5
C8,9 13,3.5, 16,3
C19,3 21,6 21,8
C21,9,20,9,19,11"/>
<path d="
M13.5,10.5
C15.5,13.5 14.5,13.5 14.5,13.5
C16,15 11,21.5, 8,21
C5,21 3,18 3,16
C3,15,4,15,5,13"/> -->
<path d="
M9,7
L6,7
A2 2 0 0 0 6,17
L9,17
"/>
<path d="
M15,7
L18,7
A2 2 0 0 1 18,17
L15,17
"/>
<path d="
M7,12
L17,12
"/>
</symbol>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

@ -0,0 +1,9 @@
export function get(req, res) {
if (!req.session.passport || !req.session.passport.user) {
res.send(null);
return;
}
const { id, username, displayName, photo } = req.session.passport && req.session.passport.user;
res.send({ id, username, displayName, photo });
}

@ -4,7 +4,15 @@ import { body } from './_utils.js';
export async function get(req, res) { export async function get(req, res) {
const { id } = req.params; const { id } = req.params;
const r = await fetch(`https://api.github.com/gists/${id}`); const headers = {};
const user = req.session.passport && req.session.passport.user;
if (user) {
headers.Authorization = `token ${user.token}`;
}
const r = await fetch(`https://api.github.com/gists/${id}`, {
headers
});
res.writeHead(r.status, { res.writeHead(r.status, {
'Content-Type': 'application/json' 'Content-Type': 'application/json'

@ -131,7 +131,7 @@
</li> </li>
<li class='box bg-flash white'> <li class='box bg-flash white'>
<h2 style='padding:2.4rem 0 0 0'>No virtual DOM overhead</h2> <h2 style='padding:2.4rem 0 0 0'>No virtual DOM</h2>
<p>Svelte compiles your code to tiny, framework-less vanilla JS — your app starts fast and stays fast</p> <p>Svelte compiles your code to tiny, framework-less vanilla JS — your app starts fast and stays fast</p>
<a href="TODO-blog-post-on-vdom-overhead">learn more</a> <a href="TODO-blog-post-on-vdom-overhead">learn more</a>

@ -1,7 +1,7 @@
<script> <script>
import { user, logout } from '../../../../user.js'; import { user, logout } from '../../../../user.js';
let showMenu = false; let showMenu = true;
let name; let name;
$: name = $user.displayName || $user.username; $: name = $user.displayName || $user.username;
@ -13,7 +13,7 @@
{#if showMenu} {#if showMenu}
<div class="menu"> <div class="menu">
<button on:click={logout}>log out</button> <button on:click={logout}>Log out</button>
</div> </div>
{/if} {/if}
</div> </div>
@ -21,46 +21,65 @@
<style> <style>
.user { .user {
position: relative; position: relative;
float: right; display: inline-block;
display: block; padding: 0em 3.2rem 0 1.6rem;
padding: .5em 2.2em 0 .8em;
line-height: 1; line-height: 1;
z-index: 99; z-index: 99;
height: 2.5em; }
.user::after {
/* embiggen hit zone, so log out menu doesn't disappear */
position: absolute;
content: '';
width: 100%;
height: 3.2rem;
left: 0;
top: 0;
} }
span { span {
/* position: relative; padding: 0 2em 0 0; */ /* position: relative; padding: 0 2em 0 0; */
line-height: 1; line-height: 1;
display: inline-block; display: inline-block;
padding: .05em 0; font-family: var(--font-ui);
font-family: Rajdhani; font-size: 1.3rem;
font-weight: 400; opacity: 0.7;
}
.user:hover span {
opacity: 1;
} }
img { img {
position: absolute; position: absolute;
top: .2em; top: -0.05em;
right: 0; right: 0;
width: 1.6em; width: 2.4rem;
height: 1.6em; height: 2.4rem;
border-radius: 50%; border: 1px solid rgba(255,255,255,0.3);
border-radius: 0.2rem;
} }
.menu { .menu {
position: absolute; position: absolute;
min-width: calc(100% + .1em); width: calc(100% - 0rem);
background-color: #f4f4f4; top: 3rem;
padding: .5em; left: 0rem;
background-color: var(--second);
padding: 0.8rem 1.6rem;
z-index: 99; z-index: 99;
top: calc(2.5em - 1px);
border-bottom: 1px solid #eee;
border-left: 1px solid #eee;
right: 0;
text-align: left; text-align: left;
border-radius: 0.4rem;
} }
.menu button { .menu button {
background-color: transparent; background-color: transparent;
font-family: var(--font-ui);
font-size: 1.3rem;
/* opacity: 0.7; */
}
.menu button:hover {
opacity: 1;
} }
</style> </style>

@ -29,8 +29,12 @@
return new Promise(f => setTimeout(f, ms)); return new Promise(f => setTimeout(f, ms));
} }
$: {
console.log({ canSave });
}
let canSave; let canSave;
$: canSave = !!$user && !!gist && $user.id == gist.owner.id; // comparing number and string $: canSave = !!$user && !!gist && !!gist.owner && $user.id == gist.owner.id; // comparing number and string
function handleKeydown(event) { function handleKeydown(event) {
if (event.which === 83 && (isMac ? event.metaKey : event.ctrlKey)) { if (event.which === 83 && (isMac ? event.metaKey : event.ctrlKey)) {
@ -268,7 +272,7 @@ export default app;` });
{#if gist} {#if gist}
<a class="icon" href={gist.html_url} title="link to gist"> <a class="icon" href={gist.html_url} title="link to gist">
<Icon name="save" /> <Icon name="link" />
</a> </a>
{/if} {/if}

@ -10,7 +10,9 @@
let version = query.version; let version = query.version;
let demo = query.demo || 'hello-world'; let demo = query.demo || 'hello-world';
let gist = query.gist; let gist_id = query.gist;
let gist;
let app = { let app = {
components: [], components: [],
@ -25,7 +27,7 @@
const params = []; const params = [];
if (version !== 'latest') params.push(`version=${version}`); if (version !== 'latest') params.push(`version=${version}`);
if (gist) params.push(`gist=${gist}`); if (gist_id) params.push(`gist=${gist_id}`);
else if (demo) params.push(`demo=${demo}`); else if (demo) params.push(`demo=${demo}`);
const url = params.length > 0 const url = params.length > 0
@ -49,11 +51,14 @@
version = pkg.version; version = pkg.version;
}); });
if (gist) { if (gist_id) {
fetch(`gist/${gist}`).then(r => r.json()).then(({ description, files }) => { fetch(`gist/${gist_id}`).then(r => r.json()).then(data => {
gist = data;
const { id, description, files } = data;
name = description; name = description;
const values = {}; let values = {};
const components = Object.keys(files) const components = Object.keys(files)
.map(file => { .map(file => {
@ -103,10 +108,19 @@
values: tryParseData(data.json5) || {}, // TODO make this more error-resistant values: tryParseData(data.json5) || {}, // TODO make this more error-resistant
components: data.components components: data.components
}; };
gist = null;
} }
}); });
} }
function handle_fork(event) {
console.log(event);
demo = null;
gist = event.detail.gist;
gist_id = gist.id;
}
function tryParseData(json5) { function tryParseData(json5) {
try { try {
return fleece.evaluate(json5); return fleece.evaluate(json5);
@ -189,7 +203,7 @@
{repl} {repl}
bind:zen_mode bind:zen_mode
on:select="{e => (demo = e.detail.slug, gist = null)}" on:select="{e => (demo = e.detail.slug, gist = null)}"
on:forked="{e => (demo = null, gist = e.detail.gist)}" on:forked={handle_fork}
/> />
{#if process.browser} {#if process.browser}

@ -2,6 +2,15 @@ import { writable } from 'svelte/store.js';
export const user = writable(null); export const user = writable(null);
export function logout() { if (process.browser) {
user.set(null); // TODO this is a workaround for the fact that there's currently
// no way to pass session data from server to client
fetch('/auth/me.json', { credentials: 'include' })
.then(r => r.json())
.then(user.set);
}
export async function logout() {
const r = await fetch(`/auth/logout`, { method: 'POST' });
if (r.ok) user.set(null);
} }

@ -22,9 +22,10 @@ self.addEventListener('message', async event => {
if (event.data.components.length === 0) return; if (event.data.components.length === 0) return;
await ready; await ready;
postMessage( const result = await bundle(event.data.components);
await bundle(event.data.components) if (result) {
); postMessage(result);
}
break; break;
} }
@ -143,7 +144,10 @@ async function bundle(components) {
throw dom.error; throw dom.error;
} }
if (token !== currentToken) return; if (token !== currentToken) {
console.error(`aborted`);
return;
}
cached.dom = dom.bundle; cached.dom = dom.bundle;

Loading…
Cancel
Save