์ด์ ๊น์ง๋ ๋จ์ํ ๋์ ํ๋กํ๊ณผ ๊ฑฐ๋ ํต๊ณ ์ ๋๋ง ๋ณด์ฌ์ฃผ๋ ๊ตฌ์กฐ์์ง๋ง, ์ด๋ฒ์๋ ๋ ๋ง์ ์์ ์ ์ ๋ณด๋ฅผ ๋ณด์ฌ์ฃผ๊ธฐ ์ํด ํ๋ก์/ํ๋ก์ ๋ฆฌ์คํธ๋ฅผ ์ถ๊ฐํ๋ค. ๋ํ ์ซ์ ํฌ๋งท, ์๋ต ์๊ฐ ํ์, ์ ํฌ๋ ฅ ํํ ๋ฑ์์ ์ ํธ ํจ์ ๋ถ๋ฆฌ ๋ฐ ํฌ๋งท ์ ํ๋ ํจ๊ป ์งํํ๋ค.
ProfileData์๋ ๋ค์๊ณผ ๊ฐ์ ๊ตฌ์กฐ๊ฐ ์์๋ค:
{
following: ["userId1", "userId2", ...],
followers: ["userId3", "userId4", ...],
}
๋จ์ํ ์ ์ ID ๋ฐฐ์ด๋ง ์์ด์, ํ๋ฉด์ ๋ณด์ฌ์ฃผ๊ธฐ ์ํด์๋ ๊ฐ ์ ์ ID์ ๋ํด ๋ค์ API ํธ์ถ์ด ํ์ํ๋ค.
const followingProfiles = await Promise.all(
following.map(userId => shootingStar.launch(GetProfileByUserIDGameIDWing(userId, gameID)))
)
โ ๊ฐ๊ฐ์ userID์ ๋ํด ๋ค์ ProfileData๋ฅผ ๋ฐ์์์ผ ํ๋ฉด์ ๊ตฌ์ฑํ ์ ์์์.
๋ฒํผ์ ์ข์ฐ ์๋ฐฉํฅ ํ ๊ธ์ผ๋ก ๊ตฌ์ฑ:
<FavoriteButton
onLeftClick={handleLeftButtonClick}
onRightClick={handleRightButtonClick}
FollowingNumber={followingProfiles.length}
FollowerNumber={followerProfiles.length}
/>
๋ด๊ฐ ์ฆ๊ฒจ์ฐพ๋ โ ํ๋ก์ ๋ชฉ๋ก
๋๋ฅผ ์ฆ๊ฒจ์ฐพ๋ โ ํ๋ก์ ๋ชฉ๋ก
ํด๋น ๋ฒํผ ํด๋ฆญ ์, ๊ฐ๊ฐ visibleSection์ ์ ๋ฐ์ดํธํด์ ์๋์ ๋ฆฌ์คํธ๊ฐ ๋ณด์ฌ์ง๋๋ก ๊ตฌ์ฑ:
{visibleSection === 'following' && followingProfiles.map(...) }
{visibleSection === 'follower' && followerProfiles.map(...) }
FollowContainer, FollowerContainer๋ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ๊ตฌ์กฐ๋ก ์ค๊ณํด ์คํ์ผ ์ ์ง์ ์ปดํฌ๋ํธ ๋ถ๋ฆฌ๊ฐ ๊น๋ํด์ก๋ค.
์ ํฌ๋ ฅ: 14,213,000 โ 1,000๋ง+ ์์ผ๋ก ์ถ์ฝ
์๋ต ์๊ฐ: 1,542,300 ๋ง์ดํฌ๋ก์ด โ 1.5์ด ํํ๋ก ๋ณํ
์ฌ๊ฑฐ๋์จ: 0.864444444%์ฒ๋ผ ๋๋ฌด ๊ธด ์ค์ โ ๋ถํธํ๊ณ ์ง์ ๋ถํ ํํ
์ฒ์์๋ toFixed() ๊ฐ์ ๋ด์ฅ ํจ์๋ง ์ฐ๊ธฐ๋ ํ์ง๋ง, ๊ฒฐ๊ตญ ์ค๋ณต๋๊ณ ์ ์ง๋ณด์๊ฐ ์ด๋ ค์์ง๋ ๊ฑธ ๋ง๊ธฐ ์ํด utils๋ก ๋ถ๋ฆฌํ๋ค.
๋ํ ์ด ๊ณผ์ ์์ toFixed(1)์ด ๋ฌธ์์ด์ ๋ฐํํ๋ค๋ ์ ๋ ๊ณ ๋ คํ๊ฒ ๋๋๋ฐ, ์๋ฅผ ๋ค์ด 0.864444444.toFixed(1)์ ๋ฌธ์์ด "0.9"๋ฅผ ๋ฐํํ๊ธฐ ๋๋ฌธ์ ์ซ์ ๊ณ์ฐ์ด ํ์ํ UI์๋ ์ ์ ํ์ง ์์๋ค. ๋์ Math.floor๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ ์ฒ๋ฆฌ๋ฅผ ์ง์ ์ ์ดํ๋ ๋ฐฉ์์ผ๋ก ๊ฐ์ ํ๋ค.
์ด ํจ์์์ ํต์ฌ์ ๋จ์ํ ๋จ์๋ฅผ ๋๋๋ ๊ฒ๋ฟ ์๋๋ผ, Math.floor()๋ฅผ ํ์ฉํด์ ์์์ ์์ด ์ ์๋ก '๋ฑ ๋์ด๋ด๋' ์ฒ๋ฆฌ๋ฅผ ํจ๊ป ์ ์ฉํ๋ค๋ ์ ์ด๋ค. ์๋ฅผ ๋ค์ด 54213000์ 5.4213์ฒ๋ง์ด์ง๋ง, ์ฐ๋ฆฌ๋ ์ด๋ฅผ 5์ฒ๋ง์ผ๋ก ํํํ๊ธฐ ์ํด Math.floor(power / 10000000) ๊ฐ์ ํํ๋ก ๊ตฌ์ฑํ๋ค. โ ์์์ ์ดํ๋ฅผ ๋ฒ๋ฆฌ๊ณ ๋จ์๋ฅผ ๋์ด์ฃผ๋ ๋ฐฉ์.
export const formatPower = (power: number): string => {
if (power >= 100000000) {
const billions = Math.floor(power / 100000000);
return `${billions}์ต`;
} else if (power >= 10000000) {
const tenMillions = Math.floor(power / 10000000);
return `${tenMillions}์ฒ๋ง`;
} else if (power >= 10000) {
const tenThousand = Math.floor(power / 10000);
return `${tenThousand}๋ง`;
} else {
return power.toLocaleString();
}
};
์
๋ ฅ ์ ํฌ๋ ฅ ์ถ๋ ฅ ๋ฌธ์์ด
1234 1,234
120000 12๋ง
987654321 9์ต
20000000 2์ฒ๋ง
54213000 5์ฒ๋ง
์ด ๊ตฌ์กฐ๋ "์ฒ๋ง" ๋จ์ ํํ๋ ์ง์ํด์, ์ต ๋จ์๋ก ํํํ๊ธฐ ์ ๋งคํ ์ซ์๋ ์์ฐ์ค๋ฝ๊ฒ ๋จ์ ๋์ด์ ํํํ ์ ์์
โ ์ซ์ ๊ท๋ชจ๊ฐ ํด์๋ก ์๊ฐ์ ์ผ๋ก ๋ช
ํํ๊ฒ ๊ตฌ๋ถ ๊ฐ๋ฅํ๊ณ , ๊ฐ๋
์ฑ๊ณผ ์ ๋ฌ๋ ฅ์ด ํฅ์๋จ
์์ ์ค "๊ทธ๋ฅ ์๋ฒ์์ ์ ์๋ก ์๋ผ์ ์ฃผ๋ฉด ๋๋ ๊ฑฐ ์๋๊ฐ?"๋ผ๋ ์์ฒญ๋ ํ๋๋ฐ, ์ด์ ๋ํด ๋ฐฑ์๋ ๊ฐ๋ฐ์๊ฐ ์ค๋ช ํ๊ธธ:
"๊ฐ์ ํฌ๋งท์ ์ฌ๋ฌ API์์ ๊ณต์ ํด์ผ ํ๊ณ , ์ด๊ฑธ ์๋ฒ์์ ๋งค๋ฒ ๊ฐ๊ณตํ๋ฉด ์คํ๋ ค ์์ ๋ญ๋น๊ฐ ํฌ๋ค. ํด๋ผ์ด์ธํธ์์ ํ ์ค๋ก ์๋ฅด๊ณ ์ฐ๋ ๊ฒ ๋ถ๋ด๋ ์ ๊ณ ํ์ฅ์ฑ๋ ์ข๋ค"๊ณ ํ๋ค.
์ค์ ๋ก ํ๋ก ํธ์์๋ Math.floor๋ก ์๋ผ์ฃผ๊ธฐ๋ง ํ๋ฉด ๋๋๊น, ์ฌ์ฌ์ฉ์ฑ๊ณผ ์ ์ง๋ณด์ ์ธก๋ฉด์์๋ ๋ ํฉ๋ฆฌ์ ์ด์๋ค.
// 0.864444444 โ ๋๋ฌด ๋ณด๊ธฐ ๋ถํธํจ!
๊ทธ๋์ ์ ์ ๊ฐ ์ง๊ด์ ์ผ๋ก ์ดํดํ ์ ์๋๋ก ํผ์ผํธ ๋จ์๋ก ์ ๋ฆฌํด์ ํํํ๋ค.
export const FormatRetrade = (retrade: number): number => {
const FormattedRetrade = Math.floor(retrade * 100);
return FormattedRetrade;
};
0.743 โ 74%
0.812 โ 81%
0.864444444 โ 86%
toFixed()๋ฅผ ์ฐ๋ฉด "0.9"์ฒ๋ผ ๋ฌธ์์ด๋ก ๋ฐํ๋์ด ์ฌ์ฌ์ฉ์ด ๋ถํธํ์ง๋ง,
Math.floor๋ฅผ ์ฌ์ฉํ๋ฉด ์ซ์ ๊ทธ๋๋ก ๋ฑ ๋จ์ด์ง๋ ์ ์๋ก ์ฒ๋ฆฌ ๊ฐ๋ฅํด์ ํผ์ผํธ ํํ์ ๋ ์ ํฉํ๋ค.
<StatusBadge
level={mainCharacter?.level}
power={formatPower(mainCharacter?.power || 0)}
union={mainCharacter?.union}
/>
<TradeStatus
popularity={profileData.stat.popularity}
retrade_rate={FormatRetrade(profileData.stat.retrade_rate)}
response_time={convertMicrosecondsToTime(profileData.stat.mean_response_time)}
/>
์ ํธ ํจ์๋ก ๋ชจ๋ ์ซ์ ํํ์ด ํ์คํ๋จ
์ฌ์ฉ์์๊ฒ ๋ณด์ฌ์ง๋ ์ ๋ณด๊ฐ ๋ ๊ฐ๊ฒฐํ๊ณ ์ง๊ด์ ์
โ์ซ์ ํ๋์๋ UX๊ฐ ์๋ค.โ
์ซ์ ํํ์ ๋จ์ํ ๋ฐ์ดํฐ๊ฐ ์๋, ์ฌ์ฉ์๊ฐ ๊ทธ ์ ์ ๋ฅผ ์ด๋ค ๋๋์ผ๋ก ์ธ์ํ ์ง ๊ฒฐ์ ํ๋ ์๊ฐ ์์๋ค.
์ ํฌ๋ ฅ์ ์์ํ๊ฒ ๋์ด์ง ๋จ์๋ก,
ํผ์ผํธ๋ ์งง๊ณ ๋ช
ํํ ์ ์๋ก ํํํ๋ ์ ์ฒด ํ๋กํ ํ๋ฉด์ด ์ ๋ขฐ๊ฐ ์๊ณ ์ ๋๋ ๋๋์ ์ฃผ๊ฒ ๋์๋ค.
์์ผ๋ก๋ ๋ชจ๋ ์ซ์ ํํ์ ์ ํธ ๊ธฐ๋ฐ์ผ๋ก ๊ด๋ฆฌํ๊ณ , ์ฌ์ฉ์ ๊ด์ ์ ์ ๋ณด ์ ๋ฌ์ ์ฐ์ ํ๊ฒ ๋ค.