Skip to content

Commit

Permalink
feat(bookmarks): improve bookmark deletion and settings management
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Goniszewski <[email protected]>
  • Loading branch information
goniszewski committed Sep 3, 2024
1 parent d09bdb3 commit 3da3e90
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/lib/database/repositories/Bookmark.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { serializeBookmark } from '$lib/utils/serialize-dbo-entity';
import { and, asc, count, desc, eq, inArray, like, or } from 'drizzle-orm';

import { db } from '../db';
import { bookmarkSchema, bookmarksToTagsSchema, fileSchema, tagSchema } from '../schema';
import { bookmarkSchema, bookmarksToTagsSchema, tagSchema } from '../schema';
import { mapRelationsToWithStatements } from './common';

import type { Bookmark } from '$lib/types/Bookmark.type';
Expand Down Expand Up @@ -145,6 +145,7 @@ export const deleteBookmark = async (id: number, ownerId: number): Promise<void>
await db
.delete(bookmarkSchema)
.where(and(eq(bookmarkSchema.id, id), eq(bookmarkSchema.ownerId, ownerId)));
await db.delete(bookmarksToTagsSchema).where(eq(bookmarksToTagsSchema.bookmarkId, id));
};

export const fetchBookmarkTags = async (id: number, ownerId: number): Promise<{ tags: Tag[] }> => {
Expand Down
3 changes: 1 addition & 2 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { LayoutServerLoad } from './$types';
import { db } from '$lib/database/db';
import {
getBookmarksByUserId,
getBookmarksCountForUser
getBookmarksByUserId, getBookmarksCountForUser
} from '$lib/database/repositories/Bookmark.repository';
import { fetchUserCategoryAndTags, getUserCount } from '$lib/database/repositories/User.repository';
import { searchIndexKeys } from '$lib/utils/search';
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</script>

{#if $page.data.user?.id}
<div class="m-4 ml-auto flex w-full flex-col justify-center sm:flex-row">
<div class="m-4 ml-auto flex flex-1 w-full flex-col justify-center sm:flex-row">
<form
class="flex w-full flex-1 flex-wrap items-center pr-5"
bind:this={bookmarksViewForm}
Expand Down
6 changes: 1 addition & 5 deletions src/routes/settings/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const actions = {

const settings = await request.formData();

const mappedSettings: UserSettings = {
const mappedSettings: Partial<UserSettings> = {
theme: settings.get('theme') as UserSettings['theme'],
uiAnimations: settings.get('uiAnimations') === 'on',
llm: {
Expand All @@ -48,17 +48,13 @@ export const actions = {
}
};

console.log('Received mappedSettings:', JSON.stringify(mappedSettings, null, 2));

const updatedSettings = await updateUserSettings(owner, mappedSettings)
.then(({ settings }) => settings)
.catch((err) => {
console.error('Error updating user settings. Details:', JSON.stringify(err, null, 2));
return null;
});

console.log('Updated settings:', JSON.stringify(updatedSettings, null, 2));

if (!updatedSettings) {
return {
success: false,
Expand Down
5 changes: 3 additions & 2 deletions src/routes/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use:enhance={() => {
return async ({ update, result }) => {
if (result.type === 'success' && result?.data?.updatedSettings) {
console.log('result.data.updatedSettings', result.data.updatedSettings);
// @ts-ignore-next-line
userSettingsStore.set(result.data.updatedSettings);
// @ts-ignore-next-line
Expand Down Expand Up @@ -87,7 +88,7 @@
type="checkbox"
name="uiAnimations"
class="checkbox-accent checkbox"
checked={$page.data.user.settings.uiAnimations}
checked={$userSettingsStore.uiAnimations}
on:change={(e) => {
// @ts-ignore
$userSettingsStore.uiAnimations = e.target.checked;
Expand All @@ -110,7 +111,7 @@
type="checkbox"
name="llmEnabled"
class="checkbox-accent checkbox"
checked={$page.data.user.settings.llm.enabled}
checked={$userSettingsStore.llm.enabled}
on:change={(e) => {
// @ts-ignore
$userSettingsStore.llm.enabled = e.target.checked;
Expand Down

0 comments on commit 3da3e90

Please sign in to comment.