Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realworld update #290

Merged
merged 30 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
54dcbd1
store user info in JWT. yeah, yeah, i know
Rich-Harris Dec 20, 2020
f99169b
use prefetching promise if available, reload on query change
Rich-Harris Dec 21, 2020
c7efcb7
inject credentials in server-side fetch
Rich-Harris Dec 21, 2020
e003e75
start updating realworld example
Rich-Harris Dec 21, 2020
6db72d6
always supply a body when posting
Rich-Harris Dec 21, 2020
cc58597
swap tabs
Rich-Harris Dec 21, 2020
3f0fe81
simplify setup
Rich-Harris Dec 21, 2020
6363b2f
simplify settings page
Rich-Harris Dec 21, 2020
6b59ee8
replace/pushState on goto
Rich-Harris Dec 21, 2020
8f49289
handle redirects
Rich-Harris Dec 21, 2020
8d1569f
update lockfile
Rich-Harris Dec 21, 2020
1a088b2
add preloading indicator
Rich-Harris Dec 21, 2020
d1d9f26
fix prettier config
Rich-Harris Dec 21, 2020
40010ee
remove double layout
Rich-Harris Dec 21, 2020
1e7e67a
update manifest/logo
Rich-Harris Dec 21, 2020
23ad4b5
remove unwanted segment
Rich-Harris Dec 21, 2020
08180a4
fix settings page
Rich-Harris Dec 21, 2020
5744e5b
fix following logic
Rich-Harris Dec 21, 2020
298518b
various
Rich-Harris Dec 23, 2020
fd37ff3
only insist on a body for GET requests
Rich-Harris Dec 23, 2020
096e19b
only attempt 304s for get requests
Rich-Harris Dec 23, 2020
36bea7b
allow empty responses for non-GET requests
Rich-Harris Dec 23, 2020
48d7a38
allow forms to override method with ?_method=delete etc
Rich-Harris Dec 23, 2020
bcbb033
fix comment submission/deleting, including progressive enhancement
Rich-Harris Dec 23, 2020
39a6aa0
some changes i apparently made before christmas
Rich-Harris Jan 4, 2021
e4f39e8
merge master -> realworld-update
Rich-Harris Mar 23, 2021
d4d9b43
update imports
Rich-Harris Mar 24, 2021
20c59c6
minor fixes
Rich-Harris Mar 24, 2021
fb58287
fix imports
Rich-Harris Mar 25, 2021
a8f277b
Merge branch 'master' into realworld-update
Rich-Harris Mar 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100
"printWidth": 100,
"svelteSortOrder": "scripts-markup-styles",
"svelteBracketNewLine": true
}
36 changes: 20 additions & 16 deletions examples/hn.svelte.dev/src/components/PreloadingIndicator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
let p = 0;
let visible = false;
onMount(() => {
visible = true;
function next() {
visible = true;
p += 0.1;
const remaining = 1 - p;
if (remaining > 0.15) setTimeout(next, 500 / remaining);
Expand All @@ -13,16 +13,6 @@
});
</script>

{#if visible}
<div class="progress-container">
<div class="progress" style="width: {p * 100}%"></div>
</div>
{/if}

{#if p >= 0.4}
<div class="fade"></div>
{/if}

<style>
.progress-container {
position: absolute;
Expand All @@ -46,18 +36,32 @@
position: fixed;
width: 100%;
height: 100%;
background-color: rgba(255,255,255,0.3);
background-color: rgba(255, 255, 255, 0.3);
pointer-events: none;
z-index: 998;
animation: fade 0.4s;
}
:global(html).dark .fade {
background-color: rgba(0,0,0,0.3);
background-color: rgba(0, 0, 0, 0.3);
}
@keyframes fade {
from { opacity: 0 }
to { opacity: 1 }
from {
opacity: 0;
}
to {
opacity: 1;
}
}
</style>
</style>

{#if visible}
<div class="progress-container">
<div class="progress" style="width: {p * 100}%" />
</div>
{/if}

{#if p >= 0.4}
<div class="fade" />
{/if}
1 change: 1 addition & 0 deletions examples/realworld.svelte.dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"svelte": "^3.29.0"
},
"dependencies": {
"cookie": "^0.4.1",
"node-fetch": "^2.6.1"
}
}
13 changes: 7 additions & 6 deletions examples/realworld.svelte.dev/src/common/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ async function send({ method, path, data, token }) {
opts.headers['Authorization'] = `Token ${token}`;
}

const fetch = typeof window !== 'undefined'
? window.fetch
: await import('node-fetch').then(mod => mod.default)
const fetch =
typeof window !== 'undefined'
? window.fetch
: await import('node-fetch').then((mod) => mod.default);

return fetch(`${base}/${path}`, opts)
.then(r => r.text())
.then(json => {
.then((r) => r.text())
.then((json) => {
try {
return JSON.parse(json);
} catch (err) {
Expand All @@ -41,4 +42,4 @@ export function post(path, data, token) {

export function put(path, data, token) {
return send({ method: 'PUT', path, data, token });
}
}
1 change: 1 addition & 0 deletions examples/realworld.svelte.dev/src/common/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const page_size = 10;
6 changes: 3 additions & 3 deletions examples/realworld.svelte.dev/src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export function post(endpoint, data) {
return fetch(endpoint, {
method: 'POST',
credentials: 'include',
body: JSON.stringify(data),
body: JSON.stringify(data || {}),
headers: {
'Content-Type': 'application/json'
}
}).then(r => r.json());
}
}).then((r) => r.json());
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,53 +1,16 @@
<script>
import { session, page } from '$app/stores';
import * as api from '$common/api.js';
import { session } from '$app/stores';
import ArticlePreview from './ArticlePreview.svelte';
import ListPagination from './ListPagination.svelte';

export let tab, username = false;
export let favorites = false;
export let tag;
export let p;

let query;
let articles;
let articlesCount;

$: {
const endpoint = tab === 'feed' ? 'articles/feed' : 'articles';
const page_size = tab === 'feed' ? 5 : 10;

let params = `limit=${page_size}&offset=${(p - 1) * page_size}`;
if (tab === 'tag') params += `&tag=${tag}`;
if (tab === 'profile') params += `&${favorites ? 'favorited' : 'author'}=${encodeURIComponent(username)}`;

query = `${endpoint}?${params}`;
}

$: query && getData();

async function getData() {
articles = null;

// TODO do we need some error handling here?
({ articles, articlesCount } = await api.get(query, $session.user && $session.user.token));
}
export let articles;
</script>

{#if articles}
{#if articles.length === 0}
<div class="article-preview">
No articles are here... yet.
</div>
{:else}
<div>
{#each articles as article (article.slug)}
<ArticlePreview {article} user={$session.user}/>
{/each}

<ListPagination {articlesCount} page={parseInt($page.params.user, 10)} />
</div>
{/if}
{#if articles.length === 0}
<div class="article-preview">No articles are here... yet.</div>
{:else}
<div class="article-preview">Loading...</div>
{/if}
<div>
{#each articles as article (article.slug)}
<ArticlePreview {article} user={$session.user} />
{/each}
</div>
{/if}
47 changes: 0 additions & 47 deletions examples/realworld.svelte.dev/src/components/Home.svelte

This file was deleted.

54 changes: 0 additions & 54 deletions examples/realworld.svelte.dev/src/components/MainView/index.svelte

This file was deleted.

28 changes: 18 additions & 10 deletions examples/realworld.svelte.dev/src/components/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,52 @@

<nav class="navbar navbar-light">
<div class="container">
<a rel='prefetch' class="navbar-brand" href=".">conduit</a>
<a rel="prefetch" class="navbar-brand" href="/">conduit</a>
<ul class="nav navbar-nav pull-xs-right">
<li class="nav-item">
<a rel='prefetch' class="nav-link" class:active="{$page.path === '/'}" href="/">Home</a>
<a rel="prefetch" class="nav-link" class:active={$page.path === '/'} href="/">Home</a>
</li>

{#if $session.user}
<li class="nav-item">
<a rel='prefetch' href="/editor" class="nav-link" class:active="{$page.path === '/editor'}">
<i class="ion-compose"></i>&nbsp;New Post
<a rel="prefetch" href="/editor" class="nav-link" class:active={$page.path === '/editor'}>
<i class="ion-compose" />&nbsp;New Post
</a>
</li>

<li class="nav-item">
<a rel='prefetch' href="/settings" class="nav-link" class:active="{$page.path === '/settings'}">
<i class="ion-gear-a"></i>&nbsp;Settings
<a
rel="prefetch"
href="/settings"
class="nav-link"
class:active={$page.path === '/settings'}>
<i class="ion-gear-a" />&nbsp;Settings
</a>
</li>

<li class="nav-item">
<a rel='prefetch' href='/profile/@{$session.user.username}' class="nav-link">
<a rel="prefetch" href="/profile/@{$session.user.username}" class="nav-link">
<!-- <img src={$user.image} class="user-pic" alt={$user.username}> -->
{$session.user.username}
</a>
</li>
{:else}
<li class="nav-item">
<a rel='prefetch' href="/login" class="nav-link" class:active="{$page.path === '/login'}">
<a rel="prefetch" href="/login" class="nav-link" class:active={$page.path === '/login'}>
Sign in
</a>
</li>

<li class="nav-item">
<a rel='prefetch' href="/register" class="nav-link" class:active="{$page.path === '/register'}">
<a
rel="prefetch"
href="/register"
class="nav-link"
class:active={$page.path === '/register'}>
Sign up
</a>
</li>
{/if}
</ul>
</div>
</nav>
</nav>
Loading