-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature] 카테고리 관리 화면에서, 내가 만든 목표와 그룹에 속한 목표를 분리 #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
764ddd9
feat: 내가 만든 목표와 그룹에 속한 목표를 분리
dioo1461 caae26b
fix: 그룹 카테고리는 수정/삭제 버튼 제거
dioo1461 a55df4a
style: 내가 만든 목표에도 노란색 color indicator 나타나도록 수정
dioo1461 92e0a4f
style: 카테고리 수정/삭제 버튼 스타일 변경
dioo1461 22899bd
fix: update BUTTON_ICON_STYLE to use containerStyle and remove unused…
dioo1461 068c2b4
refactor: 코드 리뷰 반영
dioo1461 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,70 @@ | ||
| import { useQuery, useQueryClient } from '@tanstack/react-query'; | ||
| import { useQueries, useQueryClient } from '@tanstack/react-query'; | ||
| import { useCallback, useMemo } from 'react'; | ||
|
|
||
| import type { GroupColorKey } from '@/constants/groupColors'; | ||
| import { GROUP_COLORS } from '@/constants/groupColors'; | ||
| import { useProfileQuery } from '@/features/user/api/queries'; | ||
| import { ASYNC_KEYS, asyncStorage } from '@/utils/asyncStorage'; | ||
|
|
||
| import { useGroupsQuery } from '../api/queries'; | ||
|
|
||
| const GROUP_COLOR_KEYS = Object.keys(GROUP_COLORS) as GroupColorKey[]; | ||
| const queryKey = (userId: number | null, groupId: number) => ['groupColor', userId, groupId]; | ||
|
|
||
| const pickRandomGroupColorKey = (): GroupColorKey => | ||
| GROUP_COLOR_KEYS[Math.floor(Math.random() * GROUP_COLOR_KEYS.length)]; | ||
|
|
||
| const isGroupColorKey = (v: string): v is GroupColorKey => | ||
| (GROUP_COLOR_KEYS as readonly string[]).includes(v); | ||
|
|
||
| export const useGroupColorKey = (groupId: number | null) => { | ||
| const { data: profileData } = useProfileQuery(); | ||
| const userId = profileData?.id; | ||
| export const useGroupColorKeyMap = () => { | ||
| const groups = useGroupsQuery().data; | ||
| const groupIds = useMemo( | ||
| () => Array.from(new Set(groups?.map(g => g.groupId))).sort((a, b) => a - b), | ||
| [groups], | ||
| ); | ||
| const userId = useProfileQuery().data?.id ?? null; | ||
| const qc = useQueryClient(); | ||
|
|
||
| const queryKey = ['groupColor', userId, groupId]; | ||
|
|
||
| const { data: colorKey } = useQuery({ | ||
| queryKey, | ||
| enabled: userId != null && groupId != null, | ||
| queryFn: async () => { | ||
| if (userId == null || groupId == null) return null; | ||
| const results = useQueries({ | ||
| queries: groupIds.map((groupId) => ({ | ||
| queryKey: queryKey(userId, groupId), | ||
| enabled: userId != null && groupId != null, | ||
| queryFn: async (): Promise<GroupColorKey | null> => { | ||
| if (userId == null) return null; | ||
| const storageKey = ASYNC_KEYS.groupColor(userId, groupId); | ||
| const stored = await asyncStorage.get(storageKey); | ||
|
|
||
| const storageKey = ASYNC_KEYS.groupColor(userId, groupId); | ||
| const stored = await asyncStorage.get(storageKey); | ||
| if (stored && isGroupColorKey(stored)) return stored; | ||
|
|
||
| if (stored && isGroupColorKey(stored)) return stored; | ||
| const newKey = pickRandomGroupColorKey(); | ||
| await asyncStorage.set(storageKey, newKey); | ||
| return newKey; | ||
| }, | ||
| staleTime: Infinity, | ||
| gcTime: Infinity, | ||
| })), | ||
| }); | ||
|
|
||
| const newKey = pickRandomGroupColorKey(); | ||
| await asyncStorage.set(storageKey, newKey); | ||
| return newKey; | ||
| }, | ||
| staleTime: Infinity, | ||
| gcTime: Infinity, | ||
| const colorKeyMap = new Map<number, GroupColorKey>(); | ||
| groupIds.forEach((groupId, idx) => { | ||
| const colorKey = results[idx]?.data ?? null; | ||
| if (colorKey) colorKeyMap.set(groupId, colorKey); | ||
| }); | ||
|
|
||
| const updateColorKey = async (next: GroupColorKey) => { | ||
| if (userId == null || groupId == null) return; | ||
| const updateColorKey = useCallback( | ||
| async (groupId: number, next: GroupColorKey) => { | ||
| if (userId == null) return; | ||
| qc.setQueryData(queryKey(userId, groupId), next); | ||
| await asyncStorage.set(ASYNC_KEYS.groupColor(userId, groupId), next); | ||
| }, | ||
| [qc, userId], | ||
| ); | ||
|
|
||
| qc.setQueryData(queryKey, next); | ||
| await asyncStorage.set(ASYNC_KEYS.groupColor(userId, groupId), next); | ||
| return { | ||
| colorKeyMap: colorKeyMap, | ||
| updateColorKey, | ||
| isReady: userId != null, | ||
| }; | ||
|
|
||
| return { colorKey: colorKey ?? null, updateColorKey }; | ||
| }; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { Button, Icon, Shapes, Text, TText } from '@/components'; | |
| import { useDeleteCategoryMutation } from '@/features/category/api/mutations'; | ||
| import type { CategoryTag } from '@/features/category/model'; | ||
| import { useStackNavigation } from '@/hooks'; | ||
| import { theme } from '@/theme'; | ||
| import { dialogService } from '@/utils/dialog'; | ||
| import type { Time } from '@/utils/Time'; | ||
|
|
||
|
|
@@ -56,6 +57,7 @@ const CategoryItem = ({ id, title, goal, tags = [] }: CategoryItemProps) => { | |
| return ( | ||
| <View style={styles.container}> | ||
| <View style={styles.content}> | ||
| <View style={styles.groupColorIndicator} /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <Text {...GOAL_NAME_TEXT_STYLE}> | ||
| {title} | ||
| </Text> | ||
|
|
@@ -86,12 +88,16 @@ const CategoryItem = ({ id, title, goal, tags = [] }: CategoryItemProps) => { | |
| <View style={styles.content}> | ||
| <Button.Icon | ||
| Icon={Icon.Edit} | ||
| color={theme.color.blue[300]} | ||
| containerStyle={[styles.iconContainer, { borderColor: theme.color.blue[300] }]} | ||
| height={16} | ||
| onPress={onEditPress} | ||
| width={16} | ||
| /> | ||
| <Button.Icon | ||
| Icon={Icon.TrashBin} | ||
| color={theme.color.red[300]} | ||
| containerStyle={[styles.iconContainer, { borderColor: theme.color.red[300] }]} | ||
| height={16} | ||
| onPress={onDeletePress} | ||
| width={16} | ||
|
|
||
51 changes: 51 additions & 0 deletions
51
src/screens/category/ManageCategoryScreen/components/GroupCategoryItem/index.style.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import type { ViewStyle } from 'react-native'; | ||
| import { StyleSheet } from 'react-native'; | ||
|
|
||
| import type { TextProps } from '@/components/Text'; | ||
| import { GROUP_COLORS, type GroupColorKey } from '@/constants/groupColors'; | ||
| import { theme } from '@/theme'; | ||
| import type { Color } from '@/types'; | ||
|
|
||
| export const createStyles = ({ | ||
| groupColorKey, | ||
| }: { | ||
| groupColorKey: GroupColorKey; | ||
| }) => StyleSheet.create({ | ||
| container: { | ||
| flexDirection: 'row', | ||
| justifyContent: 'space-between', | ||
| paddingVertical: theme.spacing[200], | ||
| }, | ||
| content: { | ||
| flexDirection: 'row', | ||
| alignItems: 'center', | ||
| gap: theme.spacing[200], | ||
| }, | ||
| groupColorIndicator: { | ||
| backgroundColor: GROUP_COLORS[groupColorKey].medium, | ||
| width: 10, height: 10, | ||
| borderRadius: theme.radius['max'], | ||
| }, | ||
| }); | ||
|
|
||
| export const GOAL_NAME_TEXT_STYLE: TextProps = { | ||
| font: 'b3', | ||
| }; | ||
|
|
||
| export const GOAL_TIME_TEXT_STYLE: TextProps = { | ||
| font: 'b4', | ||
| color: theme.color.neutral[500], | ||
| }; | ||
|
|
||
| export const TAG_CONTAINER_STYLE = (color: Color): ViewStyle => ({ | ||
| borderRadius: theme.radius['max'], | ||
| borderWidth: 1, | ||
| borderColor: color, | ||
| paddingVertical: theme.spacing[50], | ||
| paddingHorizontal: theme.spacing[100], | ||
| }); | ||
|
|
||
| export const TAG_TEXT_STYLE = (color: Color): TextProps => ({ | ||
| font: 'b5', | ||
| color, | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (belongingGroup)블록 내에 있어belongingGroup이 항상 참이므로 삼항 연산자는 불필요합니다. 코드를 단순화할 수 있습니다.그러나 더 중요한 문제가 있습니다.
groupColorKey를 찾지 못하면(예: 데이터 로딩 중) 해당 카테고리가 '내 목표'와 '그룹 목표' 목록 양쪽에서 모두 누락되어 UI에서 일시적으로 사라지게 됩니다. 이는 사용자 경험에 좋지 않은 영향을 줍니다.useGroupColorKeyMap의isReady플래그를 사용하여 색상 데이터가 준비되었을 때만 이 로직을 실행하도록 하여 이 문제를 해결하는 것을 고려해 보세요.