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 @@ -34,9 +34,9 @@ export function HomeBoardSelect({ className }: { className?: string }) {

return item ? (
<span className="flex items-center gap-2">
{item.icon === undefined ? null : (
{item.kind === "board" ? (
<TablerIcon name={boardIconName(item.icon)} />
)}
) : null}
{item.label}
</span>
) : null;
Expand All @@ -47,9 +47,9 @@ export function HomeBoardSelect({ className }: { className?: string }) {
{boardItems.map((item) => (
<SelectItem key={item.value} value={item.value}>
<span className="flex items-center gap-2">
{item.icon === undefined ? null : (
{item.kind === "board" ? (
<TablerIcon name={boardIconName(item.icon)} />
)}
) : null}
{item.label}
</span>
</SelectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function HomeStatusMenu({ className }: { className?: string }) {
{statusItems.map((item) => (
<MenuRadioItem closeOnClick key={item.value} value={item.value}>
<span className="flex items-center gap-2">
{item.statusType ? (
{item.kind === "status" ? (
<PostStatusIcon icon={item.icon} type={item.statusType} />
) : null}
{item.label}
Expand Down
19 changes: 14 additions & 5 deletions apps/public-feature-board/src/features/home/home-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 14 additions & 2 deletions apps/public-feature-board/src/features/home/home-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -117,7 +113,7 @@ function RenameBoardFormFields({ board }: { board: RenameBoardRow }) {
draft.visibility = value.visibility;
}

if (iconChanged) {
if (iconTouched.current) {
draft.icon = value.icon;
}
});
Expand Down Expand Up @@ -166,7 +162,10 @@ function RenameBoardFormFields({ board }: { board: RenameBoardRow }) {
<IconPickerField
fallbackIcon={DEFAULT_BOARD_ICON}
label="Choose icon"
onChange={(icon) => field.handleChange(icon)}
onChange={(icon) => {
iconTouched.current = true;
field.handleChange(icon);
}}
value={field.state.value}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -39,20 +40,9 @@ interface Post {
} | null;
}

interface Board {
icon: string | null;
id: string;
name: string;
slug: string;
}
type Board = Pick<TBoard, "icon" | "id" | "name" | "slug">;

interface Status {
color?: string | null;
icon: string | null;
id: string;
label: string;
type: TPostStatusType;
}
type Status = Pick<TPostStatus, "color" | "icon" | "id" | "label" | "type">;

interface RecentPostsSectionProps {
organizationId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ type EditableStatus = Pick<TPostStatus, "icon" | "id" | "label" | "type"> & {
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: {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -191,7 +189,10 @@ function PostStatusEditForm({ status }: { status: EditableStatus }) {
<IconPickerField
fallbackIcon={DEFAULT_POST_STATUS_ICONS[type]}
label="Choose icon"
onChange={(icon) => field.handleChange(icon)}
onChange={(icon) => {
iconTouched.current = true;
field.handleChange(icon);
}}
value={field.state.value}
/>
</Field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 6 additions & 2 deletions packages/post-ui/src/forms/post-create-form-shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion packages/post-ui/src/post-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions packages/ui/src/icon-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1582,10 +1582,18 @@ function IconPickerField({
<TablerIcon name={selected} />
<span>{label}</span>
</PopoverTrigger>
<PopoverPopup align="start" className="w-auto p-2" sideOffset={6}>
<PopoverPopup
align="start"
aria-label={label}
className="w-auto p-2"
sideOffset={6}
>
<IconPickerContent
onIconSelect={(icon) => {
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}
Expand Down
16 changes: 7 additions & 9 deletions packages/ui/src/icon-picker/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -98,7 +96,7 @@ export function loadIconPickerSprite(): Promise<void> {

setStatus("loading");

spriteState.loadPromise = fetch(spriteUrl)
spriteState.loadPromise = fetch(getSpriteUrl())
.then((response) => {
if (!response.ok) {
throw new Error(
Expand Down
Loading