insert history entry when forking

pull/2680/head
Richard Harris 6 years ago
parent fd1b4448cb
commit c3857abd23

@ -10,7 +10,7 @@
<script>
import Repl from '@sveltejs/svelte-repl';
import { onMount } from 'svelte';
import { goto } from '@sapper/app';
import { process_example } from '../../../utils/examples';
import InputOutputToggle from '../../../components/Repl/InputOutputToggle.svelte';
import AppControls from './_components/AppControls/index.svelte';
@ -26,7 +26,7 @@
let width = process.browser ? window.innerWidth : 1000;
let checked = false;
$: if (typeof history !== 'undefined') {
function update_query_string(version) {
const params = [];
if (version !== 'latest') params.push(`version=${version}`);
@ -38,17 +38,15 @@
history.replaceState({}, 'x', url);
}
onMount(() => {
if (version !== 'local') {
fetch(`https://unpkg.com/svelte@${version || '3'}/package.json`)
.then(r => r.json())
.then(pkg => {
version = pkg.version;
});
$: if (typeof history !== 'undefined') update_query_string(version);
function fetch_gist(id) {
if (gist && gist.uid === id) {
// if the id changed because we just forked, don't refetch
return;
}
// TODO handle `relaxed` logic
fetch(`repl/${id}.json`).then(r => {
if (r.ok) {
r.json().then(data => {
@ -77,12 +75,24 @@
console.warn('TODO: 404 Gist')
}
});
}
$: if (process.browser) fetch_gist(id);
onMount(() => {
if (version !== 'local') {
fetch(`https://unpkg.com/svelte@${version || '3'}/package.json`)
.then(r => r.json())
.then(pkg => {
version = pkg.version;
});
}
});
function handle_fork(event) {
console.log('> handle_fork', event);
gist = event.detail.gist;
id = gist.uid;
goto(`/repl/${gist.uid}?version=${version}`);
}
$: svelteUrl = process.browser && version === 'local' ?

@ -10,8 +10,6 @@ export async function post(req, res) {
try {
const { name, files } = await body(req);
console.log({ name, files });
const [row] = await query(`
insert into gists(user_id, name, files)
values ($1, $2, $3) returning *`, [user.id, name, JSON.stringify(files)]);

Loading…
Cancel
Save