feat(places): colour tags, tabs for the texts and opening hours on the phone

Tags on the place form are pills in their own colour, with a palette under
the dot that recolours a tag for the whole trip (PUT /trips/:id/tags/:id was
there already, the client now reaches it through repo and store) and a
custom colour field of its own instead of the system picker. A new tag is
made in a colour picked the same way.

Description, notes and the note for one day's visit sit in one card under a
switch, each with a line on where the text shows up; the day tab is named
after its day and is only there with one visit in context. Nothing about the
three fields changes underneath.

Opening hours get a switch for open around the clock next to closed. Google
writes a place open all week as one period on Sunday that never closes; it
read as Sunday open and every other day closed, and now opens every day.

The phone form follows the desktop: category as one field with a list, tags
in one field, the texts switch, and phone, e-mail and opening hours, which it
did not have. The hours and the text tabs are shared hooks (usePlaceHours,
usePlaceTextTabs). Files and costs on the phone sheets are drawn as fields
like the rest, and the paste hint, a keyboard shortcut a phone has no use
for, is gone with its key.
This commit is contained in:
Maurice
2026-11-17 08:44:05 +01:00
parent 33d074c786
commit a3f6635633
100 changed files with 2538 additions and 510 deletions
+32
View File
@@ -0,0 +1,32 @@
// FE-UTIL-COLORSPACE-001 to FE-UTIL-COLORSPACE-003
import { describe, expect, it } from 'vitest';
import { hexToHsv, hsvToHex, hueHex, normalizeHex } from './colorSpace';
describe('colorSpace', () => {
it('FE-UTIL-COLORSPACE-001: reads a typed colour in the forms people type it, and nothing else', () => {
expect(normalizeHex('#ABCDEF')).toBe('#abcdef');
expect(normalizeHex('abcdef')).toBe('#abcdef');
expect(normalizeHex(' #f0a ')).toBe('#ff00aa');
expect(normalizeHex('#abcd')).toBeNull();
expect(normalizeHex('red')).toBeNull();
expect(normalizeHex('')).toBeNull();
});
it('FE-UTIL-COLORSPACE-002: hue, saturation and value of the primaries, grey and black', () => {
expect(hexToHsv('#ff0000')).toEqual({ h: 0, s: 1, v: 1 });
expect(hexToHsv('#00ff00')).toEqual({ h: 120, s: 1, v: 1 });
expect(hexToHsv('#0000ff')).toEqual({ h: 240, s: 1, v: 1 });
expect(hexToHsv('#808080')).toEqual({ h: 0, s: 0, v: 128 / 255 });
expect(hexToHsv('#000000')).toEqual({ h: 0, s: 0, v: 0 });
});
it('FE-UTIL-COLORSPACE-003: a colour survives the way there and back, and the hue alone is the pure one', () => {
for (const hex of ['#6366f1', '#ec4899', '#f97316', '#10b981', '#64748b', '#ffffff', '#000000']) {
expect(hsvToHex(hexToHsv(hex))).toBe(hex);
}
expect(hueHex(0)).toBe('#ff0000');
expect(hueHex(120)).toBe('#00ff00');
expect(hueHex(240)).toBe('#0000ff');
});
});
+52
View File
@@ -0,0 +1,52 @@
/**
* Hex colours to hue, saturation and value and back, for the colour field of
* the tag palette: the field picks saturation and value, the slider the hue.
*/
export interface Hsv {
/** 0 to 360. */
h: number;
/** 0 to 1. */
s: number;
/** 0 to 1. */
v: number;
}
const HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
/** A typed colour as lowercase #rrggbb, or null when it is not one. Accepts the short #rgb form and a missing #. */
export function normalizeHex(raw: string): string | null {
const m = HEX.exec(raw.trim());
if (!m) return null;
const digits = m[1].length === 3 ? [...m[1]].map((c) => c + c).join('') : m[1];
return `#${digits.toLowerCase()}`;
}
export function hexToHsv(hex: string): Hsv {
const norm = normalizeHex(hex) ?? '#000000';
const [r, g, b] = [1, 3, 5].map((i) => parseInt(norm.slice(i, i + 2), 16) / 255);
const max = Math.max(r, g, b);
const d = max - Math.min(r, g, b);
let h = 0;
if (d) {
if (max === r) h = ((g - b) / d) % 6;
else if (max === g) h = (b - r) / d + 2;
else h = (r - g) / d + 4;
}
return { h: (h * 60 + 360) % 360, s: max ? d / max : 0, v: max };
}
export function hsvToHex({ h, s, v }: Hsv): string {
const f = (n: number) => {
const k = (n + h / 60) % 6;
const c = v - v * s * Math.max(0, Math.min(k, 4 - k, 1));
return Math.round(c * 255)
.toString(16)
.padStart(2, '0');
};
return `#${f(5)}${f(3)}${f(1)}`;
}
/** The pure hue at full saturation and value, the colour the field fades from. */
export function hueHex(h: number): string {
return hsvToHex({ h, s: 1, v: 1 });
}
+10 -2
View File
@@ -1,7 +1,15 @@
import { describe, expect, it } from 'vitest';
import { buildPlace, buildTag } from '../../tests/helpers/factories';
import { nextTagColor, placeTagIds, tagChanges, tagChoices, withTagChanges, withTripTag } from './placeTags';
import {
TAG_COLORS,
nextTagColor,
placeTagIds,
tagChanges,
tagChoices,
withTagChanges,
withTripTag,
} from './placeTags';
describe('placeTags', () => {
it('FE-UTIL-PLTAGS-001: offers each tag once and by name, as the first list that has it says', () => {
@@ -46,7 +54,7 @@ describe('placeTags', () => {
expect(second).toMatch(/^#[0-9a-f]{6}$/);
expect(second).not.toBe(first);
// Past the last colour it starts over.
expect(nextTagColor(Array.from({ length: 8 }, () => buildTag()))).toBe(first);
expect(nextTagColor(Array.from({ length: TAG_COLORS.length }, () => buildTag()))).toBe(first);
});
it('FE-UTIL-PLTAGS-005: adds a tag to the list by name, and replaces the one of the same id', () => {
+13 -2
View File
@@ -33,11 +33,22 @@ export function placeTagIds(carried: readonly PlaceTag[] | undefined): number[]
}
// What a new tag is coloured with, one after the other, so the tags of a trip tell apart at a glance.
const NEW_TAG_COLORS = ['#6366f1', '#ec4899', '#f97316', '#10b981', '#06b6d4', '#8b5cf6', '#ef4444', '#f59e0b'];
export const TAG_COLORS = [
'#6366f1',
'#ec4899',
'#f97316',
'#10b981',
'#06b6d4',
'#8b5cf6',
'#ef4444',
'#f59e0b',
'#84cc16',
'#64748b',
];
/** The colour the next new tag of a trip gets. */
export function nextTagColor(tripTags: readonly unknown[]): string {
return NEW_TAG_COLORS[tripTags.length % NEW_TAG_COLORS.length];
return TAG_COLORS[tripTags.length % TAG_COLORS.length];
}
/** The trip's tags with one more, or with the one of that id as it is now, by name as the server lists them. */