-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guillaume_Bernier
committed
Apr 8, 2024
1 parent
44869ef
commit 7162ab4
Showing
7 changed files
with
103 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { fail } from "@sveltejs/kit"; | ||
|
||
export async function load({ locals }) { | ||
try { | ||
if (!locals.pb.authStore.model) { | ||
console.log('No authenticated user found.'); | ||
return fail(401, { message: 'No authenticated user found.' }); | ||
} | ||
|
||
const userId = locals.pb.authStore.model.id; | ||
|
||
const record = await locals.pb.collection('users').getOne(userId); | ||
const theme: "light" | "dark" = record.theme || 'system'; | ||
return { | ||
props: { | ||
theme, | ||
} | ||
}; | ||
} catch (err) { | ||
console.log('Error on loading theme: ', err); | ||
return { status: 500, error: new Error('Internal server error') }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
app/src/routes/(app)/admin/(settings)/settings/appearance/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
<script lang="ts"> | ||
import type { PageData } from "./$types.js"; | ||
import AppearanceForm from "./appearance-form.svelte"; | ||
import { Separator } from "$lib/components/ui/separator"; | ||
import type { PageData } from './$types.js'; | ||
import AppearanceForm from './appearance-form.svelte'; | ||
import { Separator } from '$lib/components/ui/separator'; | ||
export let data: PageData; | ||
let formData: any = data.form; | ||
let theme: any = data.props?.theme; | ||
</script> | ||
|
||
<div class="space-y-6"> | ||
<div> | ||
<h3 class="text-lg font-medium">Appearance</h3> | ||
<p class="text-sm text-muted-foreground"> | ||
<p class="text-muted-foreground text-sm"> | ||
Customize the appearance of the app. Automatically switch between day and night themes. | ||
</p> | ||
</div> | ||
<Separator /> | ||
<AppearanceForm data={data.form} /> | ||
</div> | ||
<AppearanceForm data={formData} {theme} /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/// <reference path="../pb_data/types.d.ts" /> | ||
migrate((db) => { | ||
const dao = new Dao(db) | ||
const collection = dao.findCollectionByNameOrId("_pb_users_auth_") | ||
|
||
// update | ||
collection.schema.addField(new SchemaField({ | ||
"system": false, | ||
"id": "cz5ruofb", | ||
"name": "theme", | ||
"type": "select", | ||
"required": false, | ||
"presentable": false, | ||
"unique": false, | ||
"options": { | ||
"maxSelect": 1, | ||
"values": [ | ||
"dark", | ||
"light", | ||
"system" | ||
] | ||
} | ||
})) | ||
|
||
return dao.saveCollection(collection) | ||
}, (db) => { | ||
const dao = new Dao(db) | ||
const collection = dao.findCollectionByNameOrId("_pb_users_auth_") | ||
|
||
// update | ||
collection.schema.addField(new SchemaField({ | ||
"system": false, | ||
"id": "cz5ruofb", | ||
"name": "theme", | ||
"type": "select", | ||
"required": false, | ||
"presentable": false, | ||
"unique": false, | ||
"options": { | ||
"maxSelect": 1, | ||
"values": [ | ||
"dark", | ||
"light" | ||
] | ||
} | ||
})) | ||
|
||
return dao.saveCollection(collection) | ||
}) |