From 80ddf82297cc463ac31cf73a4b9f0699129e2002 Mon Sep 17 00:00:00 2001 From: nafees nazik Date: Thu, 19 Nov 2026 14:26:03 +0530 Subject: [PATCH] fix(icons): address review feedback on resets and filter types The picker now emits null when the selected icon is the entity default, and the board/status edit forms track picker interaction instead of comparing against a captured value, so an untouched icon is omitted while an explicit default selection persists null even after a refetch. The roadmap drop reads the synchronous drag target first. The picker popup gets an accessible name, and the sprite URL is resolved lazily after the browser check so server module evaluation does not touch import.meta.url. Home filter rows are a discriminated union, recent-post projections derive from the domain rows, and the post form's board list derives its type from PostBoardSelect. --- .../features/home/components/board-select.tsx | 8 ++++---- .../features/home/components/status-menu.tsx | 2 +- .../src/features/home/home-context.ts | 19 ++++++++++++++----- .../src/features/home/home-provider.tsx | 16 ++++++++++++++-- .../board/components/rename-board-dialog.tsx | 19 +++++++++---------- .../components/recent-posts-section.tsx | 18 ++++-------------- .../components/post-status-edit-dialog.tsx | 15 ++++++++------- .../roadmap/components/roadmap-board.tsx | 2 +- .../src/forms/post-create-form-shared.tsx | 8 ++++++-- packages/post-ui/src/post-field.tsx | 2 +- packages/ui/src/icon-picker/index.tsx | 12 ++++++++++-- packages/ui/src/icon-picker/sprite.ts | 16 +++++++--------- 12 files changed, 79 insertions(+), 58 deletions(-) diff --git a/apps/public-feature-board/src/features/home/components/board-select.tsx b/apps/public-feature-board/src/features/home/components/board-select.tsx index 307b5138..77b51473 100644 --- a/apps/public-feature-board/src/features/home/components/board-select.tsx +++ b/apps/public-feature-board/src/features/home/components/board-select.tsx @@ -34,9 +34,9 @@ export function HomeBoardSelect({ className }: { className?: string }) { return item ? ( - {item.icon === undefined ? null : ( + {item.kind === "board" ? ( - )} + ) : null} {item.label} ) : null; @@ -47,9 +47,9 @@ export function HomeBoardSelect({ className }: { className?: string }) { {boardItems.map((item) => ( - {item.icon === undefined ? null : ( + {item.kind === "board" ? ( - )} + ) : null} {item.label} diff --git a/apps/public-feature-board/src/features/home/components/status-menu.tsx b/apps/public-feature-board/src/features/home/components/status-menu.tsx index c8cb03f8..5599ea95 100644 --- a/apps/public-feature-board/src/features/home/components/status-menu.tsx +++ b/apps/public-feature-board/src/features/home/components/status-menu.tsx @@ -44,7 +44,7 @@ export function HomeStatusMenu({ className }: { className?: string }) { {statusItems.map((item) => ( - {item.statusType ? ( + {item.kind === "status" ? ( ) : null} {item.label} diff --git a/apps/public-feature-board/src/features/home/home-context.ts b/apps/public-feature-board/src/features/home/home-context.ts index 3a1d7484..e39644be 100644 --- a/apps/public-feature-board/src/features/home/home-context.ts +++ b/apps/public-feature-board/src/features/home/home-context.ts @@ -5,16 +5,25 @@ import { createContext, use } from "react"; import type { HomePageSortOption } from "../../hooks/use-home-page-filters"; -export type HomeFilterItem = { +type HomeFilterItemBase = { count: number; - /** The board or status mark; absent on the "all" row. */ - icon?: string | null; label: string; - /** Present on status rows, absent on board rows and "all". */ - statusType?: TPostStatus["type"]; value: string; }; +/** + * A row in the board or status filter. The variants keep an "all" row from + * carrying a mark and a status row from omitting its vocabulary. + */ +export type HomeFilterItem = + | (HomeFilterItemBase & { kind: "all" }) + | (HomeFilterItemBase & { icon: TBoard["icon"]; kind: "board" }) + | (HomeFilterItemBase & { + icon: TPostStatus["icon"]; + kind: "status"; + statusType: TPostStatus["type"]; + }); + export type HomePost = { board: TBoard; post: TPostListItem; diff --git a/apps/public-feature-board/src/features/home/home-provider.tsx b/apps/public-feature-board/src/features/home/home-provider.tsx index 7a78b3e9..2c3c0f55 100644 --- a/apps/public-feature-board/src/features/home/home-provider.tsx +++ b/apps/public-feature-board/src/features/home/home-provider.tsx @@ -270,10 +270,16 @@ export function HomeProvider({ children }: { children: ReactNode }) { const totalPosts = statusCounts.reduce((sum, s) => sum + s.count, 0); return [ - { count: totalPosts, label: m.curly_many_badger(), value: "all" }, + { + count: totalPosts, + kind: "all" as const, + label: m.curly_many_badger(), + value: "all", + }, ...statuses.map((status) => ({ count: countMap.get(status.id) ?? 0, icon: status.icon, + kind: "status" as const, label: status.label || formatPostStatus(status.type), statusType: status.type, value: status.id, @@ -298,10 +304,16 @@ export function HomeProvider({ children }: { children: ReactNode }) { const totalPosts = boardCounts.reduce((sum, b) => sum + b.count, 0); return [ - { count: totalPosts, label: m.spry_male_nils(), value: "all" }, + { + count: totalPosts, + kind: "all" as const, + label: m.spry_male_nils(), + value: "all", + }, ...boards.map((board) => ({ count: countMap.get(board.slug) ?? 0, icon: board.icon, + kind: "board" as const, label: board.name, value: board.slug, })), diff --git a/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx b/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx index 9aab96d3..08c5350d 100644 --- a/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx +++ b/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx @@ -83,9 +83,10 @@ function RenameBoardFormFields({ board }: { board: RenameBoardRow }) { const store = useRenameBoardDialogContext(); const boardId = useSelector(store, (state) => state.context.data.boardId); const navigate = useNavigate(); - // Captured when the sheet opened: a refetch can change the row under the - // form, and a save must compare against the value the editor started with. - const initialIcon = useRef(board.icon); + // Whether the picker was used, not whether the value differs from the row: + // a refetch can change the row under the form, and an untouched icon must be + // omitted rather than written back from a stale form value. + const iconTouched = useRef(false); const form = useAppForm({ ...boardFormOpts, @@ -102,11 +103,6 @@ function RenameBoardFormFields({ board }: { board: RenameBoardRow }) { const visibilityIsDirty = formApi.getFieldMeta("visibility")?.isDirty ?? false; - // Compare with the value the sheet opened with, not `isDirty`: the - // form's defaults can be replaced by a refetch, and a save that only - // changed one field must not repoint the others. - const iconChanged = value.icon !== initialIcon.current; - const tx = boardCollection.update(boardId, (draft) => { if (nameIsDirty) { draft.name = value.name; @@ -117,7 +113,7 @@ function RenameBoardFormFields({ board }: { board: RenameBoardRow }) { draft.visibility = value.visibility; } - if (iconChanged) { + if (iconTouched.current) { draft.icon = value.icon; } }); @@ -166,7 +162,10 @@ function RenameBoardFormFields({ board }: { board: RenameBoardRow }) { field.handleChange(icon)} + onChange={(icon) => { + iconTouched.current = true; + field.handleChange(icon); + }} value={field.state.value} /> )} diff --git a/apps/web/src/dashboard/features/dashboard-home/components/recent-posts-section.tsx b/apps/web/src/dashboard/features/dashboard-home/components/recent-posts-section.tsx index 32770dff..7ed11028 100644 --- a/apps/web/src/dashboard/features/dashboard-home/components/recent-posts-section.tsx +++ b/apps/web/src/dashboard/features/dashboard-home/components/recent-posts-section.tsx @@ -1,4 +1,5 @@ -import type { TPostStatusType } from "@feeblo/domain/post-status/schema"; +import type { TBoard } from "@feeblo/domain/board/schema"; +import type { TPostStatus } from "@feeblo/domain/post-status/schema"; import { formatPostStatus } from "@feeblo/post-ui/post-status"; import { PostCard } from "@feeblo/post-ui/post/post-card"; import { StandaloneUpvoteButton } from "@feeblo/post-ui/upvote-toggle"; @@ -39,20 +40,9 @@ interface Post { } | null; } -interface Board { - icon: string | null; - id: string; - name: string; - slug: string; -} +type Board = Pick; -interface Status { - color?: string | null; - icon: string | null; - id: string; - label: string; - type: TPostStatusType; -} +type Status = Pick; interface RecentPostsSectionProps { organizationId: string; diff --git a/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx b/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx index f7b29526..6e2350da 100644 --- a/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx +++ b/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx @@ -85,9 +85,9 @@ type EditableStatus = Pick & { function PostStatusEditForm({ status }: { status: EditableStatus }) { const { postStatusCollection } = useDashboardCollections(); const store = usePostStatusEditDialogContext(); - // The value the form opened with; a save that only renamed the status must - // not repoint its icon at a concurrent change. - const initialIcon = useRef(status.icon); + // Whether the picker was used; an untouched icon is omitted, and selecting + // the current section's default is stored as null rather than a name. + const iconTouched = useRef(false); const form = useAppForm({ defaultValues: { @@ -126,14 +126,12 @@ function PostStatusEditForm({ status }: { status: EditableStatus }) { ) + 1 : undefined; - const iconChanged = data.value.icon !== initialIcon.current; - const tx = postStatusCollection.update(status.id, (draft) => { draft.color = data.value.color; draft.label = data.value.label; draft.type = data.value.type; - if (iconChanged) { + if (iconTouched.current) { draft.icon = data.value.icon; } @@ -191,7 +189,10 @@ function PostStatusEditForm({ status }: { status: EditableStatus }) { field.handleChange(icon)} + onChange={(icon) => { + iconTouched.current = true; + field.handleChange(icon); + }} value={field.state.value} /> diff --git a/apps/web/src/dashboard/features/roadmap/components/roadmap-board.tsx b/apps/web/src/dashboard/features/roadmap/components/roadmap-board.tsx index 32a2f62c..21fbc3b1 100644 --- a/apps/web/src/dashboard/features/roadmap/components/roadmap-board.tsx +++ b/apps/web/src/dashboard/features/roadmap/components/roadmap-board.tsx @@ -136,8 +136,8 @@ export function RoadmapBoard({ lanes, organizationId }: RoadmapBoardProps) { // SAFETY: The runtime invariant checked by the surrounding code guarantees this type. const targetStatusId = - dragPreview?.targetStatusId ?? dragState?.targetStatusId ?? + dragPreview?.targetStatusId ?? (target?.data?.statusId as string | undefined); if ( diff --git a/packages/post-ui/src/forms/post-create-form-shared.tsx b/packages/post-ui/src/forms/post-create-form-shared.tsx index 9e3f5f19..660a8c6c 100644 --- a/packages/post-ui/src/forms/post-create-form-shared.tsx +++ b/packages/post-ui/src/forms/post-create-form-shared.tsx @@ -14,7 +14,11 @@ import { z } from "zod"; import { emptyOnBehalfAuthor } from "../contact-combobox/contact-combobox"; import { m } from "../paraglide/messages.js"; -import { PostBoardSelect, StatusField } from "../post-field"; +import { + PostBoardSelect, + type PostBoardSelectProps, + StatusField, +} from "../post-field"; import { PostTitleInput } from "../post-title-input"; import { usePostCollections } from "../providers/post-collections-provider"; @@ -184,7 +188,7 @@ export const PostBoardField = withForm({ props: { // SAFETY: [] satisfies the boards contract; consumers always provide the // real board list when mounting the field. - boards: [] as Array<{ icon?: string | null; id: string; name: string }>, + boards: [] as PostBoardSelectProps["boards"], }, render: ({ form, boards }) => { return ( diff --git a/packages/post-ui/src/post-field.tsx b/packages/post-ui/src/post-field.tsx index b89a1b27..21981feb 100644 --- a/packages/post-ui/src/post-field.tsx +++ b/packages/post-ui/src/post-field.tsx @@ -187,7 +187,7 @@ export function StatusField({ ); } -type PostBoardSelectProps = { +export type PostBoardSelectProps = { boards: { icon?: string | null; id: string; name: string }[]; currentBoardId: string; onValueChange: (boardId: string | null) => void; diff --git a/packages/ui/src/icon-picker/index.tsx b/packages/ui/src/icon-picker/index.tsx index 2ebc92f3..8f0d1cbb 100644 --- a/packages/ui/src/icon-picker/index.tsx +++ b/packages/ui/src/icon-picker/index.tsx @@ -1582,10 +1582,18 @@ function IconPickerField({ {label} - + { - onChange(icon.name); + // Selecting the entity default is the same "no override" state as + // "Use default"; storing the catalogue name would make it look + // like a custom choice after the default artwork changes. + onChange(icon.name === fallbackIcon ? null : icon.name); setOpen(false); }} value={selected} diff --git a/packages/ui/src/icon-picker/sprite.ts b/packages/ui/src/icon-picker/sprite.ts index 84aa0523..07d59119 100644 --- a/packages/ui/src/icon-picker/sprite.ts +++ b/packages/ui/src/icon-picker/sprite.ts @@ -5,15 +5,13 @@ import type { IconPickerSpriteStatus } from "./types"; /** * The generated sprite as a Vite asset. * - * `new URL(..., import.meta.url)` is resolved at build time into one emitted - * file, the same as a `?url` import, and it keeps the asset's type out of the - * package's ambient declarations: a consumer that imports the picker would - * otherwise need the `*.svg?url` declaration in its own program. + * Resolved lazily rather than at module scope: this module can be evaluated on + * the server, where `import.meta.url` is a file URL rather than a served + * asset. Vite still turns the static `new URL` into an emitted asset URL. */ -const spriteUrl = new URL( - "./generated/tabler-filled-sprite.svg", - import.meta.url -).href; +function getSpriteUrl(): string { + return new URL("./generated/tabler-filled-sprite.svg", import.meta.url).href; +} const SPRITE_ATTRIBUTE = "data-icon-picker-sprite"; @@ -98,7 +96,7 @@ export function loadIconPickerSprite(): Promise { setStatus("loading"); - spriteState.loadPromise = fetch(spriteUrl) + spriteState.loadPromise = fetch(getSpriteUrl()) .then((response) => { if (!response.ok) { throw new Error(