Skip to content

Commit a5cecc9

Browse files
author
Nevo David
committed
feat: reload calendar modal
1 parent 048df4f commit a5cecc9

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

apps/frontend/src/components/launches/add.edit.model.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { TopTitle } from '@gitroom/frontend/components/launches/helpers/top.titl
3232
import { PickPlatforms } from '@gitroom/frontend/components/launches/helpers/pick.platform.component';
3333
import { ProvidersOptions } from '@gitroom/frontend/components/launches/providers.options';
3434
import { v4 as uuidv4 } from 'uuid';
35-
import useSWR, { useSWRConfig } from 'swr';
35+
import useSWR from 'swr';
3636
import { useToaster } from '@gitroom/react/toaster/toaster';
3737
import { UpDownArrow } from '@gitroom/frontend/components/launches/up.down.arrow';
3838
import { DatePicker } from '@gitroom/frontend/components/launches/helpers/date.picker';
@@ -53,10 +53,10 @@ export const AddEditModal: FC<{
5353
date: dayjs.Dayjs;
5454
integrations: Integrations[];
5555
reopenModal: () => void;
56+
mutate: () => void;
5657
}> = (props) => {
57-
const { date, integrations, reopenModal } = props;
58+
const { date, integrations, reopenModal, mutate } = props;
5859
const [dateState, setDateState] = useState(date);
59-
const { mutate } = useSWRConfig();
6060

6161
// hook to open a new modal
6262
const modal = useModals();
@@ -243,7 +243,7 @@ export const AddEditModal: FC<{
243243
await fetch(`/posts/${existingData.group}`, {
244244
method: 'DELETE',
245245
});
246-
mutate('/posts');
246+
mutate();
247247
modal.closeAll();
248248
return;
249249
}
@@ -321,7 +321,7 @@ export const AddEditModal: FC<{
321321

322322
existingData.group = uuidv4();
323323

324-
mutate('/posts');
324+
mutate();
325325
toaster.show(
326326
!existingData.integration
327327
? 'Added successfully'

apps/frontend/src/components/launches/calendar.context.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const CalendarContext = createContext({
3131
integrations: [] as Integrations[],
3232
trendings: [] as string[],
3333
posts: [] as Array<Post & { integration: Integration }>,
34+
reloadCalendarView: () => {/** empty **/},
3435
display: 'week',
3536
setFilters: (filters: {
3637
currentWeek: number;
@@ -175,6 +176,7 @@ export const CalendarWeekProvider: FC<{
175176
<CalendarContext.Provider
176177
value={{
177178
trendings,
179+
reloadCalendarView: swr.mutate,
178180
...filters,
179181
posts: isLoading ? [] : internalData,
180182
integrations,

apps/frontend/src/components/launches/calendar.tsx

+30-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
'use client';
22

3-
import React, { FC, Fragment, useCallback, useEffect, useMemo, useState } from 'react';
3+
import React, {
4+
FC,
5+
Fragment,
6+
useCallback,
7+
useEffect,
8+
useMemo,
9+
useState,
10+
} from 'react';
411
import {
512
Integrations,
613
useCalendar,
@@ -159,7 +166,14 @@ export const CalendarColumn: FC<{
159166
}> = (props) => {
160167
const { getDate, randomHour } = props;
161168
const user = useUser();
162-
const { integrations, posts, trendings, changeDate, display } = useCalendar();
169+
const {
170+
integrations,
171+
posts,
172+
trendings,
173+
changeDate,
174+
display,
175+
reloadCalendarView,
176+
} = useCalendar();
163177

164178
const toaster = useToaster();
165179
const modal = useModals();
@@ -168,15 +182,16 @@ export const CalendarColumn: FC<{
168182
const postList = useMemo(() => {
169183
return posts.filter((post) => {
170184
const pList = dayjs.utc(post.publishDate).local();
171-
const check = display === 'week'
172-
? pList.isSameOrAfter(getDate.startOf('hour')) && pList.isBefore(getDate.endOf('hour'))
173-
: pList.format('DD/MM/YYYY') === getDate.format('DD/MM/YYYY');
185+
const check =
186+
display === 'week'
187+
? pList.isSameOrAfter(getDate.startOf('hour')) &&
188+
pList.isBefore(getDate.endOf('hour'))
189+
: pList.format('DD/MM/YYYY') === getDate.format('DD/MM/YYYY');
174190

175191
return check;
176192
});
177193
}, [posts, display, getDate]);
178194

179-
180195
const canBeTrending = useMemo(() => {
181196
return !!trendings.find((trend) => {
182197
return dayjs
@@ -282,6 +297,7 @@ export const CalendarColumn: FC<{
282297
<ExistingDataContextProvider value={data}>
283298
<AddEditModal
284299
reopenModal={editPost(post)}
300+
mutate={reloadCalendarView}
285301
integrations={integrations
286302
.slice(0)
287303
.filter((f) => f.id === data.integration)
@@ -308,6 +324,7 @@ export const CalendarColumn: FC<{
308324
children: (
309325
<AddEditModal
310326
integrations={integrations.slice(0).map((p) => ({ ...p }))}
327+
mutate={reloadCalendarView}
311328
date={
312329
randomHour ? getDate.hour(Math.floor(Math.random() * 24)) : getDate
313330
}
@@ -368,11 +385,15 @@ export const CalendarColumn: FC<{
368385
))}
369386
</div>
370387
{!isBeforeNow && (
371-
<div className="pb-[2.5px] px-[5px] flex-1 flex" onClick={integrations.length ? addModal : addProvider}>
388+
<div
389+
className="pb-[2.5px] px-[5px] flex-1 flex"
390+
onClick={integrations.length ? addModal : addProvider}
391+
>
372392
<div
373393
className={clsx(
374-
display === 'month' ? 'flex-1 min-h-[40px] w-full' :
375-
!postList.length
394+
display === 'month'
395+
? 'flex-1 min-h-[40px] w-full'
396+
: !postList.length
376397
? 'h-full w-full absolute left-0 top-0 p-[5px]'
377398
: 'min-h-[40px] w-full',
378399
'flex items-center justify-center cursor-pointer pb-[2.5px]'

0 commit comments

Comments
 (0)