Skip to content

Commit e650805

Browse files
committed
fix(routines): archive done, archived counter, FAB offset, day zoom from week and month (TM-918..922)
Archive done matched only frequency NONE but completed one-offs come back with a null frequency, so nothing was archived. The archived chip was hardcoded to 0 and the count action read the wrong response level. The FAB now clears the desktop status bar, and the week header and month date open the Day view.
1 parent fdaa878 commit e650805

10 files changed

Lines changed: 147 additions & 37 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
jest.mock('@/plugins/axios', () => ({
2+
__esModule: true,
3+
default: { get: jest.fn() },
4+
}));
5+
6+
import axios from '@/plugins/axios';
7+
import { getArchivedDailyTasksCount } from '../daily-tasks';
8+
9+
describe('getArchivedDailyTasksCount', () => {
10+
it('unwraps the count from the response envelope', async () => {
11+
(axios.get as jest.Mock).mockResolvedValueOnce({
12+
data: { data: { count: 4 } },
13+
});
14+
expect(await getArchivedDailyTasksCount()).toBe(4);
15+
expect(axios.get).toHaveBeenCalledWith(
16+
'daily-routines/tasks/archived/count',
17+
);
18+
});
19+
});

‎src/actions/tmgr/daily-tasks.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export const getDailyTasks = async (): Promise<Task[]> => {
2424
export const getArchivedDailyTasksCount = async (): Promise<Number> => {
2525
try {
2626
const {
27-
data: { count },
27+
data: {
28+
data: { count },
29+
},
2830
} = await $axios.get(`daily-routines/tasks/archived/count`);
2931
return count;
3032
} catch (error) {

‎src/components/dailyRoutine/views/DayView.vue‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
<span>{{ unscheduled.length }}</span>
1919
</div>
2020
<button
21-
v-if="unscheduledDoneCount > 0"
21+
v-if="doneUnscheduledIdList.length > 0"
2222
type="button"
2323
class="rounded-pill border border-line bg-surface px-2.5 py-1 text-[10px] font-semibold tracking-wider text-ink-subtle uppercase hover:border-brand hover:text-brand"
24-
@click="$emit('archive-done-unscheduled')"
24+
@click="$emit('archive-done-unscheduled', doneUnscheduledIdList)"
2525
>
26-
{{ $t('dailyRoutine.archiveDone', { n: unscheduledDoneCount }) }}
26+
{{
27+
$t('dailyRoutine.archiveDone', { n: doneUnscheduledIdList.length })
28+
}}
2729
</button>
2830
</div>
2931
<RoutineRow
@@ -117,6 +119,7 @@
117119
<script setup lang="ts">
118120
import { useRoutineDrag } from '@/composable/useRoutineDrag';
119121
import type { RoutineEntry } from '@/types/dailyRoutine';
122+
import { doneUnscheduledIds } from '@/utils/dailyRoutines/archiveDone';
120123
import { isSameDay, parseTime } from '@/utils/dailyRoutines/dateHelpers';
121124
import { clusterEvents } from '@/utils/dailyRoutines/lanePacking';
122125
import { sortUnscheduledNewestFirst } from '@/utils/dailyRoutines/sortRoutines';
@@ -141,7 +144,7 @@
141144
(e: 'delete', entry: RoutineEntry): void;
142145
(e: 'select', entry: RoutineEntry): void;
143146
(e: 'archive', entry: RoutineEntry): void;
144-
(e: 'archive-done-unscheduled'): void;
147+
(e: 'archive-done-unscheduled', ids: number[]): void;
145148
(
146149
e: 'create',
147150
payload: { date: string; timeH: number; timeM: number },
@@ -195,8 +198,8 @@
195198
const unscheduled = computed(() =>
196199
sortUnscheduledNewestFirst(props.entries.filter((e) => !e.time)),
197200
);
198-
const unscheduledDoneCount = computed(
199-
() => unscheduled.value.filter((e) => e.completed).length,
201+
const doneUnscheduledIdList = computed(() =>
202+
doneUnscheduledIds(unscheduled.value),
200203
);
201204
const scheduled = computed(() => props.entries.filter((e) => !!e.time));
202205

‎src/components/dailyRoutine/views/ListView.vue‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
<span class="text-ink-subtle">{{ unscheduled.length }}</span>
2121
</div>
2222
<button
23-
v-if="unscheduledDoneCount > 0"
23+
v-if="doneUnscheduledIdList.length > 0"
2424
type="button"
2525
class="rounded-pill border border-line bg-surface px-2.5 py-1 text-[10px] font-semibold tracking-wider text-ink-subtle uppercase hover:border-brand hover:text-brand"
26-
@click="$emit('archive-done-unscheduled')"
26+
@click="$emit('archive-done-unscheduled', doneUnscheduledIdList)"
2727
>
28-
{{ $t('dailyRoutine.archiveDone', { n: unscheduledDoneCount }) }}
28+
{{
29+
$t('dailyRoutine.archiveDone', { n: doneUnscheduledIdList.length })
30+
}}
2931
</button>
3032
</header>
3133
<div class="flex flex-col gap-1.5">
@@ -77,6 +79,7 @@
7779
<script setup lang="ts">
7880
import { useRoutineDrag } from '@/composable/useRoutineDrag';
7981
import type { RoutineEntry } from '@/types/dailyRoutine';
82+
import { doneUnscheduledIds } from '@/utils/dailyRoutines/archiveDone';
8083
import { sortUnscheduledNewestFirst } from '@/utils/dailyRoutines/sortRoutines';
8184
import { currentTimeZone, todayIn } from '@/utils/timezone';
8285
import { computed } from 'vue';
@@ -97,7 +100,7 @@
97100
(e: 'delete', entry: RoutineEntry): void;
98101
(e: 'select', entry: RoutineEntry): void;
99102
(e: 'archive', entry: RoutineEntry): void;
100-
(e: 'archive-done-unscheduled'): void;
103+
(e: 'archive-done-unscheduled', ids: number[]): void;
101104
(
102105
e: 'context',
103106
payload: { entry: RoutineEntry; x: number; y: number },
@@ -108,8 +111,8 @@
108111
sortUnscheduledNewestFirst(props.entries.filter((e) => !e.time)),
109112
);
110113
111-
const unscheduledDoneCount = computed(
112-
() => unscheduled.value.filter((e) => e.completed).length,
114+
const doneUnscheduledIdList = computed(() =>
115+
doneUnscheduledIds(unscheduled.value),
113116
);
114117
115118
const scheduled = computed(() =>

‎src/components/dailyRoutine/views/MonthView.vue‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,22 @@
4343
class="flex items-center justify-end text-xs tabular-nums"
4444
:style="dayLabelStyle(d)"
4545
>
46-
<span
46+
<button
4747
v-if="isSameDay(d, today)"
48-
class="inline-flex h-5 w-5 items-center justify-center rounded-pill bg-brand text-[10px] font-bold text-on-accent"
48+
type="button"
49+
class="inline-flex h-5 w-5 items-center justify-center rounded-pill bg-brand text-[10px] font-bold text-on-accent hover:opacity-80"
50+
@click.stop="$emit('select-day', d)"
51+
>
52+
{{ d.getDate() }}
53+
</button>
54+
<button
55+
v-else
56+
type="button"
57+
class="rounded-sm px-1 hover:bg-surface-hover hover:underline"
58+
@click.stop="$emit('select-day', d)"
4959
>
5060
{{ d.getDate() }}
51-
</span>
52-
<span v-else>{{ d.getDate() }}</span>
61+
</button>
5362
</div>
5463
<div
5564
v-for="e in byDay[i].slice(0, maxChips)"

‎src/components/dailyRoutine/views/WeekView.vue‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
:style="{ gridTemplateColumns: gridCols, minWidth: innerMinWidth }"
1010
>
1111
<div />
12-
<div
12+
<button
1313
v-for="(d, i) in days"
1414
:key="i"
15-
class="px-2 py-2 text-center"
15+
type="button"
16+
class="cursor-pointer px-2 py-2 text-center hover:bg-surface-hover"
1617
:class="i === 0 ? '' : 'border-l border-line'"
1718
:style="
1819
isSameDay(d, today)
1920
? { background: 'rgba(232,133,125,.08)' }
2021
: undefined
2122
"
23+
@click="$emit('select-day', d)"
2224
>
2325
<div
2426
class="text-[10px] font-bold tracking-wider uppercase"
@@ -32,7 +34,7 @@
3234
>
3335
{{ d.getDate() }}
3436
</div>
35-
</div>
37+
</button>
3638
</div>
3739

3840
<!-- All-day row -->
@@ -223,6 +225,7 @@
223225
}>();
224226
225227
const emit = defineEmits<{
228+
(e: 'select-day', date: Date): void;
226229
(e: 'toggle', entry: RoutineEntry): void;
227230
(e: 'edit', entry: RoutineEntry): void;
228231
(

‎src/pages/DailyRoutine.vue‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,14 @@
315315
<span>{{ unscheduledEntries.length }}</span>
316316
</div>
317317
<button
318-
v-if="unscheduledDoneCount > 0"
318+
v-if="doneUnscheduledIdList.length > 0"
319319
type="button"
320320
class="rounded-pill border border-line bg-surface px-2.5 py-1 text-[10px] font-semibold tracking-wider text-ink-subtle uppercase hover:border-brand hover:text-brand"
321-
@click="onArchiveDoneUnscheduled"
321+
@click="onArchiveDoneUnscheduled(doneUnscheduledIdList)"
322322
>
323323
{{
324324
$t('dailyRoutine.archiveDone', {
325-
n: unscheduledDoneCount,
325+
n: doneUnscheduledIdList.length,
326326
})
327327
}}
328328
</button>
@@ -373,6 +373,7 @@
373373
:week-start="weekStart"
374374
:is-mobile="isMobile"
375375
:is-tablet="isTablet"
376+
@select-day="onSelectDay"
376377
@toggle="onToggle"
377378
@edit="onEdit"
378379
@create="onCreateAt"
@@ -464,7 +465,7 @@
464465
<button
465466
v-if="!selectMode"
466467
type="button"
467-
class="fixed right-4 bottom-20 z-20 flex h-12 w-12 items-center justify-center rounded-full bg-brand text-on-accent shadow-tmgr-md transition-transform hover:scale-105 hover:bg-brand-hover md:right-6 md:bottom-6 md:h-14 md:w-14"
468+
class="fixed right-4 bottom-20 z-20 flex h-12 w-12 items-center justify-center rounded-full bg-brand text-on-accent shadow-tmgr-md transition-transform hover:scale-105 hover:bg-brand-hover md:right-6 md:bottom-[calc(var(--statusbar-h,0px)+1.5rem)] md:h-14 md:w-14"
468469
:title="$t('dailyRoutine.page.newRoutineTitle')"
469470
:aria-label="$t('dailyRoutine.page.newRoutine')"
470471
data-tour="routines.add"
@@ -536,6 +537,8 @@
536537
startOfMonth,
537538
startOfWeek,
538539
} from '@/utils/dailyRoutines/dateHelpers';
540+
import { getArchivedDailyTasksCount } from '@/actions/tmgr/daily-tasks';
541+
import { doneUnscheduledIds } from '@/utils/dailyRoutines/archiveDone';
539542
import { sortUnscheduledNewestFirst } from '@/utils/dailyRoutines/sortRoutines';
540543
import { requestCache } from '@/utils/requestCache';
541544
import { nowDateIn, todayDateIn, todayIn } from '@/utils/timezone';
@@ -644,9 +647,17 @@
644647
entries.value.filter((e) => !e.time && e.date === todayIso.value),
645648
),
646649
);
647-
const unscheduledDoneCount = computed(
648-
() => unscheduledEntries.value.filter((e) => e.completed).length,
650+
const doneUnscheduledIdList = computed(() =>
651+
doneUnscheduledIds(unscheduledEntries.value),
649652
);
653+
const archivedCount = ref(0);
654+
async function refreshArchivedCount() {
655+
try {
656+
archivedCount.value = Number(await getArchivedDailyTasksCount());
657+
} catch {
658+
archivedCount.value = 0;
659+
}
660+
}
650661
const scheduledEntries = computed(() =>
651662
entries.value.filter((e) => !!e.time),
652663
);
@@ -656,7 +667,7 @@
656667
return {
657668
routines: todays.length,
658669
completed: todays.filter((e) => e.completed).length,
659-
archived: 0,
670+
archived: archivedCount.value,
660671
};
661672
});
662673
@@ -842,6 +853,7 @@
842853
const snapshotKey = routinesSnapshotKey();
843854
viewPending.value = true;
844855
viewError.value = null;
856+
void refreshArchivedCount();
845857
try {
846858
if (view.value === 'year') {
847859
await Promise.all([
@@ -1024,8 +1036,8 @@
10241036
await reload();
10251037
}
10261038
1027-
async function onArchiveDoneUnscheduled() {
1028-
await store.dispatch('dailyRoutines/archiveDoneUnscheduled');
1039+
async function onArchiveDoneUnscheduled(ids: number[]) {
1040+
await store.dispatch('dailyRoutines/archiveDoneUnscheduled', ids);
10291041
await reload();
10301042
}
10311043

‎src/store/modules/dailyRoutines.js‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,7 @@ const dailyRoutinesModule = {
273273
await archiveDailyTask(taskId);
274274
commit('removeEntries', (e) => e.task_id === taskId);
275275
},
276-
async archiveDoneUnscheduled({ commit, state }) {
277-
const ids = [
278-
...new Set(
279-
state.entries
280-
.filter((e) => e.frequency === 'NONE' && e.completed)
281-
.map((e) => e.task_id),
282-
),
283-
];
276+
async archiveDoneUnscheduled({ commit }, ids) {
284277
for (const id of ids) {
285278
await archiveDailyTask(id);
286279
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { doneUnscheduledIds } from '../dailyRoutines/archiveDone';
2+
3+
const entry = (
4+
task_id: number,
5+
over: Partial<{
6+
time: string | null;
7+
completed: boolean;
8+
frequency: string | null;
9+
}>,
10+
) => ({
11+
task_id,
12+
time: null as string | null,
13+
completed: true,
14+
frequency: 'NONE',
15+
...over,
16+
});
17+
18+
describe('doneUnscheduledIds', () => {
19+
it('returns completed unscheduled one-off routines', () => {
20+
expect(doneUnscheduledIds([entry(1, {}), entry(2, {})] as any)).toEqual([
21+
1, 2,
22+
]);
23+
});
24+
25+
it('treats a missing frequency as one-off', () => {
26+
expect(
27+
doneUnscheduledIds([
28+
entry(1, { frequency: null }),
29+
entry(2, { frequency: undefined }),
30+
] as any),
31+
).toEqual([1, 2]);
32+
});
33+
34+
it('skips recurring, scheduled and open entries', () => {
35+
expect(
36+
doneUnscheduledIds([
37+
entry(1, { frequency: 'DAILY' }),
38+
entry(2, { time: '09:00' }),
39+
entry(3, { completed: false }),
40+
entry(4, {}),
41+
] as any),
42+
).toEqual([4]);
43+
});
44+
45+
it('deduplicates task ids', () => {
46+
expect(doneUnscheduledIds([entry(5, {}), entry(5, {})] as any)).toEqual([
47+
5,
48+
]);
49+
});
50+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { RoutineEntry } from '@/types/dailyRoutine';
2+
3+
export function doneUnscheduledIds(
4+
entries: Pick<RoutineEntry, 'task_id' | 'time' | 'completed' | 'frequency'>[],
5+
): number[] {
6+
return [
7+
...new Set(
8+
entries
9+
.filter(
10+
(e) =>
11+
!e.time && e.completed && (!e.frequency || e.frequency === 'NONE'),
12+
)
13+
.map((e) => e.task_id),
14+
),
15+
];
16+
}

0 commit comments

Comments
 (0)