From 8729fe48c382f77ec9b2f88523ff1752c3e07b02 Mon Sep 17 00:00:00 2001 From: Adorian Doran Date: Tue, 18 Nov 2025 01:09:22 +0200 Subject: [PATCH] client/note color picker menu item: add support to operate with note IDs as well --- .../custom-items/ColorPickerMenuItem.css | 4 ++ .../custom-items/ColorPickerMenuItem.tsx | 40 ++++++++++++++----- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/apps/client/src/menus/custom-items/ColorPickerMenuItem.css b/apps/client/src/menus/custom-items/ColorPickerMenuItem.css index 205ac9a29..1f56926a9 100644 --- a/apps/client/src/menus/custom-items/ColorPickerMenuItem.css +++ b/apps/client/src/menus/custom-items/ColorPickerMenuItem.css @@ -10,6 +10,10 @@ background: transparent; } +.color-picker-menu-item > .color-cell.disabled-color-cell { + cursor: not-allowed; +} + .color-picker-menu-item > .color-cell.selected { outline: 2px solid royalblue; } \ No newline at end of file diff --git a/apps/client/src/menus/custom-items/ColorPickerMenuItem.tsx b/apps/client/src/menus/custom-items/ColorPickerMenuItem.tsx index d9b9a3d41..11ca42c48 100644 --- a/apps/client/src/menus/custom-items/ColorPickerMenuItem.tsx +++ b/apps/client/src/menus/custom-items/ColorPickerMenuItem.tsx @@ -1,23 +1,44 @@ import "./ColorPickerMenuItem.css"; -import { useState } from "preact/hooks"; +import { useEffect, useState } from "preact/hooks"; import attributes from "../../services/attributes"; import FNote from "../../entities/fnote"; +import froca from "../../services/froca"; const COLORS = ["blue", "green", "cyan", "red", "magenta", "brown", "yellow", ""]; export interface ColorPickerMenuItemProps { - note: FNote | null; + /** The target Note instance or its ID string. */ + note: FNote | string | null; } export default function ColorPickerMenuItem(props: ColorPickerMenuItemProps) { - const {note} = props; - if (!note) return null; + if (!props.note) return null; - const [currentColor, setCurrentColor] = useState(note.getLabel("color")?.value ?? ""); + const [note, setNote] = useState(null); + const [currentColor, setCurrentColor] = useState(null); + + + useEffect(() => { + const retrieveNote = async (noteId: string) => { + const result = await froca.getNote(noteId, true); + if (result) { + setNote(result); + setCurrentColor(result.getLabel("color")?.value ?? ""); + } + } + + if (typeof props.note === "string") { + retrieveNote(props.note); // Get the note from the given ID string + } else { + setNote(props.note); + } + }, []); const onColorCellClicked = (color: string) => { - attributes.setLabel(note.noteId, "color", color); - setCurrentColor(color); + if (note) { + attributes.setLabel(note.noteId, "color", color); + setCurrentColor(color); + } } return
@@ -25,13 +46,14 @@ export default function ColorPickerMenuItem(props: ColorPickerMenuItemProps) { onColorCellClicked(color)} /> ))}
} -function ColorCell(props: {color: string, isSelected: boolean, onClick?: () => void}) { - return
void}) { + return
;