refactor: code clean up
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
+19
-20
@@ -62,18 +62,17 @@ const {
|
||||
editingCollection,
|
||||
collectionEditorMode,
|
||||
collectionEditorType,
|
||||
isTaskView,
|
||||
isTasksSection,
|
||||
} = storeToRefs(chronoUiStore);
|
||||
|
||||
const { loadVisibleRange: loadVisibleRangeOperations } = chronoOperationsStore;
|
||||
|
||||
const {
|
||||
initialize,
|
||||
setViewMode,
|
||||
setCurrentDate,
|
||||
selectCalendar,
|
||||
selectSection,
|
||||
selectDate,
|
||||
selectCollection,
|
||||
openEditCalendar,
|
||||
selectTaskList,
|
||||
openEditTaskList,
|
||||
createEventFromDate,
|
||||
startEditingSelectedEntity,
|
||||
@@ -120,10 +119,10 @@ async function onFilesSelected(event: Event) {
|
||||
if (files.length) await openImport(files)
|
||||
}
|
||||
|
||||
function syncViewModeFromRoute() {
|
||||
function selectSectionFromRoute() {
|
||||
const routePath = route.path;
|
||||
const mode = routePath.endsWith('/tasks') ? 'tasks' : 'calendar';
|
||||
setViewMode(mode);
|
||||
const section = routePath.endsWith('/tasks') ? 'tasks' : 'calendar';
|
||||
selectSection(section);
|
||||
}
|
||||
|
||||
function handleCalendarViewChange(view: CalendarViewType) {
|
||||
@@ -150,16 +149,16 @@ watch(
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
syncViewModeFromRoute();
|
||||
await initialize(isTaskView.value ? 'tasks' : 'calendar');
|
||||
selectSectionFromRoute();
|
||||
await initialize(isTasksSection.value ? 'tasks' : 'calendar');
|
||||
} catch (error) {
|
||||
console.error('[Chrono] - Failed to load data from ChronoManager:', error);
|
||||
}
|
||||
});
|
||||
|
||||
watch(() => route.fullPath, async () => {
|
||||
syncViewModeFromRoute();
|
||||
if (isTaskView.value) {
|
||||
selectSectionFromRoute();
|
||||
if (isTasksSection.value) {
|
||||
await ensureTasksLoaded();
|
||||
}
|
||||
});
|
||||
@@ -187,7 +186,7 @@ watch(() => route.fullPath, async () => {
|
||||
|
||||
<!-- View Switcher for Calendar -->
|
||||
<v-btn-toggle
|
||||
v-if="!isTaskView"
|
||||
v-if="!isTasksSection"
|
||||
:model-value="calendarView"
|
||||
color="primary"
|
||||
variant="outlined"
|
||||
@@ -214,11 +213,11 @@ watch(() => route.fullPath, async () => {
|
||||
>
|
||||
<div class="pa-4">
|
||||
<CollectionList
|
||||
v-if="!isTaskView"
|
||||
v-if="!isTasksSection"
|
||||
:collections="collections"
|
||||
:selected-collection="selectedCollection"
|
||||
type="calendar"
|
||||
@select="selectCalendar"
|
||||
@select="selectCollection"
|
||||
@edit="openEditCalendar"
|
||||
@toggle-visibility="toggleCalendarVisibility"
|
||||
/>
|
||||
@@ -227,12 +226,12 @@ watch(() => route.fullPath, async () => {
|
||||
:collections="collections"
|
||||
:selected-collection="selectedCollection"
|
||||
type="tasklist"
|
||||
@select="selectTaskList"
|
||||
@select="selectCollection"
|
||||
@edit="openEditTaskList"
|
||||
/>
|
||||
|
||||
<v-btn
|
||||
v-if="!isTaskView"
|
||||
v-if="!isTasksSection"
|
||||
variant="tonal"
|
||||
color="primary"
|
||||
block
|
||||
@@ -262,7 +261,7 @@ watch(() => route.fullPath, async () => {
|
||||
<input ref="fileInputRef" type="file" accept=".ics,text/calendar" multiple class="d-none" @change="onFilesSelected" />
|
||||
|
||||
<!-- Mini Calendar Widget -->
|
||||
<v-card v-if="!isTaskView" class="mt-4" variant="outlined">
|
||||
<v-card v-if="!isTasksSection" class="mt-4" variant="outlined">
|
||||
<v-card-text class="pa-2">
|
||||
<MiniCalendar v-model="currentDate" />
|
||||
</v-card-text>
|
||||
@@ -299,7 +298,7 @@ watch(() => route.fullPath, async () => {
|
||||
<v-progress-linear v-if="loading" indeterminate color="primary" />
|
||||
|
||||
<CalendarView
|
||||
v-if="!isTaskView"
|
||||
v-if="!isTasksSection"
|
||||
:view="calendarView"
|
||||
:current-date="currentDate"
|
||||
:calendars="calendars"
|
||||
@@ -307,7 +306,7 @@ watch(() => route.fullPath, async () => {
|
||||
:initial-agenda-view-span="agendaViewSpan"
|
||||
@event-click="editEvent"
|
||||
@date-click="createEventFromDate"
|
||||
@update:current-date="setCurrentDate"
|
||||
@update:current-date="selectDate"
|
||||
@update:days-span="setDaysViewSpan"
|
||||
@update:agenda-span="setAgendaViewSpan"
|
||||
/>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { useEntitiesStore } from '@ChronoManager/stores/entitiesStore'
|
||||
import { useServicesStore } from '@ChronoManager/stores/servicesStore'
|
||||
import { useImportStore } from '@ChronoManager/stores/importStore'
|
||||
import { EpochSpan } from '@/types/date'
|
||||
import type { ChronoSection } from '@/types'
|
||||
|
||||
type ChronoEntityProperties = EventObject | TaskObject
|
||||
|
||||
@@ -162,7 +163,7 @@ export const useChronoOperationsStore = defineStore('chronoOperationsStore', ()
|
||||
tasksLoaded.value = true
|
||||
}
|
||||
|
||||
async function initialize(viewMode: 'calendar' | 'tasks' = 'calendar') {
|
||||
async function initialize(section: ChronoSection = 'calendar') {
|
||||
loading.value = true
|
||||
try {
|
||||
if (!collectionsLoaded.value) {
|
||||
@@ -171,7 +172,7 @@ export const useChronoOperationsStore = defineStore('chronoOperationsStore', ()
|
||||
collectionsLoaded.value = true
|
||||
}
|
||||
|
||||
if (viewMode === 'tasks') {
|
||||
if (section === 'tasks') {
|
||||
await ensureTasksLoaded()
|
||||
}
|
||||
|
||||
|
||||
+15
-19
@@ -5,12 +5,13 @@ import { EntityObject } from '@ChronoManager/models/entity'
|
||||
import { EventObject } from '@ChronoManager/models/event'
|
||||
import { TaskObject } from '@ChronoManager/models/task'
|
||||
import type { ServiceObject } from '@ChronoManager/models/service'
|
||||
import type { ChronoSection } from '@/types'
|
||||
import { useChronoOperationsStore } from '@/stores/chronoOperationsStore'
|
||||
|
||||
export const useChronoUiStore = defineStore('chronoUiStore', () => {
|
||||
const operationsStore = useChronoOperationsStore()
|
||||
|
||||
const viewMode = ref<'calendar' | 'tasks'>('calendar')
|
||||
const section = ref<ChronoSection>('calendar')
|
||||
const currentDate = ref(new Date())
|
||||
const sidebarVisible = ref(true)
|
||||
const selectedCollection = shallowRef<CollectionObject | null>(null)
|
||||
@@ -24,22 +25,18 @@ export const useChronoUiStore = defineStore('chronoUiStore', () => {
|
||||
const collectionEditorMode = ref<'create' | 'edit'>('create')
|
||||
const collectionEditorType = ref<'calendar' | 'tasklist'>('calendar')
|
||||
|
||||
const isTaskView = computed(() => viewMode.value === 'tasks')
|
||||
const isTasksSection = computed(() => section.value === 'tasks')
|
||||
|
||||
function setViewMode(mode: 'calendar' | 'tasks') {
|
||||
viewMode.value = mode
|
||||
function selectSection(target: ChronoSection) {
|
||||
section.value = target
|
||||
}
|
||||
|
||||
function setCurrentDate(date: Date) {
|
||||
function selectDate(date: Date) {
|
||||
currentDate.value = new Date(date)
|
||||
}
|
||||
|
||||
function selectCalendar(calendar: CollectionObject) {
|
||||
selectedCollection.value = calendar
|
||||
}
|
||||
|
||||
function selectTaskList(list: CollectionObject) {
|
||||
selectedCollection.value = list
|
||||
function selectCollection(collection: CollectionObject) {
|
||||
selectedCollection.value = collection
|
||||
}
|
||||
|
||||
function openCollectionEditor(type: 'calendar' | 'tasklist') {
|
||||
@@ -193,8 +190,8 @@ export const useChronoUiStore = defineStore('chronoUiStore', () => {
|
||||
await operationsStore.finishImport(refresh)
|
||||
}
|
||||
|
||||
async function initialize(viewMode: 'calendar' | 'tasks' = 'calendar') {
|
||||
await operationsStore.initialize(viewMode)
|
||||
async function initialize(initialSection: ChronoSection = 'calendar') {
|
||||
await operationsStore.initialize(initialSection)
|
||||
if (selectedCollection.value && !operationsStore.collections.some(
|
||||
collection => collection.identifier === selectedCollection.value?.identifier,
|
||||
)) {
|
||||
@@ -203,7 +200,7 @@ export const useChronoUiStore = defineStore('chronoUiStore', () => {
|
||||
}
|
||||
|
||||
return {
|
||||
viewMode,
|
||||
section,
|
||||
currentDate,
|
||||
sidebarVisible,
|
||||
selectedCollection,
|
||||
@@ -216,11 +213,10 @@ export const useChronoUiStore = defineStore('chronoUiStore', () => {
|
||||
editingCollection,
|
||||
collectionEditorMode,
|
||||
collectionEditorType,
|
||||
isTaskView,
|
||||
setViewMode,
|
||||
setCurrentDate,
|
||||
selectCalendar,
|
||||
selectTaskList,
|
||||
isTasksSection,
|
||||
selectSection,
|
||||
selectDate,
|
||||
selectCollection,
|
||||
openCreateCalendar,
|
||||
openCreateTaskList,
|
||||
openEditCalendar,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
// Local UI-specific types
|
||||
export type ChronoSection = 'calendar' | 'tasks';
|
||||
export type CalendarView = 'days' | 'month' | 'agenda';
|
||||
|
||||
export interface ViewState {
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { EntityObject } from '@ChronoManager/models/entity'
|
||||
import type { EventObject } from '@ChronoManager/models/event'
|
||||
import type { EventMutationObject } from '@ChronoManager/models/event-mutation'
|
||||
import type { CalendarInstance } from '../types/instance'
|
||||
import type { VisibleDateRange } from '../types'
|
||||
import { parseCalendarDate, shiftLocalDays, startOfLocalDay } from './date'
|
||||
import { EpochSpan } from '@/types/date'
|
||||
|
||||
@@ -96,7 +95,7 @@ function materializeInstance(
|
||||
durationDays: number | null,
|
||||
recurring: boolean,
|
||||
mutation: EventMutationObject | undefined,
|
||||
range?: VisibleDateRange,
|
||||
range?: EpochSpan,
|
||||
): CalendarInstance | null {
|
||||
if (mutation?.mutationExclusion === true) return null
|
||||
|
||||
@@ -208,7 +207,7 @@ function expandWeekly(
|
||||
start: Date,
|
||||
durationMs: number,
|
||||
durationDays: number | null,
|
||||
range: VisibleDateRange,
|
||||
range: EpochSpan,
|
||||
mutations: Map<number, EventMutationObject>,
|
||||
): CalendarInstance[] {
|
||||
const pattern = (entity.properties as EventObject).pattern!
|
||||
@@ -227,13 +226,13 @@ function expandWeekly(
|
||||
|
||||
while (true) {
|
||||
const intervalWeekStart = shiftLocalDays(weekStart, week * interval * 7)
|
||||
if (intervalWeekStart.getTime() >= range.endMs) break
|
||||
if (intervalWeekStart.getTime() >= range.end) break
|
||||
|
||||
for (const weekday of weekdays) {
|
||||
const candidate = shiftLocalDays(intervalWeekStart, weekday - 1)
|
||||
const candidateMs = candidate.getTime()
|
||||
if (candidateMs < start.getTime()) continue
|
||||
if (candidateMs >= range.endMs) return instances
|
||||
if (candidateMs >= range.end) return instances
|
||||
if (concludesMs !== null && candidateMs > concludesMs) return instances
|
||||
|
||||
occurrenceCount += 1
|
||||
|
||||
Reference in New Issue
Block a user