Skip to content

Commit 558fca2

Browse files
committed
feat: change font item size
1 parent f51155c commit 558fca2

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

app/layout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {SocketProvider} from "@/components/providers/socket-provider";
1010
import {QueryProvider} from "@/components/providers/query-provider";
1111
import {Toaster} from "@/components/ui/toaster";
1212
import Notifications from "@/components/notifications";
13+
import { FontSizeProvider } from "@/components/providers/FontSizeProvider";
1314

1415
const inter = Inter({subsets: ["latin"]});
1516

@@ -37,7 +38,9 @@ export default async function RootLayout({
3738
<QueryProvider>
3839
<Toaster/>
3940
<Notifications />
40-
{children}
41+
<FontSizeProvider>
42+
{children}
43+
</FontSizeProvider>
4144
</QueryProvider>
4245
</SocketProvider>
4346
</ThemeProvider>

components/auth/user-button.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {UserAvatar} from "@/components/user-avatar";
1313
import {Button} from "@/components/ui/button";
1414
import {useModal} from "@/hooks/use-modal-store";
1515
import {User} from "@prisma/client";
16+
import {useFontSize} from "@/components/providers/FontSizeProvider";
1617

1718

1819
interface UserButtonProps {
@@ -21,6 +22,7 @@ interface UserButtonProps {
2122

2223
export const UserButton = ({user}: UserButtonProps) => {
2324
const { onOpen } = useModal();
25+
const { changeFontSize } = useFontSize();
2426

2527
return (
2628
<DropdownMenu>
@@ -34,9 +36,14 @@ export const UserButton = ({user}: UserButtonProps) => {
3436
Профиль
3537
</DropdownMenuItem>
3638
</Button>
39+
<div>
40+
<button onClick={() => changeFontSize('14px')}>14px</button>
41+
<button onClick={() => changeFontSize('16px')}>16px</button>
42+
<button onClick={() => changeFontSize('18px')}>18px</button>
43+
</div>
3744
<LogoutButton>
3845
<DropdownMenuItem>
39-
<LogOut className="h-4 w-4 mr-2" />
46+
<LogOut className="h-4 w-4 mr-2"/>
4047
Выйти
4148
</DropdownMenuItem>
4249
</LogoutButton>

components/chat/conver-chat-item.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {FileType} from "next/dist/lib/file-exists";
2323
import {useModal} from "@/hooks/use-modal-store";
2424
import {useParams, useRouter} from "next/navigation";
2525
import {ExtendedUser} from "@/next-auth";
26+
import {useFontSize} from "@/components/providers/FontSizeProvider";
2627

2728
interface ChatItemProps {
2829
id: string;
@@ -68,6 +69,7 @@ export const ConverChatItem = ({
6869
const {onOpen} = useModal();
6970
const params = useParams();
7071
const router = useRouter();
72+
const { fontSize } = useFontSize();
7173

7274
const onMemberClick = () => {
7375
if (member.id === currentMember.id) {
@@ -216,7 +218,8 @@ export const ConverChatItem = ({
216218
</a>
217219
</div>)}
218220
{!fileUrl && !isEditing && (
219-
<p className={cn("text-sm text-zinc-600 dark:text-zinc-300", deleted && "italic text-zinc-500 dark:text-zinc-400 text-xs mt-1")}>
221+
<p style={{fontSize: fontSize}} className={cn("text-sm text-zinc-600 dark:text-zinc-300",
222+
deleted && "italic text-zinc-500 dark:text-zinc-400 text-xs mt-1", )}>
220223
{content}
221224
{isUpdated && !deleted && (<span className="text-[10px] mx-2 text-zinc-500 dark:text-zinc-400">
222225
(edited)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use client"
2+
import React, { createContext, useState, useContext, useEffect } from 'react';
3+
4+
interface FontSizeContextType {
5+
fontSize: string;
6+
changeFontSize: (size: string) => void;
7+
}
8+
9+
const FontSizeContext = createContext<FontSizeContextType | undefined>(undefined);
10+
11+
export const FontSizeProvider = ({ children }: {
12+
children: React.ReactNode;
13+
}) => {
14+
const [fontSize, setFontSize] = useState<string>('16px');
15+
16+
useEffect(() => {
17+
const savedFontSize = localStorage.getItem('fontSize');
18+
if (savedFontSize) {
19+
setFontSize(savedFontSize);
20+
}
21+
}, []);
22+
23+
const changeFontSize = (size: string) => {
24+
setFontSize(size);
25+
console.log(size);
26+
localStorage.setItem('fontSize', size);
27+
};
28+
29+
return (
30+
<FontSizeContext.Provider value={{ fontSize, changeFontSize }}>
31+
{children}
32+
</FontSizeContext.Provider>
33+
);
34+
};
35+
36+
export const useFontSize = (): FontSizeContextType => {
37+
const context = useContext(FontSizeContext);
38+
if (!context) {
39+
throw new Error('useFontSize must be used within a FontSizeProvider');
40+
}
41+
return context;
42+
};

0 commit comments

Comments
 (0)