fix(defter): haftalar ayın günlerine göre (1–8, 9–15, 16–22, 23–son), defter bugünün haftasıyla açılır
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useRef, useState } from 'react'
|
||||
import { useLocation, useSearchParams } from 'react-router'
|
||||
import { useLocation } from 'react-router'
|
||||
import { Info } from 'lucide-react'
|
||||
import { PageError, PageHeader, PageLoading } from '@/components/page'
|
||||
import { PeriodPicker } from '@/features/periods/period-picker'
|
||||
@@ -8,7 +8,7 @@ import { Section } from '@/features/planning/plan-read'
|
||||
import { useCategories, usePaymentMethods } from '@/lib/catalog'
|
||||
import { useEntries } from '@/lib/entries'
|
||||
import { toIsoDate } from '@/lib/format'
|
||||
import { parseWeekParam, weekIndexFor } from '@/lib/ledger'
|
||||
import { weekIndexFor } from '@/lib/ledger'
|
||||
import { isWritable } from '@/lib/period-select'
|
||||
import { useBudget } from '@/lib/periods'
|
||||
import { t } from '@/lib/strings'
|
||||
@@ -33,11 +33,11 @@ export function LedgerPage() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Hafta adreste tutulur (`?hafta=2`): yenileyince / geri gelince aynı hafta açılır.
|
||||
* Defter her açılışta **bugünün haftasıyla** başlar (dönem geçmişteyse son, gelecekteyse ilk
|
||||
* hafta); oklarla gezilen hafta yalnızca bu ekranda tutulur, adrese yazılmaz (kullanıcı kararı).
|
||||
* Düzen: hafta seçici → form → haftalık özet → girişler (masaüstünde form solda, diğerleri sağda).
|
||||
*/
|
||||
function LedgerView({ period }: { period: Period }) {
|
||||
const [params, setParams] = useSearchParams()
|
||||
const [today] = useState(() => toIsoDate(new Date()))
|
||||
const [editing, setEditing] = useState<Entry | null>(null)
|
||||
// Panel'deki "Harcama Ekle" → tutar alanına odaklan
|
||||
@@ -45,9 +45,9 @@ function LedgerView({ period }: { period: Period }) {
|
||||
const formRef = useRef<HTMLDivElement>(null)
|
||||
const inPeriod = today >= period.start_date && today <= period.last_date
|
||||
const todayIndex = inPeriod ? weekIndexFor(period.weeks, today) : null
|
||||
const index =
|
||||
parseWeekParam(params.get('hafta'), period.weeks.length) ?? weekIndexFor(period.weeks, today)
|
||||
const week = period.weeks[index - 1]
|
||||
const [index, setIndex] = useState(() => weekIndexFor(period.weeks, today))
|
||||
// Dönem tarihleri değişip hafta sayısı azalırsa son haftaya düş
|
||||
const week = period.weeks[Math.min(index, period.weeks.length) - 1]
|
||||
const readOnly = !isWritable(period)
|
||||
|
||||
const budget = useBudget(period.id)
|
||||
@@ -57,15 +57,7 @@ function LedgerView({ period }: { period: Period }) {
|
||||
|
||||
const goTo = (n: number) => {
|
||||
setEditing(null)
|
||||
setParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev) // seçili dönem (`donem`) korunur
|
||||
if (n === todayIndex) next.delete('hafta')
|
||||
else next.set('hafta', String(n))
|
||||
return next
|
||||
},
|
||||
{ replace: true },
|
||||
)
|
||||
setIndex(n)
|
||||
}
|
||||
|
||||
function edit(e: Entry) {
|
||||
@@ -81,7 +73,7 @@ function LedgerView({ period }: { period: Period }) {
|
||||
<div className="mx-auto max-w-3xl lg:max-w-none">
|
||||
<WeekPicker
|
||||
weeks={period.weeks}
|
||||
index={index}
|
||||
index={week.index}
|
||||
todayIndex={todayIndex}
|
||||
budget={budget.data}
|
||||
onChange={goTo}
|
||||
@@ -123,7 +115,7 @@ function LedgerView({ period }: { period: Period }) {
|
||||
{budget.isError ? (
|
||||
<PageError message={budget.error.message} onRetry={budget.refetch} />
|
||||
) : budget.data ? (
|
||||
<WeekSummary budget={budget.data} index={index} />
|
||||
<WeekSummary budget={budget.data} index={week.index} />
|
||||
) : (
|
||||
<PageLoading />
|
||||
)}
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { PeriodWeek } from '@/types/PeriodWeek'
|
||||
|
||||
const s = t.ledger
|
||||
|
||||
/** ◀ önceki | 2. hafta / 5 · 07.12 – 13.12 | sonraki ▶ (+ "Bu hafta", haftanın toplamı) */
|
||||
/** ◀ önceki | 2. hafta / 4 · 09.12 – 15.12 | sonraki ▶ (+ "Bu hafta", haftanın toplamı) */
|
||||
export function WeekPicker({
|
||||
weeks,
|
||||
index,
|
||||
|
||||
Reference in New Issue
Block a user