-
Notifications
You must be signed in to change notification settings - Fork 354
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
Svelte 5 Migration #161
Svelte 5 Migration #161
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,15 @@ | |
import { writable } from "svelte/store" | ||
import { setContext } from "svelte" | ||
import { WebsiteName } from "../../../../config" | ||
interface Props { | ||
children?: import("svelte").Snippet | ||
} | ||
|
||
let { children }: Props = $props() | ||
|
||
const adminSectionStore = writable("") | ||
setContext("adminSection", adminSectionStore) | ||
let adminSection: string | ||
let adminSection: string = $state() | ||
adminSectionStore.subscribe((value) => { | ||
adminSection = value | ||
}) | ||
|
@@ -47,12 +52,12 @@ | |
</div> | ||
</div> | ||
<div class="container px-6 lg:px-12 py-3 lg:py-6"> | ||
<slot /> | ||
{@render children?.()} | ||
</div> | ||
</div> | ||
|
||
<div class="drawer-side"> | ||
<label for="admin-drawer" class="drawer-overlay" /> | ||
<label for="admin-drawer" class="drawer-overlay"></label> | ||
<ul | ||
class="menu menu-lg p-4 w-80 min-h-full bg-base-100 lg:border-r text-primary" | ||
> | ||
|
@@ -68,7 +73,7 @@ | |
<a | ||
href="/account" | ||
class={adminSection === "home" ? "active" : ""} | ||
on:click={closeDrawer} | ||
onclick={closeDrawer} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using Svelte's event directive instead of onclick The change from
Apply this change to all click handlers: -onclick={closeDrawer}
+on:click={closeDrawer} Also applies to: 98-98, 117-117 |
||
> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
|
@@ -90,7 +95,7 @@ | |
<a | ||
href="/account/billing" | ||
class={adminSection === "billing" ? "active" : ""} | ||
on:click={closeDrawer} | ||
onclick={closeDrawer} | ||
> | ||
<svg | ||
class="h-5 w-5" | ||
|
@@ -109,7 +114,7 @@ | |
<a | ||
href="/account/settings" | ||
class={adminSection === "settings" ? "active" : ""} | ||
on:click={closeDrawer} | ||
onclick={closeDrawer} | ||
> | ||
<svg class="h-5 w-5" viewBox="0 0 24 24" stroke="none" fill="none"> | ||
<g id="Interface / Settings"> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,7 +7,7 @@ | |||||
let adminSection: Writable<string> = getContext("adminSection") | ||||||
adminSection.set("settings") | ||||||
|
||||||
export let data | ||||||
let { data } = $props() | ||||||
let { user, supabase } = data | ||||||
|
||||||
// True if definitely has a password, but can be false if they | ||||||
|
@@ -21,11 +21,14 @@ | |||||
// @ts-expect-error: we ignore because Supabase does not maintain an AMR typedef | ||||||
let usingOAuth = user?.amr?.find((x) => x.method === "oauth") ? true : false | ||||||
|
||||||
let sendBtn: HTMLButtonElement | ||||||
let sentEmail = false | ||||||
let sendBtn: HTMLButtonElement | undefined = $state() | ||||||
let sentEmail = $state(false) | ||||||
let sendForgotPassword = () => { | ||||||
sendBtn.disabled = true | ||||||
sendBtn.textContent = "Sending..." | ||||||
if (sendBtn) { | ||||||
sendBtn.disabled = true | ||||||
sendBtn.textContent = "Sending..." | ||||||
} | ||||||
|
||||||
let email = user?.email | ||||||
if (email) { | ||||||
supabase.auth | ||||||
|
@@ -34,6 +37,10 @@ | |||||
}) | ||||||
.then((d) => { | ||||||
sentEmail = d.error ? false : true | ||||||
if (sendBtn) { | ||||||
sendBtn.disabled = false | ||||||
sendBtn.textContent = "Send Forgot Password" | ||||||
} | ||||||
}) | ||||||
} | ||||||
} | ||||||
|
@@ -95,7 +102,7 @@ | |||||
<button | ||||||
class="btn btn-outline btn-wide {sentEmail ? 'hidden' : ''}" | ||||||
bind:this={sendBtn} | ||||||
on:click={sendForgotPassword} | ||||||
onclick={sendForgotPassword} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert to Svelte's event handling convention The change from -onclick={sendForgotPassword}
+on:click={sendForgotPassword} 📝 Committable suggestion
Suggested change
|
||||||
>Send Set Password Email | ||||||
</button> | ||||||
<div class="success alert alert-success {sentEmail ? '' : 'hidden'}"> | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,11 +1,15 @@ | ||||||||||||||||||||||||
<script lang="ts"> | ||||||||||||||||||||||||
import { run } from "svelte/legacy" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
import { invalidate } from "$app/navigation" | ||||||||||||||||||||||||
import { onMount } from "svelte" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export let data | ||||||||||||||||||||||||
let { data, children } = $props() | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let { supabase, session } = data | ||||||||||||||||||||||||
$: ({ supabase, session } = data) | ||||||||||||||||||||||||
let { supabase, session } = $state(data) | ||||||||||||||||||||||||
run(() => { | ||||||||||||||||||||||||
;({ supabase, session } = data) | ||||||||||||||||||||||||
}) | ||||||||||||||||||||||||
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider simplifying the state synchronization. The current state synchronization could be more concise by combining the state declaration and synchronization. -let { supabase, session } = $state(data)
-run(() => {
- ;({ supabase, session } = data)
-})
+let { supabase, session } = $state(() => data) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
onMount(() => { | ||||||||||||||||||||||||
const { data } = supabase.auth.onAuthStateChange((event, _session) => { | ||||||||||||||||||||||||
|
@@ -18,4 +22,4 @@ | |||||||||||||||||||||||
}) | ||||||||||||||||||||||||
</script> | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
<slot /> | ||||||||||||||||||||||||
{@render children?.()} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,12 +3,16 @@ | |||||||||||||||||||
import type { SubmitFunction } from "@sveltejs/kit" | ||||||||||||||||||||
import "../../../../app.css" | ||||||||||||||||||||
|
||||||||||||||||||||
export let data | ||||||||||||||||||||
export let form: FormAccountUpdateResult | ||||||||||||||||||||
interface Props { | ||||||||||||||||||||
data: any | ||||||||||||||||||||
form: FormAccountUpdateResult | ||||||||||||||||||||
} | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider improving type safety for the Props interface. While the interface addition is good for structure, the interface Props {
- data: any
+ data: {
+ user: { email: string }
+ profile?: {
+ full_name?: string
+ company_name?: string
+ website?: string
+ }
+ }
form: FormAccountUpdateResult
}
|
||||||||||||||||||||
|
||||||||||||||||||||
let { data, form }: Props = $props() | ||||||||||||||||||||
|
||||||||||||||||||||
let { user, profile } = data | ||||||||||||||||||||
|
||||||||||||||||||||
let loading = false | ||||||||||||||||||||
let loading = $state(false) | ||||||||||||||||||||
Comment on lines
+21
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider optimizing the data destructuring pattern. While the current implementation works, you could simplify the destructuring pattern to avoid the intermediate step. - let { data, form }: Props = $props()
- let { user, profile } = data
+ let { data: { user, profile }, form }: Props = $props() 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
let fullName: string = profile?.full_name ?? "" | ||||||||||||||||||||
let companyName: string = profile?.company_name ?? "" | ||||||||||||||||||||
let website: string = profile?.website ?? "" | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding Svelte 5 migration testing strategy.
To ensure a smooth transition to Svelte 5:
Add these scripts to the
scripts
section: