mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
refactor(planner): share the day note draft and save between desktop and phone
The desktop note dialog and the phone note sheet fill their editor with dayNoteDraft and save through writeDayNote, so both trim the title, store an empty detail as null and default the icon the same way. Both count the detail line against one shared limit.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// FE-PLANNER-NOTELIMIT-001: the detail limit both day note editors count against.
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { DAY_NOTE_DETAIL_MAX, dayNoteNearLimit } from './DayPlanSidebar.constants';
|
||||
|
||||
describe('day note detail limit', () => {
|
||||
it('FE-PLANNER-NOTELIMIT-001: the counter warns from a hundred characters before the limit', () => {
|
||||
expect(DAY_NOTE_DETAIL_MAX).toBe(2000);
|
||||
expect(dayNoteNearLimit(1899)).toBe(false);
|
||||
expect(dayNoteNearLimit(1900)).toBe(true);
|
||||
expect(dayNoteNearLimit(2000)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -44,6 +44,12 @@ export const NOTE_ICONS = [
|
||||
const NOTE_ICON_MAP = Object.fromEntries(NOTE_ICONS.map(({ id, Icon }) => [id, Icon]))
|
||||
export function getNoteIcon(iconId) { return NOTE_ICON_MAP[iconId] || FileText }
|
||||
|
||||
/** The most a day note's detail line may hold, in the desktop dialog and the phone sheet alike. */
|
||||
export const DAY_NOTE_DETAIL_MAX = 2000
|
||||
|
||||
/** Whether a detail line is close enough to the limit for the counter to warn. */
|
||||
export const dayNoteNearLimit = (length: number): boolean => length >= DAY_NOTE_DETAIL_MAX - 100
|
||||
|
||||
export const TYPE_ICONS = {
|
||||
flight: '✈️', hotel: '🏨', restaurant: '🍽️', train: '🚆',
|
||||
car: '🚗', cruise: '🚢', bus: '🚌', ferry: '⛴️', cable_car: '🚡', bicycle: '🚲', taxi: '🚕',
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useId, useRef } from 'react'
|
||||
import Markdown from 'react-markdown'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import remarkBreaks from 'remark-breaks'
|
||||
import { NOTE_ICONS, getNoteIcon } from './DayPlanSidebar.constants'
|
||||
import { DAY_NOTE_DETAIL_MAX, NOTE_ICONS, dayNoteNearLimit, getNoteIcon } from './DayPlanSidebar.constants'
|
||||
import NoteFormatToolbar from '../shared/NoteFormatToolbar'
|
||||
import NoteColorPicker from '../shared/NoteColorPicker'
|
||||
import { noteSurface } from './noteSurface'
|
||||
@@ -42,8 +42,6 @@ interface DayPlanSidebarNoteModalProps {
|
||||
|
||||
type NoteDialogProps = Omit<DayPlanSidebarNoteModalProps, 'noteUi' | 'noteInputRef'> & { dayId: string; ui: NoteModalUi | undefined }
|
||||
|
||||
const BODY_MAX = 2000
|
||||
|
||||
/**
|
||||
* Add/edit dialog for a day note (#1629), one per day whose note is open.
|
||||
*
|
||||
@@ -166,7 +164,7 @@ function OpenNoteDialog({ dayId, ui, setNoteUi, cancelNote, saveNote, onRequestD
|
||||
id={bodyId}
|
||||
ref={bodyRef}
|
||||
value={ui.time}
|
||||
maxLength={BODY_MAX}
|
||||
maxLength={DAY_NOTE_DETAIL_MAX}
|
||||
rows={6}
|
||||
onChange={e => patch({ time: e.target.value })}
|
||||
placeholder={t('notes.bodyPlaceholder')}
|
||||
@@ -174,7 +172,7 @@ function OpenNoteDialog({ dayId, ui, setNoteUi, cancelNote, saveNote, onRequestD
|
||||
/>
|
||||
<div className="mt-1 flex justify-between gap-2" style={fs(10.5)}>
|
||||
<span className="text-content-faint">{t('notes.markdownHint')}</span>
|
||||
<span className={`tabular-nums ${bodyLen >= BODY_MAX - 100 ? 'text-warning' : 'text-content-faint'}`}>{bodyLen}/{BODY_MAX}</span>
|
||||
<span className={`tabular-nums ${dayNoteNearLimit(bodyLen) ? 'text-warning' : 'text-content-faint'}`}>{bodyLen}/{DAY_NOTE_DETAIL_MAX}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user