Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-07-12 - DateRangePicker ํ† ๊ธ€ ๋ฒ„ํŠผ์˜ ํ‚ค๋ณด๋“œ ์ ‘๊ทผ์„ฑ ๋ฐ ์ƒํƒœ ์ธ์ง€ ๊ฐœ์„ 
**Learning:** ์—ฌ๋Ÿฌ ์„ ํƒ์ง€ ์ค‘ ํ•˜๋‚˜๋ฅผ ๊ณ ๋ฅด๋Š” ํ† ๊ธ€ ํ˜•ํƒœ์˜ ๋ฒ„ํŠผ ๊ทธ๋ฃน(์˜ˆ: ๊ธฐ๊ฐ„ ์„ ํƒ ํ”„๋ฆฌ์…‹)์—์„œ๋Š” ์‹œ๊ฐ์ ์ธ ์Šคํƒ€์ผ(์ƒ‰์ƒ) ๋ณ€ํ™”๋งŒ์œผ๋กœ ์ƒํƒœ๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉด ์Šคํฌ๋ฆฐ ๋ฆฌ๋” ๋“ฑ ๋ณด์กฐ ๊ธฐ๊ธฐ ์‚ฌ์šฉ์ž๊ฐ€ ํ˜„์žฌ ์„ ํƒ๋œ ๊ฐ’์„ ์ธ์ง€ํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ํ‚ค๋ณด๋“œ ๋„ค๋น„๊ฒŒ์ด์…˜ ์‹œ ํฌ์ปค์Šค ๋ง(`focus-visible` ํด๋ž˜์Šค)์ด ๋น ์ ธ ์žˆ์œผ๋ฉด ์‚ฌ์šฉ์ž๊ฐ€ ์–ด๋–ค ๋ฒ„ํŠผ์— ์œ„์น˜ํ•ด ์žˆ๋Š”์ง€ ์‹œ๊ฐ์ ์œผ๋กœ ํ™•์ธํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค.
**Action:** ํ† ๊ธ€ ํ˜•ํƒœ์˜ ๋ฒ„ํŠผ์ด๋‚˜ ํƒญ์—๋Š” ๋ฐ˜๋“œ์‹œ `aria-pressed={isActive}` ์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ƒํƒœ๋ฅผ ๋ช…ํ™•ํžˆ ์ „๋‹ฌํ•˜๊ณ , Tailwind CSS๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” `focus-visible:outline-none focus-visible:ring-2`์™€ ๊ฐ™์€ ํ‚ค๋ณด๋“œ ํฌ์ปค์Šค ์Šคํƒ€์ผ์„ ๋ฐ˜๋“œ์‹œ ํฌํ•จํ•˜์—ฌ ํ‚ค๋ณด๋“œ ์ ‘๊ทผ์„ฑ์„ ํ™•๋ณดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
79 changes: 39 additions & 40 deletions packages/web/src/components/dashboard/date-range-picker.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
'use client'
"use client";

import { useSearchParams, useRouter } from 'next/navigation'
import { subDays, format, differenceInDays } from 'date-fns'
import { Suspense } from 'react'
import { cn } from '@/lib/utils'
import { useSearchParams, useRouter } from "next/navigation";
import { subDays, format, differenceInDays } from "date-fns";
import { Suspense } from "react";
import { cn } from "@/lib/utils";

const PRESETS = [
{ days: 7, label: '7d' },
{ days: 30, label: '30d' },
{ days: 90, label: '90d' },
{ days: 3650, label: 'ALL' },
] as const
{ days: 7, label: "7d" },
{ days: 30, label: "30d" },
{ days: 90, label: "90d" },
{ days: 3650, label: "ALL" },
] as const;

function DateRangePickerContent() {
const router = useRouter()
const searchParams = useSearchParams()
const router = useRouter();
const searchParams = useSearchParams();

const currentFrom = searchParams.get('from')
const currentTo = searchParams.get('to')
const currentFrom = searchParams.get("from");
const currentTo = searchParams.get("to");

const today = new Date()
const sevenDaysAgo = subDays(today, 7)
const today = new Date();
const sevenDaysAgo = subDays(today, 7);

const defaultFrom = currentFrom || format(sevenDaysAgo, 'yyyy-MM-dd')
const defaultTo = currentTo || format(today, 'yyyy-MM-dd')
const defaultFrom = currentFrom || format(sevenDaysAgo, "yyyy-MM-dd");
const defaultTo = currentTo || format(today, "yyyy-MM-dd");

const fromDate = new Date(defaultFrom)
const toDate = new Date(defaultTo)
const daysDiff = differenceInDays(toDate, fromDate)
const fromDate = new Date(defaultFrom);
const toDate = new Date(defaultTo);
const daysDiff = differenceInDays(toDate, fromDate);

const isToday = format(toDate, 'yyyy-MM-dd') === format(today, 'yyyy-MM-dd')
const isToday = format(toDate, "yyyy-MM-dd") === format(today, "yyyy-MM-dd");
const activePreset = isToday
? daysDiff === 6
? 7
Expand All @@ -40,20 +40,20 @@ function DateRangePickerContent() {
: daysDiff >= 3649
? 3650
: null
: null
: null;

const handlePreset = (days: number) => {
const to = format(today, 'yyyy-MM-dd')
const from = format(subDays(today, days), 'yyyy-MM-dd')
const to = format(today, "yyyy-MM-dd");
const from = format(subDays(today, days), "yyyy-MM-dd");

const newParams = new URLSearchParams(searchParams.toString())
newParams.set('from', from)
newParams.set('to', to)
const newParams = new URLSearchParams(searchParams.toString());
newParams.set("from", from);
newParams.set("to", to);
// ํŽ˜์ด์ง€๋„ค์ด์…˜ ์‚ฌ์šฉ ์ค‘์ธ ํ™”๋ฉด์—์„œ ๋‚ ์งœ๊ฐ€ ๋ฐ”๋€Œ๋ฉด ์ฒซ ํŽ˜์ด์ง€๋กœ ๋ฆฌ์…‹
newParams.delete('page')
newParams.delete("page");

router.push(`?${newParams.toString()}`)
}
router.push(`?${newParams.toString()}`);
};

return (
<div className="flex flex-col sm:flex-row sm:items-center gap-2">
Expand All @@ -63,32 +63,31 @@ function DateRangePickerContent() {
key={preset.days}
type="button"
onClick={() => handlePreset(preset.days)}
aria-pressed={activePreset === preset.days}
className={cn(
'px-3 py-1 text-xs font-medium rounded-md transition-colors',
"px-3 py-1 text-xs font-medium rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
activePreset === preset.days
? 'bg-primary text-primary-foreground'
: 'text-muted-foreground hover:text-foreground hover:bg-muted',
? "bg-primary text-primary-foreground"
: "text-muted-foreground hover:text-foreground hover:bg-muted",
)}
>
{preset.label}
</button>
))}
</div>
<span className="text-xs text-muted-foreground tabular-nums">
{format(fromDate, 'MMM d')} ~ {format(toDate, 'MMM d')}
{format(fromDate, "MMM d")} ~ {format(toDate, "MMM d")}
</span>
</div>
)
);
}

export function DateRangePicker() {
return (
<Suspense
fallback={
<div className="h-8 w-64 bg-muted animate-pulse rounded-lg" />
}
fallback={<div className="h-8 w-64 bg-muted animate-pulse rounded-lg" />}
>
<DateRangePickerContent />
</Suspense>
)
);
}
Loading