mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
8fd46c4c18
Small requests from the discussions, each built end to end: planner and map (cycling mode, date first headings, clear a day, stay times per day, off-route stops, map lock, compact unplanned markers, pending stays, cable car, transit quick picks), places (location filter, category from OSM, open in maps, geo: link, image from an attachment, enrichment on file import, places near a pin, place name language, Amap first in China), lists and costs (packed counter, inherited sharing, Markdown to-dos, payment notes, bookings CSV, my plan PDF), sharing (unplanned places, travel only, without photos), journey (photo zoom, drafts, photo order, trip suggestion, day jump), atlas (region counter, region bucket list, places per country), vacay half company holidays, studio copy and paste plus the book's own layouts, and RESTORE_FROM_BACKUP for a first start restore.
172 lines
7.4 KiB
TypeScript
172 lines
7.4 KiB
TypeScript
import { useState } from 'react'
|
|
import { Flag, ListPlus, Plus, User } from 'lucide-react'
|
|
import { useTranslation } from '../../i18n'
|
|
import { avatarSrc } from '../../utils/avatarSrc'
|
|
import CustomSelect from '../shared/CustomSelect'
|
|
import { CustomDatePicker } from '../shared/CustomDateTimePicker'
|
|
import NameDialog from '../shared/NameDialog'
|
|
import { Tooltip } from '../shared/Tooltip'
|
|
import MarkdownEditable from '../shared/MarkdownEditable'
|
|
import { GRID_2, LABEL, TEXTAREA } from '../shared/dialogParts'
|
|
import { PRIO_CONFIG, katColor, taskInputStyle, taskLabelClass, type Member, type TaskFieldValues } from './todoListModel'
|
|
|
|
interface TodoTaskFieldsProps {
|
|
values: TaskFieldValues
|
|
onChange: (patch: Partial<TaskFieldValues>) => void
|
|
categories: string[]
|
|
members: Member[]
|
|
canEdit?: boolean
|
|
/** 'dialog' draws the fields like the planner's dialogs: small caps labels, list and due date side by side. */
|
|
variant?: 'pane' | 'dialog'
|
|
}
|
|
|
|
/**
|
|
* The fields a task is made of, shared by the detail pane and the new-task
|
|
* dialog so both read and behave the same: description, priority as one
|
|
* segmented track, the list (a new one is named in a dialog), the due date and
|
|
* who does it.
|
|
*/
|
|
export default function TodoTaskFields({ values, onChange, categories, members, canEdit = true, variant = 'pane' }: TodoTaskFieldsProps) {
|
|
const { t } = useTranslation()
|
|
const [namingList, setNamingList] = useState(false)
|
|
const [listName, setListName] = useState('')
|
|
const { desc, priority, category, dueDate, assignedUserId } = values
|
|
const dialog = variant === 'dialog'
|
|
const labelClass = dialog ? LABEL : taskLabelClass
|
|
|
|
const confirmList = () => {
|
|
const name = listName.trim()
|
|
if (!name) return
|
|
onChange({ category: name })
|
|
setNamingList(false)
|
|
setListName('')
|
|
}
|
|
|
|
const listField = (
|
|
<div>
|
|
<label className={labelClass}>{t('todo.detail.category')}</label>
|
|
<div style={{ display: 'flex', gap: 6 }}>
|
|
<div style={{ flex: 1, minWidth: 0 }}>
|
|
<CustomSelect
|
|
value={category}
|
|
onChange={v => onChange({ category: String(v) })}
|
|
options={[
|
|
{ value: '', label: t('todo.noCategory') },
|
|
...categories.map(c => ({
|
|
value: c, label: c,
|
|
icon: <span style={{ width: 8, height: 8, borderRadius: '50%', background: katColor(c, categories), display: 'inline-block' }} />,
|
|
})),
|
|
...(category && !categories.includes(category) ? [{
|
|
value: category, label: `${category} (${t('todo.newCategoryLabel')})`,
|
|
icon: <span style={{ width: 8, height: 8, borderRadius: '50%', background: katColor(category, categories), display: 'inline-block' }} />,
|
|
}] : []),
|
|
]}
|
|
placeholder={t('todo.noCategory')}
|
|
size="sm"
|
|
disabled={!canEdit}
|
|
/>
|
|
</div>
|
|
{canEdit && (
|
|
<Tooltip label={t('todo.addCategory')}>
|
|
<button type="button" onClick={() => setNamingList(true)} aria-label={t('todo.addCategory')}
|
|
style={{ width: 36, flexShrink: 0, background: 'var(--bg-tertiary)', border: 'none', borderRadius: 10, cursor: 'pointer', color: 'var(--text-muted)', display: 'grid', placeItems: 'center' }}>
|
|
<Plus size={14} />
|
|
</button>
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
|
|
const dueField = (
|
|
<div>
|
|
<label className={labelClass}>{t('todo.detail.dueDate')}</label>
|
|
<CustomDatePicker value={dueDate} onChange={v => onChange({ dueDate: v })} />
|
|
</div>
|
|
)
|
|
|
|
return (
|
|
<>
|
|
<div>
|
|
<label className={labelClass}>{t('todo.detail.description')}</label>
|
|
{dialog ? (
|
|
<textarea value={desc} onChange={e => onChange({ desc: e.target.value })} disabled={!canEdit} rows={3}
|
|
placeholder={t('todo.descriptionPlaceholder')} className={TEXTAREA} />
|
|
) : (
|
|
<MarkdownEditable value={desc} canEdit={canEdit} editLabel={t('todo.editDescription')}
|
|
className="text-content-secondary"
|
|
style={{ ...taskInputStyle, minHeight: 84, lineHeight: 1.5, overflowWrap: 'break-word' }}
|
|
renderEditor={editor => (
|
|
<textarea value={desc} onChange={e => onChange({ desc: e.target.value })} rows={4} {...editor}
|
|
placeholder={t('todo.descriptionPlaceholder')}
|
|
style={{ ...taskInputStyle, resize: 'vertical', minHeight: 84 }} />
|
|
)} />
|
|
)}
|
|
</div>
|
|
|
|
<div>
|
|
<label className={labelClass}>{t('todo.detail.priority')}</label>
|
|
<div style={{ display: 'flex', gap: 2, padding: 3, borderRadius: 11, background: 'var(--bg-tertiary)' }}>
|
|
{[0, 1, 2, 3].map(p => {
|
|
const cfg = PRIO_CONFIG[p]
|
|
const isActive = priority === p
|
|
return (
|
|
<button type="button" key={p} onClick={() => canEdit && onChange({ priority: p })} aria-pressed={isActive}
|
|
style={{
|
|
flex: 1, height: 28, borderRadius: 8, border: 'none', cursor: canEdit ? 'pointer' : 'default',
|
|
fontSize: 'calc(11.5px * var(--fs-scale-caption, 1))', fontWeight: 600, fontFamily: 'inherit',
|
|
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 4,
|
|
background: isActive ? 'var(--bg-card)' : 'transparent',
|
|
boxShadow: isActive ? '0 1px 2px rgba(0,0,0,0.1)' : 'none',
|
|
color: isActive ? (cfg ? cfg.color : 'var(--text-primary)') : 'var(--text-faint)',
|
|
transition: 'all 0.12s',
|
|
}}>
|
|
{cfg ? <><Flag size={10} />{cfg.label}</> : t('todo.detail.noPriority')}
|
|
</button>
|
|
)
|
|
})}
|
|
</div>
|
|
</div>
|
|
|
|
{dialog ? <div className={GRID_2}>{listField}{dueField}</div> : <>{listField}{dueField}</>}
|
|
|
|
<div>
|
|
<label className={labelClass}>{t('todo.detail.assignedTo')}</label>
|
|
<CustomSelect
|
|
value={String(assignedUserId ?? '')}
|
|
onChange={v => onChange({ assignedUserId: v ? Number(v) : null })}
|
|
options={[
|
|
{ value: '', label: t('todo.unassigned'), icon: <User size={14} className="text-content-faint" /> },
|
|
...members.map(m => ({
|
|
value: String(m.id),
|
|
label: m.is_guest ? `${m.username} · ${t('members.guest')}` : m.username,
|
|
icon: m.avatar ? (
|
|
<img src={avatarSrc(m.avatar)!} style={{ width: 18, height: 18, borderRadius: '50%', objectFit: 'cover' as const }} alt="" />
|
|
) : (
|
|
<span style={{ width: 18, height: 18, borderRadius: '50%', background: 'var(--bg-tertiary)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontSize: 'calc(10px * var(--fs-scale-caption, 1))', color: 'var(--text-muted)', fontWeight: 700 }}>
|
|
{m.username.charAt(0).toUpperCase()}
|
|
</span>
|
|
),
|
|
})),
|
|
]}
|
|
placeholder={t('todo.unassigned')}
|
|
size="sm"
|
|
disabled={!canEdit}
|
|
/>
|
|
</div>
|
|
|
|
<NameDialog
|
|
open={namingList}
|
|
title={t('todo.addCategory')}
|
|
icon={ListPlus}
|
|
placeholder={t('todo.newCategory')}
|
|
confirmLabel={t('common.add')}
|
|
value={listName}
|
|
onChange={setListName}
|
|
onConfirm={confirmList}
|
|
onClose={() => { setNamingList(false); setListName('') }}
|
|
/>
|
|
</>
|
|
)
|
|
}
|