Skip to content

Commit

Permalink
feat : fcm 연동 (#335)
Browse files Browse the repository at this point in the history
* chore : 이미지 경둜 μˆ˜μ •

* chore : ν•„μš” μ—†λŠ” μƒνƒœ 제거

* feat : λΉŒμ†‘ μ‹œ λ‘œμ»¬μŠ€ν† λ¦¬μ§€ κ°’ μ‚­μ œ

* style : μŠ€νƒ€μΌ μˆ˜μ •

* chore : μ„±κ³΅μ‹œ μ‚­μ œν•˜λ„λ‘ λ³€κ²½

* style : nav 및 메인 헀더 μˆ˜μ •

* feat : ν•„μš” μ˜μ‘΄μ„± μ„€μΉ˜

* feat : μ•ŒλžŒ μ„€μ • κ΅¬ν˜„

* chore : 이미지 경둜 μˆ˜μ •

* chore : ν•„μš” μ—†λŠ” μƒνƒœ 제거

* feat : λΉŒμ†‘ μ‹œ λ‘œμ»¬μŠ€ν† λ¦¬μ§€ κ°’ μ‚­μ œ

* style : μŠ€νƒ€μΌ μˆ˜μ •

* chore : μ„±κ³΅μ‹œ μ‚­μ œν•˜λ„λ‘ λ³€κ²½

* style : nav 및 메인 헀더 μˆ˜μ •

* feat : ν•„μš” μ˜μ‘΄μ„± μ„€μΉ˜

* feat : μ•ŒλžŒ μ„€μ • κ΅¬ν˜„

* ci : ci λΉŒλ“œ λ©”μ‹œμ§€ κ°•μ‘°
  • Loading branch information
HelloWook authored Dec 8, 2024
1 parent 4c48b94 commit 161fbd8
Show file tree
Hide file tree
Showing 22 changed files with 2,275 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: 'βœ… Build 성곡!'
message: '**βœ… Build 성곡!**'
1,326 changes: 1,326 additions & 0 deletions .pnp.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"classnames": "^2.5.1",
"clsx": "^2.1.1",
"file-saver": "^2.0.5",
"firebase": "^11.0.2",
"html2canvas": "^1.4.1",
"maplibre-gl": "^4.7.1",
"postcss-custom-properties-fallback": "^1.0.2",
Expand Down
11 changes: 11 additions & 0 deletions public/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
importScripts('https://www.gstatic.com/firebasejs/8.7.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.7.1/firebase-messaging.js');

firebase.initializeApp({
apiKey: 'AIzaSyBodJm9QErZvWuaOdM6Af1H82LA-8ZcmhE',
projectId: 'fcm-test-51b74',
messagingSenderId: '10805910843',
appId: '1:10805910843:web:e88131c7c1ef503822eb1e'
});

const messaging = firebase.messaging();
5 changes: 1 addition & 4 deletions src/components/Common/ItemSlider/ItemSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type ItemSliderProps = {
spaceBetween?: number;
value: string;
setValue: (value: string) => void;
setTheme: (themeId: number) => void;
};

export const ItemSlider = ({
Expand All @@ -33,8 +32,7 @@ export const ItemSlider = ({
height,
spaceBetween = 10,
value,
setValue,
setTheme
setValue
}: ItemSliderProps) => {
const [clickedItemId, setClickedItemId] = useState<string | null>(null);

Expand Down Expand Up @@ -68,7 +66,6 @@ export const ItemSlider = ({
onClick={() => {
setClickedItemId(item.id);
setValue(item.id);
setTheme(Number(item.id));
}}
>
<img
Expand Down
2 changes: 1 addition & 1 deletion src/components/Common/NavigationBar/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const NavigationBar = () => {
];

return (
<nav className="flex justify-around bg-white border-y p-3 max-w-[473px]">
<nav className="flex justify-around bg-white border-y p-3 max-w-[473px] fixed min-w-[375px] w-full bottom-0 z-10">
{navItems.map((item) => (
<div className="flex justify-center flex-1" key={item.id}>
<NavigationItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type LettetProps = {
letter: string;
setFont: React.Dispatch<React.SetStateAction<string>>;
setLetter: React.Dispatch<React.SetStateAction<string>>;
setTheme: (theme: number) => void;
};

export const LetterInputForm = ({
Expand All @@ -23,8 +22,7 @@ export const LetterInputForm = ({
font,
letter,
setFont,
setLetter,
setTheme
setLetter
}: LettetProps) => {
return (
<>
Expand Down Expand Up @@ -53,7 +51,6 @@ export const LetterInputForm = ({
letter={letter}
setFont={setFont}
setLetter={setLetter}
setTheme={setTheme}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,36 @@ import { useState } from 'react';
import { TopBar } from '@/components/Common/TopBar/TopBar';
import { useNavigate } from 'react-router-dom';
import { useLocalStorage } from '@/hooks/useLocalStorage';
import { useAutoSave } from '@/hooks/useAutoSave';
import { ThemeWrapper } from '../ThemeWrapper/ThemeWrapper';
import { LetterInputForm } from '../LetterInputForm/LetterInputForm';
import { useAutoSave, useToastStore } from '@/hooks';

export const PostLetterCotainer = () => {
const [title, setTitle] = useState<string>('');
const [letter, setLetter] = useState<string>('1');
const [letterContent, setLetterContent] = useState<string>('');
const [font, setFont] = useState<string>('initial');
const [theme, setTheme] = useState<number>(1);
const { setValue: saveTitle, storedValue: storedTitle } = useLocalStorage(
'title',
''
);
const { setValue: saveLetterContent, storedValue: storedContent } =
useLocalStorage('letterContent', '');
const { setValue: saveFont, storedValue: storedFont } = useLocalStorage(
'font',
''
);
const { setValue: saveLetter, storedValue: storedLetter } = useLocalStorage(
'letter',
''
);

const navigate = useNavigate();
const { addToast } = useToastStore();

const { setValue: saveTitle } = useLocalStorage('title', '');
const { setValue: saveLetterContent } = useLocalStorage(
'letterContent',
''
const [title, setTitle] = useState<string>(storedTitle || ' ');
const [letter, setLetter] = useState<string>(storedLetter || '1');
const [letterContent, setLetterContent] = useState<string>(
storedContent || ' '
);
const { setValue: saveFont } = useLocalStorage('font', '');
const { setValue: saveLetter } = useLocalStorage('letter', '');
const [font, setFont] = useState<string>(storedFont || 'initial');

const navigate = useNavigate();

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const inputValue = e.target.value;
Expand All @@ -36,7 +46,7 @@ export const PostLetterCotainer = () => {
saveLetter(letter);
};

useAutoSave(saveLetterData, 20000);
useAutoSave(saveLetterData, 10000);

return (
<>
Expand All @@ -45,11 +55,18 @@ export const PostLetterCotainer = () => {
navigate(-1);
}}
handleSuccesClick={() => {
if (!title.trim() && !letterContent.trim()) {
addToast(
'곡백을 μ œμ™Έν•œ 제λͺ©κ³Ό λ‚΄μš©μ„ μž…λ ₯ν•΄μ£Όμ„Έμš”',
'warning'
);
return;
}
saveLetterData();
navigate('/letter/select');
}}
/>
<ThemeWrapper themeId={theme}>
<ThemeWrapper themeId={Number(letter)}>
<LetterInputForm
title={title}
handleChange={handleChange}
Expand All @@ -59,7 +76,6 @@ export const PostLetterCotainer = () => {
letter={letter}
setFont={setFont}
setLetter={setLetter}
setTheme={setTheme}
/>
</ThemeWrapper>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IoIosNotifications } from 'react-icons/io';

export const TopButtonContainer = () => {
return (
<div className="flex justify-between px-6 py-4">
<div className="flex justify-between pb-8">
<NavLink to={'/'}>
<Logo h={34} />
</NavLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export const AnimationBottle = () => {
return (
<div className="flex justify-center w-full">
<img
src="/μœ λ¦¬λ³‘_μƒ˜ν”Œ.png"
className="object-contain w-24 h-52 animate-wiggle animate-infinite animate-ease-linear"
src="/μœ λ¦¬λ³‘.svg"
className="object-contain w-[35%] h-[35%] animate-wiggle animate-infinite animate-ease-linear"
/>
</div>
);
Expand Down
9 changes: 0 additions & 9 deletions src/components/SelectItemPage/SelectItem/SelectItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ const testLable: LabelProps[] = [
},
{
imgSrc: '/라벨_μƒ˜ν”Œ_02.png'
},
{
imgSrc: '/라벨_μƒ˜ν”Œ.png'
},
{
imgSrc: '/라벨_μƒ˜ν”Œ.png'
},
{
imgSrc: '/라벨_μƒ˜ν”Œ.png'
}
];

Expand Down
5 changes: 1 addition & 4 deletions src/components/SelectItemPage/SelectSlider/SelectSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ type SelectSliderProps = {
setFont: (font: string) => void;
letter: string;
setLetter: (letter: string) => void;
setTheme: (themeId: number) => void;
};

export const SelectSlider = ({
font,
setFont,
letter,
setLetter,
setTheme
setLetter
}: SelectSliderProps) => {
const [isFont, setIsFont] = useState(false);

Expand Down Expand Up @@ -46,7 +44,6 @@ export const SelectSlider = ({
value={isFont ? font : letter}
setValue={isFont ? setFont : setLetter}
spaceBetween={isFont ? 10 : 20}
setTheme={setTheme}
/>
</div>
<Margin bottom={20} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
export const SuccessModal = () => {
return (
<div className="flex flex-col items-center justify-center w-[50%] h-[20%] m-auto text-xl rounded-3xl animate-fade-up bg-slate-200 mt-[55%]">
<img src="/public/폭죽.png" className="w-12 h-12" />
<img src="/폭죽.png" className="w-12 h-12" />
<Margin top={10} />
<span>μ„±κ³΅μ μœΌλ‘œ</span>
<span>λ°œμ†‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€</span>
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useCreateLetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const useCreateLetter = () => {

onSuccess: () => {
navigate('/letter/success');
localStorage.removeItem('title');
localStorage.removeItem('letterContent');
localStorage.removeItem('letter');
localStorage.removeItem('font');
},
onError: (error: ApiErrorType) => {
addToast(`${error.message}`, 'warning');
Expand Down
33 changes: 33 additions & 0 deletions src/hooks/usePushNotification .ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { firebaseMessaging, getToken, onMessage } from '@/util/firebase';
import { useEffect } from 'react';
import { useToastStore } from './useToastStore';
import { postToken } from '@/service/nofication/postToken';

export const usePushNotification = () => {
const { addToast } = useToastStore();

useEffect(() => {
Notification.requestPermission().then((permission) => {
if (permission === 'granted') {
getToken(firebaseMessaging, {
vapidKey: import.meta.env.VITE_FCM_VAPID_KEY
})
.then((token) => {
postToken({ token });
})
.catch((error) => {
addToast('μ•ŒλžŒ 섀정에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.', 'error');
console.error(error);
});
} else {
addToast('μ•ŒλžŒ 섀정을 κ±°λΆ€ν–ˆμŠ΅λ‹ˆλ‹€.', 'success');
}
});

onMessage(firebaseMessaging, (payload) => {
if (payload.notification) {
addToast(`${payload.notification.body}`, 'success');
}
});
}, []);
};
Loading

0 comments on commit 161fbd8

Please sign in to comment.