mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
feat: quality of life sweep from the feature discussions
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.
This commit is contained in:
@@ -8,6 +8,7 @@ import { tripsApi } from '../../api/client'
|
||||
import VacayMonthCard from './VacayMonthCard'
|
||||
import type { VacayEntry } from '../../types'
|
||||
import { Building2, MousePointer2 } from 'lucide-react'
|
||||
import { companyHolidaySets, leaveFractionFor } from './companyHolidays'
|
||||
|
||||
type VacayMode = 'vacation' | 'company'
|
||||
type HoverTip = { date: string; top: number; left: number }
|
||||
@@ -51,11 +52,8 @@ export default function VacayCalendar() {
|
||||
return () => { cancelled = true }
|
||||
}, [selectedYear, yearSettings])
|
||||
|
||||
const companyHolidaySet = useMemo(() => {
|
||||
const s = new Set<string>()
|
||||
companyHolidays.forEach(h => s.add(h.date))
|
||||
return s
|
||||
}, [companyHolidays])
|
||||
// Whole company holidays close a day to leave, half ones leave half of it (#2439).
|
||||
const { full: companyHolidaySet, half: companyHalfSet } = useMemo(() => companyHolidaySets(companyHolidays), [companyHolidays])
|
||||
|
||||
const entryMap = useMemo(() => {
|
||||
const map: Record<string, VacayEntry[]> = {}
|
||||
@@ -91,7 +89,7 @@ export default function VacayCalendar() {
|
||||
const handleCellClick = useCallback(async (dateStr: string) => {
|
||||
if (mode === 'company') {
|
||||
if (!companyHolidaysEnabled) return
|
||||
await toggleCompanyHoliday(dateStr)
|
||||
await toggleCompanyHoliday(dateStr, halfDay ? 0.5 : 1)
|
||||
return
|
||||
}
|
||||
if (blockWeekends && isWeekend(dateStr, weekendDays)) {
|
||||
@@ -105,8 +103,9 @@ export default function VacayCalendar() {
|
||||
return
|
||||
}
|
||||
if (companyHolidaysEnabled && companyHolidaySet.has(dateStr)) return
|
||||
await toggleEntry(dateStr, selectedUserId || undefined, halfDay ? 0.5 : 1, compDay ? 'comp' : 'vacation')
|
||||
}, [mode, halfDay, compDay, toggleEntry, toggleCompanyHoliday, companyHolidaySet, blockWeekends, weekendDays, companyHolidaysEnabled, selectedUserId, currentUserId, entryMap])
|
||||
const fraction = companyHolidaysEnabled ? leaveFractionFor(dateStr, companyHalfSet, halfDay ? 0.5 : 1) : (halfDay ? 0.5 : 1)
|
||||
await toggleEntry(dateStr, selectedUserId || undefined, fraction, compDay ? 'comp' : 'vacation')
|
||||
}, [mode, halfDay, compDay, toggleEntry, toggleCompanyHoliday, companyHolidaySet, companyHalfSet, blockWeekends, weekendDays, companyHolidaysEnabled, selectedUserId, currentUserId, entryMap])
|
||||
|
||||
// Cells with a half day or a shared overlay report a hover, so the tooltip
|
||||
// appears exactly when there's something to explain. Fixed-positioned at the
|
||||
@@ -146,6 +145,7 @@ export default function VacayCalendar() {
|
||||
month={month}
|
||||
holidays={holidays}
|
||||
companyHolidaySet={companyHolidaySet}
|
||||
companyHalfSet={companyHalfSet}
|
||||
companyHolidaysEnabled={companyHolidaysEnabled}
|
||||
entryMap={entryMap}
|
||||
sharedMap={sharedMap}
|
||||
|
||||
@@ -10,6 +10,8 @@ interface VacayMonthCardProps {
|
||||
month: number
|
||||
holidays: HolidaysMap
|
||||
companyHolidaySet: Set<string>
|
||||
/** Half company holidays (#2439): shown half-filled, and still open for half a day of leave. */
|
||||
companyHalfSet?: Set<string>
|
||||
companyHolidaysEnabled?: boolean
|
||||
entryMap: Record<string, VacayEntry[]>
|
||||
// Shared read-only calendars per date (#444/#667) — rendered as rings, not fills.
|
||||
@@ -24,7 +26,7 @@ interface VacayMonthCardProps {
|
||||
}
|
||||
|
||||
export default function VacayMonthCard({
|
||||
year, month, holidays, companyHolidaySet, companyHolidaysEnabled = true, entryMap, sharedMap,
|
||||
year, month, holidays, companyHolidaySet, companyHalfSet, companyHolidaysEnabled = true, entryMap, sharedMap,
|
||||
onCellClick, onCellHover, companyMode, blockWeekends, weekendDays = [0, 6], tripDates, weekStart = 1
|
||||
}: VacayMonthCardProps) {
|
||||
const { t, locale } = useTranslation()
|
||||
@@ -106,13 +108,14 @@ export default function VacayMonthCard({
|
||||
const publicHoliday = holidayMarkers.find(h => (h.type ?? 'public_holiday') === 'public_holiday')
|
||||
const schoolHolidayMarkers = holidayMarkers.filter(h => h.type === 'school_holiday')
|
||||
const isCompany = companyHolidaysEnabled && companyHolidaySet.has(dateStr)
|
||||
const isHalfCompany = companyHolidaysEnabled && !!companyHalfSet?.has(dateStr)
|
||||
const dayEntries = entryMap[dateStr] || []
|
||||
const hasEntries = dayEntries.length > 0
|
||||
// A blocked weekend day that still carries an entry (#1897) stays clickable —
|
||||
// the click clears the stranded day rather than logging a new one.
|
||||
const isBlocked = (weekend && blockWeekends && !hasEntries) || (isCompany && !companyMode)
|
||||
const isToday = dateStr === todayStr
|
||||
const plain = !hasEntries && holidayMarkers.length === 0 && !isCompany
|
||||
const plain = !hasEntries && holidayMarkers.length === 0 && !isCompany && !isHalfCompany
|
||||
|
||||
// The fill always shows WHO is off (person colour, split for several) — half
|
||||
// days keep that fill and get a small corner ½ badge instead, so a half day
|
||||
@@ -130,6 +133,8 @@ export default function VacayMonthCard({
|
||||
// 2 people render via the diagonal overlay below, so each half can be a solid
|
||||
// vacation fill or a hatched comp fill independently (#1074).
|
||||
else if (dayEntries.length === 0 && isCompany) background = 'rgba(245,158,11,0.22)'
|
||||
// Half the day is the company's: the fill covers half the cell (#2439).
|
||||
else if (dayEntries.length === 0 && isHalfCompany) background = 'linear-gradient(135deg, rgba(245,158,11,0.3) 50%, transparent 50%)'
|
||||
else if (dayEntries.length === 0 && publicHoliday) background = `color-mix(in srgb, ${publicHoliday.color} 22%, transparent)`
|
||||
// A plain school-break day gets a soft wash of its calendar colour so a run of
|
||||
// days reads as one gentle stretch; the rounded band below names the calendar.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// FE-VACAY-COMPANY-001 to FE-VACAY-COMPANY-003 (#2439)
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { companyHolidaySets, leaveFractionFor, toggledCompanyHolidays } from './companyHolidays'
|
||||
|
||||
describe('company holidays', () => {
|
||||
it('FE-VACAY-COMPANY-001: splits whole and half days, old rows being whole', () => {
|
||||
const { full, half } = companyHolidaySets([{ date: 'a' }, { date: 'b', fraction: 0.5 }, { date: 'c', fraction: 1 }])
|
||||
expect([...full]).toEqual(['a', 'c'])
|
||||
expect([...half]).toEqual(['b'])
|
||||
})
|
||||
|
||||
it('FE-VACAY-COMPANY-002: adds, converts and clears by the server rule', () => {
|
||||
const one = toggledCompanyHolidays([], 'x', 0.5)
|
||||
expect(one).toEqual([{ date: 'x', fraction: 0.5 }])
|
||||
const whole = toggledCompanyHolidays(one, 'x', 1)
|
||||
expect(whole).toEqual([{ date: 'x', fraction: 1 }])
|
||||
expect(toggledCompanyHolidays(whole, 'x', 1)).toEqual([])
|
||||
})
|
||||
|
||||
it('FE-VACAY-COMPANY-003: leave on a half company holiday is half a day', () => {
|
||||
expect(leaveFractionFor('x', new Set(['x']), 1)).toBe(0.5)
|
||||
expect(leaveFractionFor('y', new Set(['x']), 1)).toBe(1)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
/** A company holiday as the plan holds it; `fraction` 0.5 is a half day (#2439). */
|
||||
export interface CompanyHoliday {
|
||||
date: string
|
||||
note?: string
|
||||
fraction?: number | null
|
||||
}
|
||||
|
||||
const isHalf = (h: CompanyHoliday) => (h.fraction ?? 1) < 1
|
||||
|
||||
/**
|
||||
* The plan's company holidays split by size (#2439): a whole one closes the day to
|
||||
* leave, a half one leaves half of it. Rows from before the column are whole.
|
||||
*/
|
||||
export function companyHolidaySets(list: CompanyHoliday[]): { full: Set<string>; half: Set<string> } {
|
||||
const full = new Set<string>()
|
||||
const half = new Set<string>()
|
||||
for (const h of list) (isHalf(h) ? half : full).add(h.date)
|
||||
return { full, half }
|
||||
}
|
||||
|
||||
/**
|
||||
* The list after a click, ahead of the server, by its rule: the same size again
|
||||
* clears the day, the other size converts it.
|
||||
*/
|
||||
export function toggledCompanyHolidays(list: CompanyHoliday[], date: string, fraction: number): CompanyHoliday[] {
|
||||
const existing = list.find(h => h.date === date)
|
||||
if (!existing) return [...list, { date, fraction }]
|
||||
if ((existing.fraction ?? 1) === fraction) return list.filter(h => h.date !== date)
|
||||
return list.map(h => (h.date === date ? { ...h, fraction } : h))
|
||||
}
|
||||
|
||||
/** The fraction a leave click may book on a day: half of a half company holiday, else what was asked. */
|
||||
export function leaveFractionFor(date: string, half: Set<string>, asked: 0.5 | 1): 0.5 | 1 {
|
||||
return half.has(date) ? 0.5 : asked
|
||||
}
|
||||
Reference in New Issue
Block a user