refactor: remove redundant isRecurring property, use recurrenceRule instead
isRecurring was redundant since recurrenceRule as truthy/falsy check suffices. Removed from shared CalendarEvent type, Mongoose virtual, and all usages.
This commit is contained in:
@@ -203,7 +203,7 @@ const Calendar = () => {
|
||||
const occurrenceDate = getDateKey(new Date(event.occurrenceStart));
|
||||
|
||||
try {
|
||||
if (event.isRecurring) {
|
||||
if (event.recurrenceRule) {
|
||||
// Recurring event: use mode and occurrenceDate
|
||||
await EventService.delete(event.id, mode, occurrenceDate);
|
||||
// Reload events to reflect changes
|
||||
@@ -260,7 +260,7 @@ const Calendar = () => {
|
||||
<DeleteEventModal
|
||||
visible={deleteModalVisible}
|
||||
eventTitle={eventToDelete?.title || ""}
|
||||
isRecurring={eventToDelete?.isRecurring || false}
|
||||
isRecurring={!!eventToDelete?.recurrenceRule}
|
||||
onConfirm={handleDeleteConfirm}
|
||||
onCancel={handleDeleteCancel}
|
||||
/>
|
||||
|
||||
@@ -19,7 +19,7 @@ export const EventCard = ({ event, onEdit, onDelete }: EventCardProps) => {
|
||||
startTime={event.occurrenceStart}
|
||||
endTime={event.occurrenceEnd}
|
||||
description={event.description}
|
||||
isRecurring={event.isRecurring}
|
||||
isRecurring={!!event.recurrenceRule}
|
||||
>
|
||||
{/* Action buttons - TouchableOpacity with delayPressIn allows ScrollView to detect scroll gestures */}
|
||||
<View className="flex-row justify-end mt-3 gap-3">
|
||||
|
||||
@@ -2,22 +2,18 @@ import mongoose, { Schema, Document, Model } from "mongoose";
|
||||
import { CalendarEvent } from "@calchat/shared";
|
||||
import { IdVirtual } from "./types";
|
||||
|
||||
interface EventVirtuals extends IdVirtual {
|
||||
isRecurring: boolean;
|
||||
}
|
||||
|
||||
export interface EventDocument
|
||||
extends Omit<CalendarEvent, "id" | "isRecurring">,
|
||||
extends Omit<CalendarEvent, "id">,
|
||||
Document {
|
||||
toJSON(): CalendarEvent;
|
||||
}
|
||||
|
||||
const EventSchema = new Schema<
|
||||
EventDocument,
|
||||
Model<EventDocument, {}, {}, EventVirtuals>,
|
||||
Model<EventDocument, {}, {}, IdVirtual>,
|
||||
{},
|
||||
{},
|
||||
EventVirtuals
|
||||
IdVirtual
|
||||
>(
|
||||
{
|
||||
userId: {
|
||||
@@ -61,11 +57,6 @@ const EventSchema = new Schema<
|
||||
return this._id.toString();
|
||||
},
|
||||
},
|
||||
isRecurring: {
|
||||
get() {
|
||||
return !!this.recurrenceRule;
|
||||
},
|
||||
},
|
||||
},
|
||||
toJSON: {
|
||||
virtuals: true,
|
||||
|
||||
@@ -37,8 +37,8 @@ export class EventService {
|
||||
const allEvents = await this.eventRepo.findByUserId(userId);
|
||||
|
||||
// Separate recurring and non-recurring events
|
||||
const recurringEvents = allEvents.filter((e) => e.isRecurring);
|
||||
const nonRecurringEvents = allEvents.filter((e) => !e.isRecurring);
|
||||
const recurringEvents = allEvents.filter((e) => e.recurrenceRule);
|
||||
const nonRecurringEvents = allEvents.filter((e) => !e.recurrenceRule);
|
||||
|
||||
// Expand all events (recurring get multiple instances, non-recurring stay as-is)
|
||||
const expanded = expandRecurringEvents(
|
||||
@@ -90,7 +90,7 @@ export class EventService {
|
||||
}
|
||||
|
||||
// For non-recurring events, always delete completely
|
||||
if (!event.isRecurring || !event.recurrenceRule) {
|
||||
if (!event.recurrenceRule) {
|
||||
await this.eventRepo.delete(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export function expandRecurringEvents(
|
||||
// to find events that start before rangeStart but extend into the range
|
||||
const adjustedRangeStart = new Date(rangeStart.getTime() - duration);
|
||||
|
||||
if (!event.isRecurring || !event.recurrenceRule) {
|
||||
if (!event.recurrenceRule) {
|
||||
// Non-recurring event: add if it overlaps with the range
|
||||
if (endTime >= rangeStart && startTime <= rangeEnd) {
|
||||
expanded.push({
|
||||
|
||||
Reference in New Issue
Block a user