mirror of
https://github.com/zadam/trilium.git
synced 2025-11-21 16:14:23 +01:00
client/note color picker menu item: add support to operate with note IDs as well
This commit is contained in:
parent
441c55eb31
commit
8729fe48c3
@ -10,6 +10,10 @@
|
|||||||
background: transparent;
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.color-picker-menu-item > .color-cell.disabled-color-cell {
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
.color-picker-menu-item > .color-cell.selected {
|
.color-picker-menu-item > .color-cell.selected {
|
||||||
outline: 2px solid royalblue;
|
outline: 2px solid royalblue;
|
||||||
}
|
}
|
||||||
@ -1,23 +1,44 @@
|
|||||||
import "./ColorPickerMenuItem.css";
|
import "./ColorPickerMenuItem.css";
|
||||||
import { useState } from "preact/hooks";
|
import { useEffect, useState } from "preact/hooks";
|
||||||
import attributes from "../../services/attributes";
|
import attributes from "../../services/attributes";
|
||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
|
import froca from "../../services/froca";
|
||||||
|
|
||||||
const COLORS = ["blue", "green", "cyan", "red", "magenta", "brown", "yellow", ""];
|
const COLORS = ["blue", "green", "cyan", "red", "magenta", "brown", "yellow", ""];
|
||||||
|
|
||||||
export interface ColorPickerMenuItemProps {
|
export interface ColorPickerMenuItemProps {
|
||||||
note: FNote | null;
|
/** The target Note instance or its ID string. */
|
||||||
|
note: FNote | string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ColorPickerMenuItem(props: ColorPickerMenuItemProps) {
|
export default function ColorPickerMenuItem(props: ColorPickerMenuItemProps) {
|
||||||
const {note} = props;
|
if (!props.note) return null;
|
||||||
if (!note) return null;
|
|
||||||
|
|
||||||
const [currentColor, setCurrentColor] = useState(note.getLabel("color")?.value ?? "");
|
const [note, setNote] = useState<FNote | null>(null);
|
||||||
|
const [currentColor, setCurrentColor] = useState<string | null>(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) => {
|
const onColorCellClicked = (color: string) => {
|
||||||
attributes.setLabel(note.noteId, "color", color);
|
if (note) {
|
||||||
setCurrentColor(color);
|
attributes.setLabel(note.noteId, "color", color);
|
||||||
|
setCurrentColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div className="color-picker-menu-item">
|
return <div className="color-picker-menu-item">
|
||||||
@ -25,13 +46,14 @@ export default function ColorPickerMenuItem(props: ColorPickerMenuItemProps) {
|
|||||||
<ColorCell key={color}
|
<ColorCell key={color}
|
||||||
color={color}
|
color={color}
|
||||||
isSelected={(color === currentColor)}
|
isSelected={(color === currentColor)}
|
||||||
|
isDisabled={(note !== null)}
|
||||||
onClick={() => onColorCellClicked(color)} />
|
onClick={() => onColorCellClicked(color)} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
function ColorCell(props: {color: string, isSelected: boolean, onClick?: () => void}) {
|
function ColorCell(props: {color: string, isSelected: boolean, isDisabled?: boolean, onClick?: () => void}) {
|
||||||
return <div class={`color-cell ${props.isSelected ? "selected" : ""}`}
|
return <div class={`color-cell ${props.isSelected ? "selected" : ""} ${props.isDisabled ? "disabled-color-cell" : ""}`}
|
||||||
style={`background-color: ${props.color}`}
|
style={`background-color: ${props.color}`}
|
||||||
onClick={props.onClick}>
|
onClick={props.onClick}>
|
||||||
</div>;
|
</div>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user