-
Notifications
You must be signed in to change notification settings - Fork 0
feat(kanban): calendar view (month grid + agenda) #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+519
−19
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| import { useState } from "react"; | ||
| import { t } from "@lingui/core/macro"; | ||
| import { Trans } from "@lingui/react/macro"; | ||
| import { ChevronLeftIcon, ChevronRightIcon, CheckCircleIcon } from "@heroicons/react/24/outline"; | ||
| import { | ||
| PRIORITY_STYLE, | ||
| currentMonth, | ||
| groupCardsByDay, | ||
| isIsoDate, | ||
| monthMatrix, | ||
| shiftMonth, | ||
| sortCards, | ||
| type BoardViewCard, | ||
| type CalendarMode, | ||
| } from "../../lib/board"; | ||
|
|
||
| /** Localized short weekday labels, Sunday-first (2023-01-01 was a Sunday). */ | ||
| const WEEKDAYS = Array.from({ length: 7 }, (_, i) => | ||
| new Date(2023, 0, 1 + i).toLocaleDateString(undefined, { weekday: "short" }), | ||
| ); | ||
|
|
||
| /** | ||
| * Calendar view over the same cards (Notion's "one data, many views"): a month | ||
| * grid or an agenda list, keyed off each card's `due`. A card click opens the | ||
| * same peek as the board/table. The remembered sub-mode lives in the board | ||
| * config (`calendarMode`); the visible month is local cursor state. | ||
| */ | ||
| export function BoardCalendar({ | ||
| cards, | ||
| today, | ||
| doneKey, | ||
| mode, | ||
| onModeChange, | ||
| selectedId, | ||
| onSelect, | ||
| }: { | ||
| cards: BoardViewCard[]; | ||
| today: string; | ||
| doneKey: string; | ||
| mode: CalendarMode; | ||
| onModeChange: (mode: CalendarMode) => void; | ||
| selectedId?: string; | ||
| onSelect: (card: BoardViewCard) => void; | ||
| }) { | ||
| const [month, setMonth] = useState(() => currentMonth()); | ||
| const byDay = groupCardsByDay(cards); | ||
| const [ys, ms] = month.split("-"); | ||
| const monthLabel = new Date(Number(ys), Number(ms) - 1, 1).toLocaleDateString(undefined, { year: "numeric", month: "long" }); | ||
|
|
||
| const isOverdue = (c: BoardViewCard) => !!c.due && c.due < today && c.columnKey !== doneKey; | ||
|
|
||
| const navBtn = | ||
| "inline-flex h-7 w-7 items-center justify-center rounded-md border border-stone-200 text-stone-500 hover:border-brand/40 hover:text-brand-dark"; | ||
| const modeBtn = (m: CalendarMode) => | ||
| `rounded-md px-2 py-1 text-xs font-medium ${ | ||
| mode === m ? "bg-brand-soft text-brand-dark" : "text-stone-500 hover:text-brand-dark" | ||
| }`; | ||
|
|
||
| const cardChip = (card: BoardViewCard, compact: boolean) => { | ||
| const overdue = isOverdue(card); | ||
| return ( | ||
| <button | ||
| key={card.id} | ||
| type="button" | ||
| onClick={() => onSelect(card)} | ||
| title={card.title} | ||
| className={`flex w-full items-center gap-1 rounded px-1 py-0.5 text-left text-[11px] transition-colors ${ | ||
| selectedId === card.id ? "bg-brand-soft/60" : "bg-stone-100/70 hover:bg-brand-soft/40" | ||
| } ${overdue ? "text-red-600" : "text-stone-700"}`} | ||
| > | ||
| {card.priority && card.priority !== "none" && ( | ||
| <span className={`h-1.5 w-1.5 shrink-0 rounded-full ${PRIORITY_STYLE[card.priority]?.split(" ")[0] ?? "bg-stone-300"}`} /> | ||
| )} | ||
| {card.icon && <span className="shrink-0">{card.icon}</span>} | ||
| <span className="truncate">{card.title}</span> | ||
| {!compact && (card.taskTotal ?? 0) > 0 && ( | ||
| <span className="ml-auto inline-flex shrink-0 items-center gap-0.5 text-[10px] text-stone-400"> | ||
| <CheckCircleIcon className="h-2.5 w-2.5" /> | ||
| {card.taskDone}/{card.taskTotal} | ||
| </span> | ||
| )} | ||
| </button> | ||
| ); | ||
| }; | ||
|
|
||
| const header = ( | ||
| <div className="flex items-center gap-2 border-b border-black/[0.04] px-4 py-2"> | ||
| {mode === "month" && ( | ||
| <> | ||
| <button type="button" className={navBtn} title={t`Previous month`} aria-label={t`Previous month`} onClick={() => setMonth((m) => shiftMonth(m, -1))}> | ||
| <ChevronLeftIcon className="h-4 w-4" /> | ||
| </button> | ||
| <button type="button" className={navBtn} title={t`Next month`} aria-label={t`Next month`} onClick={() => setMonth((m) => shiftMonth(m, 1))}> | ||
| <ChevronRightIcon className="h-4 w-4" /> | ||
| </button> | ||
| <span className="min-w-[8rem] text-sm font-medium text-brand-dark">{monthLabel}</span> | ||
| <button | ||
| type="button" | ||
| className="rounded-md border border-stone-200 px-2 py-1 text-xs text-stone-600 hover:border-brand/40 hover:text-brand-dark" | ||
| onClick={() => setMonth(currentMonth())} | ||
| > | ||
| <Trans>Today</Trans> | ||
| </button> | ||
| </> | ||
| )} | ||
| <div className="ml-auto inline-flex items-center rounded-lg border border-stone-200 p-0.5"> | ||
| <button type="button" className={modeBtn("month")} onClick={() => onModeChange("month")}> | ||
| <Trans>Month</Trans> | ||
| </button> | ||
| <button type="button" className={modeBtn("agenda")} onClick={() => onModeChange("agenda")}> | ||
| <Trans>Agenda</Trans> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
| if (mode === "agenda") { | ||
| const sorted = sortCards(cards, "due"); | ||
| const dated = sorted.filter((c) => isIsoDate(c.due)); | ||
| const undated = sorted.filter((c) => !isIsoDate(c.due)); | ||
| let lastDay = ""; | ||
| return ( | ||
| <div className="flex min-h-0 flex-1 flex-col"> | ||
| {header} | ||
| <div className="min-h-0 flex-1 overflow-auto p-4"> | ||
| {dated.length === 0 && undated.length === 0 && ( | ||
| <div className="px-3 py-8 text-center text-sm text-stone-400"> | ||
| <Trans>No cards</Trans> | ||
| </div> | ||
| )} | ||
| {dated.map((card) => { | ||
| const showHeader = card.due !== lastDay; | ||
| lastDay = card.due as string; | ||
| return ( | ||
| <div key={card.id}> | ||
| {showHeader && ( | ||
| <div className={`mt-3 mb-1 text-xs font-medium ${card.due === today ? "text-brand-dark" : "text-brand-gray"}`}> | ||
| {card.due} | ||
| {card.due === today && ( | ||
| <span className="ml-1 rounded bg-brand-soft px-1 text-[10px] text-brand-dark"> | ||
| <Trans>Today</Trans> | ||
| </span> | ||
| )} | ||
| </div> | ||
| )} | ||
| <div className="max-w-xl">{cardChip(card, false)}</div> | ||
| </div> | ||
| ); | ||
| })} | ||
| {undated.length > 0 && ( | ||
| <> | ||
| <div className="mt-4 mb-1 text-xs font-medium text-stone-400"> | ||
| <Trans>Unscheduled</Trans> | ||
| </div> | ||
| <div className="max-w-xl space-y-0.5">{undated.map((card) => cardChip(card, false))}</div> | ||
| </> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const weeks = monthMatrix(month); | ||
| return ( | ||
| <div className="flex min-h-0 flex-1 flex-col"> | ||
| {header} | ||
| <div className="grid grid-cols-7 border-b border-black/[0.04] bg-[#fbfdfb]"> | ||
| {WEEKDAYS.map((w) => ( | ||
| <div key={w} className="px-2 py-1 text-center text-[11px] font-medium uppercase tracking-wide text-brand-gray"> | ||
| {w} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| <div className="grid min-h-0 flex-1 grid-cols-7 grid-rows-6 overflow-auto"> | ||
| {weeks.flat().map((day) => { | ||
| const inMonth = day.slice(0, 7) === month; | ||
| const isToday = day === today; | ||
| const dayCards = byDay.get(day) ?? []; | ||
| return ( | ||
| <div | ||
| key={day} | ||
| className={`flex min-h-[5.5rem] flex-col gap-0.5 border-b border-r border-black/[0.04] p-1 ${inMonth ? "" : "bg-stone-50/60"}`} | ||
| > | ||
| <div | ||
| className={`mb-0.5 inline-flex h-5 w-5 items-center justify-center self-start rounded-full text-[11px] ${ | ||
| isToday ? "bg-brand text-white" : inMonth ? "text-stone-500" : "text-stone-300" | ||
| }`} | ||
| > | ||
| {Number(day.slice(8, 10))} | ||
| </div> | ||
| <div className="flex flex-col gap-0.5 overflow-hidden"> | ||
| {dayCards.slice(0, 4).map((card) => cardChip(card, true))} | ||
| {dayCards.length > 4 && ( | ||
| <span className="px-1 text-[10px] text-stone-400">+{dayCards.length - 4}</span> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| export { BoardSurface } from "./BoardSurface"; | ||
| export { BoardPeek } from "./BoardPeek"; | ||
| export { BoardTable } from "./BoardTable"; | ||
| export { BoardCalendar } from "./BoardCalendar"; | ||
| export { BoardSwimlanes } from "./BoardSwimlanes"; | ||
| export { EmojiField, ListboxSelect, TagMultiSelect, fieldCls } from "./controls"; | ||
| export type { BoardActions, BoardSurfaceProps, BoardOption } from "./types"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
Repository: cnjack/jtype
Length of output: 194
🏁 Script executed:
Repository: cnjack/jtype
Length of output: 196
🏁 Script executed:
Repository: cnjack/jtype
Length of output: 9469
Hoist month cursor state out of the shared component.
Line 45 introduces local
useState, and Lines 90/93/100 mutate it internally. Inshared/components, this should be controlled via props/callbacks so the component stays Props-in/Callbacks-out.Suggested refactor
Per coding guidelines: "Shared React components in
shared/must follow Props-in/Callbacks-out pattern and must not depend onuseReducer,useState, or any specific state pattern."🤖 Prompt for AI Agents
Source: Coding guidelines