Skip to content

Commit 492df44

Browse files
authored
Merge pull request #131 from codeit-maso/feature/chan
✨ feat: 이모지 카운트 포맷팅 및 프로필 +N 카운트 제한 기능 추가 / 코드 스플리팅 적용
2 parents 3741f4e + 091752b commit 492df44

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

src/App.jsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
import './assets/styles/base.scss';
22
import { Route, Routes } from 'react-router-dom';
3+
import { Suspense, lazy } from 'react';
34
import Header from './components/layout/Header/Header';
4-
import RecipientList from './pages/RecipientList/RecipientList';
5-
import Home from './pages/Home/Home';
6-
import CreateRecipient from './pages/CreateRecipient/CreateRecipient';
7-
import Recipient from './pages/Recipient/Recipient';
8-
import MessageForm from './pages/MessageForm/MessageForm';
5+
6+
const RecipientList = lazy(() => import('./pages/RecipientList/RecipientList'));
7+
const Home = lazy(() => import('./pages/Home/Home'));
8+
const CreateRecipient = lazy(
9+
() => import('./pages/CreateRecipient/CreateRecipient'),
10+
);
11+
const Recipient = lazy(() => import('./pages/Recipient/Recipient'));
12+
const MessageForm = lazy(() => import('./pages/MessageForm/MessageForm'));
913

1014
export default function App() {
1115
return (
1216
<>
1317
<Header />
14-
<Routes>
15-
<Route path="/" element={<Home />} />
16-
<Route path="/list" element={<RecipientList />} />
17-
<Route path="/post" element={<CreateRecipient />} />
18-
<Route path="/post/:id" element={<Recipient showDelete={false} />} />
19-
<Route
20-
path="/post/:id/edit"
21-
element={<Recipient showDelete={true} />}
22-
/>
23-
<Route path="/post/:id/message" element={<MessageForm />} />
24-
</Routes>
18+
<Suspense fallback={<div>로딩중...</div>}>
19+
<Routes>
20+
<Route path="/" element={<Home />} />
21+
<Route path="/list" element={<RecipientList />} />
22+
<Route path="/post" element={<CreateRecipient />} />
23+
<Route path="/post/:id" element={<Recipient showDelete={false} />} />
24+
<Route
25+
path="/post/:id/edit"
26+
element={<Recipient showDelete={true} />}
27+
/>
28+
<Route path="/post/:id/message" element={<MessageForm />} />
29+
</Routes>
30+
</Suspense>
2531
</>
2632
);
2733
}

src/components/recipient/HeaderService/HeaderService.jsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import emojiAdd from '../../../assets/images/emoji-add.svg';
44
import chevronDown from '../../../assets/images/chevron-down.svg';
55
import { fetchReactions, addReaction } from '../../../api/emojiReactions';
66
import ShareButton from './Share/ShareButton';
7+
import { formatCount } from '../../../utils/numberFormat';
8+
9+
function getProfileExtraCount(count) {
10+
if (count > 99) return '99';
11+
return count;
12+
}
713

814
export default function HeaderService({ recipient }) {
915
const [reactions, setReactions] = useState([]);
@@ -164,7 +170,7 @@ export default function HeaderService({ recipient }) {
164170
))}
165171
{recipient?.messageCount > 3 && (
166172
<div className={styles['header-service__additional-count']}>
167-
+{recipient.messageCount - 3}
173+
+{getProfileExtraCount(recipient.messageCount - 3)}
168174
</div>
169175
)}
170176
</div>
@@ -187,9 +193,9 @@ export default function HeaderService({ recipient }) {
187193
>
188194
<span className={styles['header-service__emoji']}>
189195
{reaction.emoji}
190-
</span>{' '}
196+
</span>
191197
<span className={styles['header-service__count']}>
192-
{reaction.count}
198+
{formatCount(reaction.count)}
193199
</span>
194200
</button>
195201
))
@@ -235,9 +241,9 @@ export default function HeaderService({ recipient }) {
235241
>
236242
<span className={styles['header-service__emoji']}>
237243
{reaction.emoji}
238-
</span>{' '}
244+
</span>
239245
<span className={styles['header-service__count']}>
240-
{reaction.count}
246+
{formatCount(reaction.count)}
241247
</span>
242248
</button>
243249
))

src/utils/numberFormat.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function formatCount(count) {
2+
if (count >= 1000000) return `${(count / 1000000).toFixed(1)}M`;
3+
if (count >= 1000) return `${(count / 1000).toFixed(1)}K`;
4+
return count.toString();
5+
}

0 commit comments

Comments
 (0)