Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
MAX_CUSTOM_TAG_COUNT,
tagCreateDataSchema,
} from "@/schemas/tag/tag-schema";
import { getDefaultTagLabelKey } from "@/utils/todo/tag-label";
import { getDefaultTagLabelKey, isDefaultTagId } from "@/utils/todo/tag-label";

const LANGUAGE_REQUEST_MAP: Record<
SettingsLanguage,
Expand Down Expand Up @@ -58,14 +58,13 @@ export const useSettingsProfile = () => {
const { mutate: logoutMutate, isPending: isLoggingOut } = useLogoutMutation();

const tagItems = (tagsQuery.data?.tags ?? []).map((tag) => {
const labelKey = tag.isDefault
? getDefaultTagLabelKey(tag.tagId)
: undefined;
const isDefault = isDefaultTagId(tag.tagId);
const labelKey = isDefault ? getDefaultTagLabelKey(tag.tagId) : undefined;

return {
id: tag.tagId,
label: labelKey ? tCommon(`tag.${labelKey}`) : tag.name,
isDefault: tag.isDefault,
isDefault,
Comment on lines +61 to +67

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

센스 있는 최적화로 성능을 한 스푼 올려볼까요?

현재 isDefault를 구할 때 내부적으로 getDefaultTagLabelKey를 호출하고, 그 값이 참이면 labelKey를 구하기 위해 동일한 함수를 한 번 더 호출하고 있어요.

getDefaultTagLabelKey의 결과를 먼저 변수에 담아두고 이 값을 활용해 기본 태그 여부를 판별하면 중복 연산을 깔끔하게 줄일 수 있습니다. 결괏값 재사용은 연산 낭비를 막는 최적화의 기본 관행이랍니다! (참고: MDN - 함수의 기본)

수정하신 로직도 문제없이 훌륭하게 작동하지만, 이 부분만 살짝 다듬어보면 더 완벽해질 것 같아요. 제안된 코드를 적용하신다면 상단의 isDefaultTagId import도 함께 제거해 주시면 좋습니다. 🚀

✨ 중복 호출을 제거하는 제안
-    const isDefault = isDefaultTagId(tag.tagId);
-    const labelKey = isDefault ? getDefaultTagLabelKey(tag.tagId) : undefined;
+    const labelKey = getDefaultTagLabelKey(tag.tagId);
+    const isDefault = labelKey !== undefined;

     return {
       id: tag.tagId,
       label: labelKey ? tCommon(`tag.${labelKey}`) : tag.name,
       isDefault,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isDefault = isDefaultTagId(tag.tagId);
const labelKey = isDefault ? getDefaultTagLabelKey(tag.tagId) : undefined;
return {
id: tag.tagId,
label: labelKey ? tCommon(`tag.${labelKey}`) : tag.name,
isDefault: tag.isDefault,
isDefault,
const labelKey = getDefaultTagLabelKey(tag.tagId);
const isDefault = labelKey !== undefined;
return {
id: tag.tagId,
label: labelKey ? tCommon(`tag.${labelKey}`) : tag.name,
isDefault,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/timo-web/app/`[locale]/(main)/settings/_hooks/account/use-settings-profile.ts
around lines 61 - 67, Update the tag mapping logic to call getDefaultTagLabelKey
once, store its result in labelKey, and derive isDefault from whether labelKey
is present. Remove the now-unused isDefaultTagId import while preserving the
existing label translation and fallback behavior.

};
});

Expand Down
4 changes: 2 additions & 2 deletions apps/timo-web/hooks/todo-modal/common/use-tag-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
MAX_CUSTOM_TAG_COUNT,
tagCreateDataSchema,
} from "@/schemas/tag/tag-schema";
import { getDefaultTagLabelKey } from "@/utils/todo/tag-label";
import { getDefaultTagLabelKey, isDefaultTagId } from "@/utils/todo/tag-label";

export interface UseTagFieldParams<TFieldValues extends FieldValues> {
control: Control<TFieldValues>;
Expand Down Expand Up @@ -63,7 +63,7 @@ export const useTagField = <TFieldValues extends FieldValues>({
(option) => option.id === field.value,
);
const customTagCount = (tagsQuery.data?.tags ?? []).filter(
(tag) => !tag.isDefault,
(tag) => !isDefaultTagId(tag.tagId),
).length;

const handleSelectTag = (label: string) => {
Expand Down
1 change: 0 additions & 1 deletion apps/timo-web/schemas/tag/tag-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const MAX_CUSTOM_TAG_COUNT = 4;
export const tagSchema = z.object({
tagId: z.number(),
name: z.string(),
isDefault: z.boolean(),
});

export const tagListDataSchema = z.object({
Expand Down
3 changes: 3 additions & 0 deletions apps/timo-web/utils/todo/tag-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ const DEFAULT_TAG_ID_TO_LABEL_KEY: Record<number, TagLabelKey> = {

export const getDefaultTagLabelKey = (tagId: number): TagLabelKey | undefined =>
DEFAULT_TAG_ID_TO_LABEL_KEY[tagId];

export const isDefaultTagId = (tagId: number): boolean =>
getDefaultTagLabelKey(tagId) !== undefined;
Loading