Skip to content

Commit

Permalink
added multiple fonts selection feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivekv634 committed Nov 11, 2024
1 parent b149344 commit e3ff43d
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 70 deletions.
68 changes: 67 additions & 1 deletion app/(pages)/account/settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@/components/ui/select';
import { useSelector } from 'react-redux';
import axios from 'axios';
import { pages, themes } from '@/app/utils/pageData';
import { fonts, pages, themes } from '@/app/utils/pageData';
import { Separator } from '@/components/ui/separator';
import { Button } from '@/components/ui/button';
import ImportNotesDialog from '@/app/components/ImportNotesDialog';
Expand All @@ -25,6 +25,9 @@ import ButtonLoader from '@/app/components/ButtonLoader';
const SettingsComponent = () => {
const isDesktop = useMediaHook({ screenWidth: 768 });
const { user } = useSelector((state) => state.note);
const [userFont, setUserFont] = useState(
user && user?.userData && user?.userData?.font,
);
const [userTheme, setUserTheme] = useState(
user && user?.userData && user?.userData?.theme,
);
Expand All @@ -36,6 +39,7 @@ const SettingsComponent = () => {
const [exportallnotes, setExportAllNotes] = useState(false);
const [exportallnotebooks, setExportAllNotebooks] = useState(false);
const [themeLoading, setThemeLoading] = useState(false);
const [fontLoading, setFontLoading] = useState(false);
const toast = useCustomToast();

const handleThemeChange = async () => {
Expand All @@ -61,6 +65,29 @@ const SettingsComponent = () => {
}
};

const handleFontChange = async () => {
try {
setFontLoading(true);
const body = { font: userFont };
await axios.put(
`${process.env.API}/api/account/update/${user.userID}`,
body,
);
setFontLoading(false);
toast({
description: 'Font updated!',
color: userTheme,
});
} catch (error) {
console.error(error);
setFontLoading(false);
toast({
description: 'Oops! something went wrong. Try again later!',
variant: 'destructive',
});
}
};

const handleDefaultHomePageChange = async (page) => {
await axios.put(`${process.env.API}/api/account/update/${user.userID}`, {
defaultHomePage: page,
Expand Down Expand Up @@ -122,11 +149,50 @@ const SettingsComponent = () => {
<Button
className={cn(user?.userData?.theme === userTheme && 'hidden')}
onClick={handleThemeChange}
disabled={themeLoading}
>
<ButtonLoader loading={themeLoading} label="Save" />
</Button>
</div>
</div>
<Separator className="my-2" />
<div className="flex justify-between items-start">
<div>
<Label className="block font-bold">Font</Label>
<Label className="text-muted-foreground">
Set your prefered font
</Label>
</div>
<div className="flex flex-col items-end gap-2">
<Select
value={userFont}
onValueChange={(e) => {
setUserFont(e);
document.body.style.fontFamily = e;
}}
>
<SelectTrigger className="w-fit gap-1">
<SelectValue />
</SelectTrigger>
<SelectContent>
{Object.keys(fonts).map((font) => {
return (
<SelectItem value={font} key={font}>
{fonts[font]}
</SelectItem>
);
})}
</SelectContent>
</Select>
<Button
className={cn(user?.userData?.font === userFont && 'hidden')}
onClick={handleFontChange}
disabled={fontLoading}
>
<ButtonLoader loading={fontLoading} label="Save" />
</Button>
</div>
</div>
</div>
<div className="p-2 border rounded-md mt-2 mx-1">
<Label className="text-2xl font-extrabold block">Behaviour</Label>
Expand Down
2 changes: 1 addition & 1 deletion app/(pages)/login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const LoginComponent = () => {
{error}
</Label>
<Label className="flex justify-end underline hover:no-underline font-semibold my-1">
<DialogTrigger className="border">
<DialogTrigger>
<span>Forgot password?</span>
</DialogTrigger>
</Label>
Expand Down
1 change: 0 additions & 1 deletion app/api/(auth)/register/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const registerUser = async (name, email, password) => {
authID: response.user.uid,
notesDocID: notesResponse.id,
};
console.log(userData);
await addDoc(userDB, userData);
return response;
};
9 changes: 4 additions & 5 deletions app/api/notes/create/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { doc, runTransaction } from 'firebase/firestore';
import { NextResponse } from 'next/server';
import { headers } from 'next/headers';
import { notes } from '@/app/utils/schema';
import { uid } from 'uid';
import { v4 } from 'uuid';

export async function POST(request) {
const notesDocID = headers().get('notesDocID');
Expand All @@ -17,14 +17,13 @@ export async function POST(request) {
if (docSnap.exists()) {
const data = docSnap.data();
if (!data.notes) {
notes = [{ ...notesData, ...body, noteID: uid() }];
transaction.set(docRef, { ...data, notes: notes });
notes = [{ ...notesData, ...body, noteID: v4() }];
} else {
notes = data.notes;
notes.push({ ...notesData, ...body, noteID: uid() });
transaction.update(docRef, { notes: notes });
notes.push({ ...notesData, ...body, noteID: v4() });
}
}
transaction.update(docRef, { notes: notes });
});
return NextResponse.json({ result: notes }, { status: 201 });
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions app/api/utils/create-autonote-notes/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { titleFormatter } from '@/app/utils/titleFormatter';
import { db } from '@/firebase.config';
import { collection, getDocs, writeBatch } from 'firebase/firestore';
import { NextResponse } from 'next/server';
import { uid } from 'uid';
import { v4 } from 'uuid';
import nodemailer from 'nodemailer';
import { emailTemplate } from '@/app/utils/emailTemplate';

Expand Down Expand Up @@ -50,7 +50,7 @@ export async function PATCH(request) {
if (lastNoteGenerationTime <= currentTime) {
newNoteBody = {
...Notes,
noteID: uid(),
noteID: v4(),
title: titleFormatter(
autoNote.titleFormat,
autoNote.noteGenerated,
Expand Down
4 changes: 2 additions & 2 deletions app/components/AutoNoteContextMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import axios from 'axios';
import { useSelector } from 'react-redux';
import { titleFormatter } from '../utils/titleFormatter';
import { useRouter } from 'next/navigation';
import { uid } from 'uid';
import { v4 } from 'uuid';
import { useCustomToast } from './SendToast';

const AutoNoteContextMenu = ({ autoNote, children }) => {
Expand Down Expand Up @@ -72,7 +72,7 @@ const AutoNoteContextMenu = ({ autoNote, children }) => {
);
const newNoteBody = {
...notes,
noteID: uid(),
noteID: v4(),
title: noteTitle,
notebook_ref_id: autoNote.autoNoteNotebookID,
body: autoNote.template || '{}',
Expand Down
2 changes: 1 addition & 1 deletion app/components/ChangeEmailDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function ChangeEmailDialog({ open, setOpen }) {
>
Cancel
</DialogClose>
<Button type="submit">
<Button disabled={loading} type="submit">
<ButtonLoader loading={loading} label="Send Verification Email" />
</Button>
</DialogFooter>
Expand Down
1 change: 1 addition & 0 deletions app/components/ChangePasswordDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default function ChangePasswordDialog({ open, setOpen }) {
<Button
type="submit"
className={cn(!isDesktop && 'my-2', 'font-semibold')}
disabled={loading}
>
<ButtonLoader loading={loading} label="Send Verification Email" />
</Button>
Expand Down
4 changes: 2 additions & 2 deletions app/components/EditAutoNoteDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { cn } from '@/lib/utils';
import { useMediaHook } from '@/app/utils/mediaHook';
import { Separator } from '@/components/ui/separator';
import { Checkbox } from '@/components/ui/checkbox';
import { uid } from 'uid';
import { v4 } from 'uuid';
import axios from 'axios';
import { useSelector } from 'react-redux';
import { useCustomToast } from './SendToast';
Expand Down Expand Up @@ -91,7 +91,7 @@ const EditAutoNoteDialog = ({
updatedNotebooks = { ...notebooks };

if (newNotebookFlag) {
const notebookID = uid();
const notebookID = v4();
autoNoteBody['autoNoteNotebookID'] = notebookID;
Object.keys(updatedNotebooks).forEach((notebook_id) => {
if (notebook_id === autoNote.autoNoteNotebookID) {
Expand Down
6 changes: 3 additions & 3 deletions app/components/NewAutoNoteDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@/components/ui/select';
import { autoNote, generationPeriod, state } from '../utils/schema';
import { Separator } from '@/components/ui/separator';
import { uid } from 'uid';
import { v4 } from 'uuid';
import { Checkbox } from '@/components/ui/checkbox';
import { auth } from '@/firebase.config';
import VerifyEmailTemplate from './VerifyEmailTemplate';
Expand Down Expand Up @@ -112,7 +112,7 @@ const NewAutoNoteDialog = ({ setOpen }) => {
setLoading(true);
let newAutoNoteBody = {
...autoNote,
autoNoteID: uid(),
autoNoteID: v4(),
autoNoteName: autoNoteName,
titleFormat: titleFormat,
state: autoNoteState,
Expand All @@ -122,7 +122,7 @@ const NewAutoNoteDialog = ({ setOpen }) => {
updatedNotebookArray = [],
updatedNotebooks = { ...notebooks };
if (Object.keys(notebooks).length == 0 || newNotebookFlag) {
const notebookID = uid();
const notebookID = v4();
newAutoNoteBody['autoNoteNotebookID'] = notebookID;
newNotebookBody = {
notebookID: notebookID,
Expand Down
4 changes: 2 additions & 2 deletions app/components/NewNoteDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Input } from '@/components/ui/input';
import { useSelector } from 'react-redux';
import { Button, buttonVariants } from '@/components/ui/button';
import { useMediaHook } from '@/app/utils/mediaHook';
import { uid } from 'uid';
import { v4 } from 'uuid';
import axios from 'axios';
import { auth } from '@/firebase.config';
import VerifyEmailTemplate from './VerifyEmailTemplate';
Expand Down Expand Up @@ -80,7 +80,7 @@ export default function NewNoteDialog() {
e.preventDefault();
try {
setLoading(true);
const notebookID = uid();
const notebookID = v4();
const TAGS = tags.split(' ').filter((tag) => tag.trim());
let noteBody = {
tagsList: TAGS,
Expand Down
4 changes: 2 additions & 2 deletions app/components/NoteConfigDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Input } from '@/components/ui/input';
import { useSelector } from 'react-redux';
import { Button, buttonVariants } from '@/components/ui/button';
import { useMediaHook } from '@/app/utils/mediaHook';
import { uid } from 'uid';
import { v4 } from 'uuid';
import axios from 'axios';
import { useCustomToast } from './SendToast';
import ButtonLoader from './ButtonLoader';
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function NoteConfigDialog({
e.preventDefault();
try {
setLoading(true);
const notebookID = uid();
const notebookID = v4();
const TAGS = tags.split(' ').filter((tag) => tag.trim());
let noteBody = {
title: noteTitle,
Expand Down
4 changes: 2 additions & 2 deletions app/components/NoteContextMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useRouter } from 'next/navigation';
import { useDispatch, useSelector } from 'react-redux';
import { setDeletedNotes, setNotes } from '../redux/slices/noteSlice';
import axios from 'axios';
import { uid } from 'uid';
import { v4 } from 'uuid';
import { usePathname } from 'next/navigation';
import {
ContextMenu,
Expand Down Expand Up @@ -169,7 +169,7 @@ export default function NoteContextMenu({ children, notesDocID, note }) {
let body = {
...note,
updation_date: new Date().toString(),
noteID: uid(),
noteID: v4(),
};
const duplicateResponse = await axios.post(
`${process.env.API}/api/notes/create`,
Expand Down
2 changes: 2 additions & 0 deletions app/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const Menubar = () => {
`${process.env.API}/api/account/user/${userID}`,
);
if (response?.data?.result) {
document.body.style.fontFamily =
response?.data?.result?.userData?.font;
dispatch(setUser(response?.data?.result));
return response?.data?.result;
}
Expand Down
19 changes: 7 additions & 12 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './globals.css';
import { Poppins } from 'next/font/google';
import { Poppins, Ubuntu_Mono } from 'next/font/google';
import LayoutComponent from './LayoutComponent';
import { cn } from '@/lib/utils';

Expand All @@ -8,6 +8,11 @@ const poppins = Poppins({
weight: ['500', '600', '700'],
});

const ubuntu = Ubuntu_Mono({
subsets: ['latin'],
weight: ['400', '700'],
});

export const metadata = {
title: 'AutoBook',
description:
Expand Down Expand Up @@ -49,23 +54,13 @@ export default function RootLayout({ children }) {
return (
<html
lang="en"
className={cn(poppins.className, 'scroll-smooth')}
className={cn(ubuntu.className, poppins.className, 'scroll-smooth')}
suppressHydrationWarning
>
<head>
{/* <meta property="og:title" content="Your App Title" /> */}
{/* <meta */}
{/* property="og:description" */}
{/* content="Description of your application." */}
{/* /> */}
{/* <meta property="og:image" content="/og-image.png" /> */}
{/* <meta property="og:type" content="website" /> */}
{/* <meta property="og:url" content="https://yourappdomain.com" /> */}
{/* <meta name="twitter:card" content="summary_large_image" /> */}
<link rel="manifest" href="/manifest.json" />
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png" />
<link rel="icon" href="/icons/favicon.ico" />
<meta name="theme-color" content="#90cdf4" />
</head>
<body className="selection:bg-fuchsia-300 selection:text-zinc-900">
<LayoutComponent>{children}</LayoutComponent>
Expand Down
9 changes: 7 additions & 2 deletions app/utils/pageData.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,13 @@ export const whyChooseUsCards = [
src: 'https://plus.unsplash.com/premium_photo-1719933739393-6086c1bfa4cc?q=80&w=1932&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
},
{
title:
'Fast and Lightweight: Optimized as a PWA for quick loading and offline access.',
title: 'Fast and Lightweight: Optimized as a PWA for quick loading.',
src: 'https://plus.unsplash.com/premium_photo-1673460448921-9126847f12b8?q=80&w=2071&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
},
];
export const fonts = {
'sans-serif': 'Sans Serif',
sans: 'Sans',
poppins: 'Poppins',
ubuntu: 'Ubuntu',
};
Loading

1 comment on commit e3ff43d

@vercel
Copy link

@vercel vercel bot commented on e3ff43d Nov 11, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.