Skip to content

Commit 9a612d4

Browse files
committed
refactor(event): update event repository methods and remove unused React hook
- Refactored the LocalEventRepository to accept Schema_Event and optional parameters for editing and deleting events, improving flexibility. - Removed the useEventRepository React hook, simplifying the repository interface and reducing unnecessary complexity in the codebase. - Updated tests to reflect changes in the event editing process, ensuring consistency with the new method signatures.
1 parent 76cb0fe commit 9a612d4

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useMemo } from "react";
21
import { EventRepository } from "./event.repository.interface";
32
import { LocalEventRepository } from "./local.event.repository";
43
import { RemoteEventRepository } from "./remote.event.repository";
@@ -13,18 +12,3 @@ export function getEventRepository(sessionExists: boolean): EventRepository {
1312
? new RemoteEventRepository()
1413
: new LocalEventRepository();
1514
}
16-
17-
/**
18-
* React hook to get the appropriate event repository based on session state.
19-
* Memoizes the repository instance to avoid recreating on each render.
20-
* Note: This hook checks session state on mount. For sagas, use getEventRepository()
21-
* with the result of session.doesSessionExist().
22-
*/
23-
export function useEventRepository(): EventRepository {
24-
return useMemo(() => {
25-
// For React components, we'll default to local and let the component
26-
// handle session state changes. In practice, components should check
27-
// session state separately if needed.
28-
return new LocalEventRepository();
29-
}, []);
30-
}

packages/web/src/common/repositories/event/local.event.repository.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2-
CompassCoreEvent,
32
Event_Core,
43
Params_Events,
54
Payload_Order,
5+
Schema_Event,
66
} from "@core/types/event.types";
77
import dayjs from "@core/util/date/dayjs";
88
import {
@@ -204,8 +204,7 @@ describe("LocalEventRepository", () => {
204204
user: event.user,
205205
});
206206

207-
// createMockStandaloneEvent always generates _id and endDate at runtime
208-
await repository.edit("event-1", updatedEvent as CompassCoreEvent);
207+
await repository.edit("event-1", updatedEvent as Schema_Event, {});
209208

210209
const savedEvent = mockEvents.get("event-1");
211210
expect(savedEvent?.title).toBe("Updated Title");

packages/web/src/common/repositories/event/local.event.repository.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2-
CompassCoreEvent,
32
Event_Core,
43
Params_Events,
54
Payload_Order,
5+
RecurringEventUpdateScope,
66
Schema_Event,
77
} from "@core/types/event.types";
88
import {
@@ -39,13 +39,20 @@ export class LocalEventRepository implements EventRepository {
3939
};
4040
}
4141

42-
async edit(_id: string, event: CompassCoreEvent): Promise<void> {
42+
async edit(
43+
_id: string,
44+
event: Schema_Event,
45+
params: { applyTo?: RecurringEventUpdateScope },
46+
): Promise<void> {
4347
// For local repository, we just save the updated event
4448
// The applyTo parameter is not relevant for local storage
4549
await saveEventToIndexedDB(event as Event_Core);
4650
}
4751

48-
async delete(_id: string): Promise<void> {
52+
async delete(
53+
_id: string,
54+
applyTo?: RecurringEventUpdateScope,
55+
): Promise<void> {
4956
// For local repository, applyTo is not relevant
5057
await deleteEventFromIndexedDB(_id);
5158
}

0 commit comments

Comments
 (0)