mirror of
https://github.com/docmost/docmost.git
synced 2025-11-22 21:11:08 +10:00
add full page width preference
This commit is contained in:
@ -1,5 +1,16 @@
|
||||
import { atomWithStorage } from "jotai/utils";
|
||||
|
||||
import { ICurrentUser } from "@/features/user/types/user.types";
|
||||
import { focusAtom } from "jotai-optics";
|
||||
|
||||
export const currentUserAtom = atomWithStorage<ICurrentUser | null>("currentUser", null);
|
||||
export const currentUserAtom = atomWithStorage<ICurrentUser | null>(
|
||||
"currentUser",
|
||||
null,
|
||||
);
|
||||
|
||||
export const userAtom = focusAtom(currentUserAtom, (optic) =>
|
||||
optic.prop("user"),
|
||||
);
|
||||
export const workspaceAtom = focusAtom(currentUserAtom, (optic) =>
|
||||
optic.prop("workspace"),
|
||||
);
|
||||
|
||||
42
apps/client/src/features/user/components/page-width-pref.tsx
Normal file
42
apps/client/src/features/user/components/page-width-pref.tsx
Normal file
@ -0,0 +1,42 @@
|
||||
import { Group, Text, Switch } from "@mantine/core";
|
||||
import { useAtom } from "jotai/index";
|
||||
import { userAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||
import { updateUser } from "@/features/user/services/user-service.ts";
|
||||
import React, { useState } from "react";
|
||||
|
||||
export default function PageWidthPref() {
|
||||
return (
|
||||
<Group justify="space-between" wrap="nowrap" gap="xl">
|
||||
<div>
|
||||
<Text size="md">Full page width</Text>
|
||||
<Text size="sm" c="dimmed">
|
||||
Choose your preferred page width.
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
<WidthToggle />
|
||||
</Group>
|
||||
);
|
||||
}
|
||||
|
||||
function WidthToggle() {
|
||||
const [user, setUser] = useAtom(userAtom);
|
||||
const [checked, setChecked] = useState(
|
||||
user.settings?.preferences?.fullPageWidth,
|
||||
);
|
||||
|
||||
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = event.currentTarget.checked;
|
||||
const updatedUser = await updateUser({ fullPageWidth: value });
|
||||
setChecked(value);
|
||||
setUser(updatedUser);
|
||||
};
|
||||
|
||||
return (
|
||||
<Switch
|
||||
defaultChecked={checked}
|
||||
onChange={handleChange}
|
||||
aria-label="Toggle full page width"
|
||||
/>
|
||||
);
|
||||
}
|
||||
@ -7,7 +7,7 @@ export interface IUser {
|
||||
emailVerifiedAt: Date;
|
||||
avatarUrl: string;
|
||||
timezone: string;
|
||||
settings: any;
|
||||
settings: IUserSettings;
|
||||
invitedById: string;
|
||||
lastLoginAt: string;
|
||||
lastActiveAt: Date;
|
||||
@ -17,9 +17,16 @@ export interface IUser {
|
||||
workspaceId: string;
|
||||
deactivatedAt: Date;
|
||||
deletedAt: Date;
|
||||
fullPageWidth: boolean; // used for update
|
||||
}
|
||||
|
||||
export interface ICurrentUser {
|
||||
user: IUser;
|
||||
workspace: IWorkspace;
|
||||
}
|
||||
|
||||
export interface IUserSettings {
|
||||
preferences: {
|
||||
fullPageWidth: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user