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

feat: svelte 5 + upgrade dependencies #175

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"format": "prettier --write ."
},
"devDependencies": {
"@sveltejs/adapter-vercel": "^4.0.3",
"@sveltejs/kit": "^2.4.3",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"marked": "^11.1.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"sanitize-html": "^2.13.0",
"svelte": "^4.2.8",
"typescript": "^5.3.3",
"vite": "^5.0.13"
"@sveltejs/adapter-vercel": "^5.4.5",
"@sveltejs/kit": "^2.7.2",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"marked": "^14.1.3",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.7",
"sanitize-html": "^2.13.1",
"svelte": "^5.0.5",
"typescript": "^5.6.3",
"vite": "^5.4.9"
}
}
942 changes: 461 additions & 481 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/lib/ArticleList/ArticlePreview.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { enhance } from '$app/forms';
export let article;
export let user;
const { article, user } = $props();
</script>

<div class="article-preview">
Expand Down Expand Up @@ -42,7 +41,7 @@
>
<input hidden type="checkbox" name="favorited" checked={article.favorited} />
<button class="btn btn-sm {article.favorited ? 'btn-primary' : 'btn-outline-primary'}">
<i class="ion-heart" />
<i class="ion-heart"></i>
{article.favoritesCount}
</button>
</form>
Expand All @@ -55,7 +54,7 @@
<span>Read more...</span>
<ul class="tag-list">
{#each article.tagList as tag}
<li class="tag-default tag-pill tag-outline"><a href="/?tag={tag}">{tag}</a></li>
<li class="tag-default tag-pill tag-outline">{tag}</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this now seems to match what is on https://www.realworld.how/specifications/frontend/templates/, so I suppose it is fine

{/each}
</ul>
</a>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ArticleList/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { page } from '$app/stores';
import ArticlePreview from './ArticlePreview.svelte';
export let articles;
const { articles } = $props();
</script>

{#if articles.length === 0}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ListErrors.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
export let errors;
const { errors } = $props();
</script>

{#if errors}
Expand Down
4 changes: 3 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { navigating } from '$app/stores';
import Nav from './Nav.svelte';
import PreloadingIndicator from './PreloadingIndicator.svelte';
const { children } = $props();
</script>

{#if $navigating}
Expand All @@ -11,5 +13,5 @@
<Nav />

<main>
<slot />
{@render children()}
</main>
13 changes: 6 additions & 7 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import ArticleList from '$lib/ArticleList/index.svelte';
import Pagination from './Pagination.svelte';
/** @type {import('./$types').PageData} */
export let data;
const { data } = $props();
$: p = +($page.url.searchParams.get('page') ?? '1');
$: tag = $page.url.searchParams.get('tag');
$: tab = $page.url.searchParams.get('tab') ?? 'all';
$: page_link_base = tag ? `tag=${tag}` : `tab=${tab}`;
const p = $derived(+($page.url.searchParams.get('page') ?? '1'));
const tag = $derived($page.url.searchParams.get('tag'));
const tab = $derived($page.url.searchParams.get('tab') ?? 'all');
const page_link_base = $derived(tag ? `tag=${tag}` : `tab=${tab}`);
</script>
<svelte:head>
Expand Down Expand Up @@ -50,7 +49,7 @@
{#if tag}
<li class="nav-item">
<a href="/?tag={tag}" class="nav-link active">
<i class="ion-pound" />
<i class="ion-pound"></i>
{tag}
</a>
</li>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
{#if $page.data.user}
<li class="nav-item">
<a href="/editor" class="nav-link" class:active={$page.url.pathname === '/editor'}>
<i class="ion-compose" />&nbsp;New Post
<i class="ion-compose"></i>&nbsp;New Post
</a>
</li>

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

Expand Down
17 changes: 7 additions & 10 deletions src/routes/Pagination.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<script>
export let pages;
export let p;
export let href;
const { pages, p, href } = $props();
let range;
$: {
range = [];
for (let i = 1; i <= pages; ++i) {
range.push(i);
const range = $derived.by(() => {
const result = [];
for (let i = 1; i <= pages; i++) {
result.push(i);
}
}
return result;
});
</script>

{#if pages > 1}
Expand Down
10 changes: 6 additions & 4 deletions src/routes/PreloadingIndicator.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script>
import { onMount } from 'svelte';
let p = 0;
let visible = false;
let p = $state(0);
let visible = $state(false);
onMount(() => {
visible = true;
function next() {
Expand All @@ -15,12 +17,12 @@

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

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

<style>
Expand Down
5 changes: 2 additions & 3 deletions src/routes/article/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import ArticleMeta from './ArticleMeta.svelte';
import CommentContainer from './CommentContainer.svelte';
/** @type {import('./$types').PageData} */
export let data;
const { data } = $props();
</script>

<svelte:head>
Expand Down Expand Up @@ -35,7 +34,7 @@

<hr />

<div class="article-actions" />
<div class="article-actions"></div>

<div class="row">
<CommentContainer comments={data.comments} user={data.user} errors={[]} />
Expand Down
7 changes: 3 additions & 4 deletions src/routes/article/[slug]/ArticleMeta.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { enhance } from '$app/forms';

export let article;
export let user;
const { article, user } = $props();
</script>

<div class="article-meta">
Expand All @@ -20,12 +19,12 @@
{#if article.author.username === user?.username}
<span>
<a href="/editor/{article.slug}" class="btn btn-outline-secondary btn-sm">
<i class="ion-edit" /> Edit Article
<i class="ion-edit"></i> Edit Article
</a>

<form use:enhance method="POST" action="?/deleteArticle">
<button class="btn btn-outline-danger btn-sm">
<i class="ion-trash-a" /> Delete Article
<i class="ion-trash-a"></i> Delete Article
</button>
</form>
</span>
Expand Down
5 changes: 2 additions & 3 deletions src/routes/article/[slug]/Comment.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { enhance } from '$app/forms';
export let comment;
export let user;
const { comment, user } = $props();
</script>

<div class="card">
Expand All @@ -23,7 +22,7 @@

{#if user && comment.author.username === user.username}
<form use:enhance method="POST" action="?/deleteComment&id={comment.id}" class="mod-options">
<button class="ion-trash-a" aria-label="Delete comment" />
<button class="ion-trash-a" aria-label="Delete comment"></button>
</form>
{/if}
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/routes/article/[slug]/CommentContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import CommentInput from './CommentInput.svelte';
import Comment from './Comment.svelte';
export let comments;
export let user;
const { comments, user } = $props();
</script>

<div class="col-xs-12 col-md-8 offset-md-2">
Expand Down
4 changes: 2 additions & 2 deletions src/routes/article/[slug]/CommentInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import { enhance } from '$app/forms';
import { placeholder } from '$lib/constants.js';

export let user;
const { user } = $props();
</script>

<form use:enhance method="POST" action="?/createComment" class="card comment-form">
<div class="card-block">
<textarea class="form-control" name="comment" placeholder="Write a comment..." rows="3" />
<textarea class="form-control" name="comment" placeholder="Write a comment..." rows="3"></textarea>
</div>

<div class="card-footer">
Expand Down
3 changes: 1 addition & 2 deletions src/routes/editor/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import Editor from './Editor.svelte';
/** @type {import('./$types').ActionData} */
export let form;
const { form } = $props();
</script>

<Editor
Expand Down
27 changes: 13 additions & 14 deletions src/routes/editor/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import { enhance } from '$app/forms';
import ListErrors from '$lib/ListErrors.svelte';
export let article;
export let errors;
const { article, errors } = $props();
let tagList = $state(article.tagList);
</script>

<div class="editor-page">
Expand Down Expand Up @@ -40,18 +41,18 @@
rows="8"
placeholder="Write your article (in markdown)"
value={article.body}
/>
></textarea>
</fieldset>

<fieldset class="form-group">
<input
class="form-control"
placeholder="Enter tags"
on:keydown={(event) => {
onkeydown={(event) => {
if (event.key === 'Enter') {
event.preventDefault();
if (!article.tagList.includes(event.target.value)) {
article.tagList = [...article.tagList, event.target.value];
if (!tagList.includes(event.target.value)) {
tagList.push(event.target.value);
}

event.target.value = '';
Expand All @@ -61,26 +62,24 @@
</fieldset>

<div class="tag-list">
{#each article.tagList as tag, i (tag)}
{#each tagList as tag, i (tag)}
<button
transition:scale|local={{ duration: 200 }}
animate:flip={{ duration: 200 }}
class="tag-default tag-pill"
on:click|preventDefault={() => {
article.tagList = [
...article.tagList.slice(0, i),
...article.tagList.slice(i + 1)
];
type="button"
onclick={() => {
tagList.splice(i, 1);
}}
aria-label="Remove {tag} tag"
>
<i class="ion-close-round" />
<i class="ion-close-round"></i>
{tag}
</button>
{/each}
</div>

{#each article.tagList as tag}
{#each tagList as tag}
<input hidden name="tag" value={tag} />
{/each}

Expand Down
6 changes: 1 addition & 5 deletions src/routes/editor/[slug]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<script>
import Editor from '../Editor.svelte';
/** @type {import('./$types').PageData} */
export let data;
/** @type {import('./$types').ActionData} */
export let form;
const { data, form } = $props();
</script>

<Editor article={data.article} errors={form?.errors} />
3 changes: 1 addition & 2 deletions src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { enhance } from '$app/forms';
import ListErrors from '$lib/ListErrors.svelte';
/** @type {import('./$types').ActionData} */
export let form;
const { form } = $props();
</script>

<svelte:head>
Expand Down
Loading