Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly reject promises on server #4464

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/routes/admin/email/components/EmailUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ const EmailUsers = () => {
usePreparedEffect(
'fetchEmailUsers',
() =>
Promise.resolve([
Promise.all([
dispatch(fetchAllWithType(GroupType.Committee)),
dispatch(fetchAllWithType(GroupType.Grade)),
dispatch(fetch({ query })),
]),
[]
[query]
);

const columns = [
Expand Down
4 changes: 2 additions & 2 deletions app/routes/articles/components/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ const Overview = () => {
usePreparedEffect(
'fetchArticlesOverview',
() =>
Promise.resolve([
Promise.all([
dispatch(fetchPopular()),
dispatch(fetchAll({ next: false, query })),
]),
[]
[query]
);

const headlineEvents = articles.slice(0, HEADLINE_EVENTS);
Expand Down
14 changes: 7 additions & 7 deletions app/routes/bdb/components/BdbDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ const BdbDetail = () => {
usePreparedEffect(
'fetchBdbDetail',
() =>
companyId &&
Promise.all([
dispatch(fetchSemesters()).then(() => dispatch(fetchAdmin(companyId))),
companyId &&
dispatch(
fetchEventsForCompany({
endpoint: `/events/${queryString(companyId)}`,
queryString: queryString(companyId),
})
),
dispatch(
fetchEventsForCompany({
endpoint: `/events/${queryString(companyId)}`,
queryString: queryString(companyId),
})
),
]),
[companyId]
);
Expand Down
4 changes: 2 additions & 2 deletions app/routes/interestgroups/components/InterestGroupDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ const InterestGroupDetail = () => {
'fetchInterestGroupDetail',
() =>
groupId &&
Promise.resolve([
Promise.all([
dispatch(fetchGroup(groupId)),
loggedIn && dispatch(fetchAllMemberships(groupId)),
]),
[loggedIn]
[groupId, loggedIn]
);

return (
Expand Down
4 changes: 3 additions & 1 deletion app/routes/meetings/MeetingDetailWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const MeetingDetailWrapper = () => {
dispatch(answerMeetingInvitation(action, token));
}

return loggedIn ? dispatch(fetchMeeting(meetingId)) : Promise.resolve();
return loggedIn && meetingId
? dispatch(fetchMeeting(meetingId))
: Promise.resolve();
},
[meetingId, loggedIn, token, action]
);
Expand Down
6 changes: 1 addition & 5 deletions app/routes/overview/components/PublicFrontpage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ const PublicFrontpage = () => {

const dispatch = useAppDispatch();

usePreparedEffect(
'fetchIndex',
() => Promise.all([dispatch(fetchData())]),
[]
);
usePreparedEffect('fetchIndex', () => dispatch(fetchData()), []);

const pinned = frontpage[0];

Expand Down
2 changes: 1 addition & 1 deletion app/routes/pages/components/PageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const PageEditor = () => {

usePreparedEffect(
'fetchPageEdit',
() => !isNew && dispatch(fetchPage(pageSlug)),
() => !isNew && pageSlug && dispatch(fetchPage(pageSlug)),
[isNew, pageSlug]
);

Expand Down
1 change: 1 addition & 0 deletions app/routes/photos/components/GalleryDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const GalleryDetail = () => {
usePreparedEffect(
'fetchGalleryDetail',
() =>
galleryId &&
Promise.all([
dispatch(fetch(galleryId)).catch(),
dispatch(fetchGallery(galleryId)).catch(() =>
Expand Down
3 changes: 2 additions & 1 deletion app/routes/photos/components/GalleryPictureEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ const GalleryPictureEditModal = () => {
usePreparedEffect(
'fetchGalleryAndGalleryPicture',
() =>
galleryId &&
Promise.all([
dispatch(fetchGallery(galleryId)),
dispatch(fetchGalleryPicture(galleryId, pictureId)),
pictureId && dispatch(fetchGalleryPicture(galleryId, pictureId)),
]),
[galleryId, pictureId]
);
Expand Down
3 changes: 2 additions & 1 deletion app/routes/photos/components/GalleryPictureModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ const GalleryPictureModal = () => {
usePreparedEffect(
'fetchGalleryPicture',
() =>
galleryId &&
Promise.all([
dispatch(fetchGalleryPicture(galleryId, pictureId)),
dispatch(fetchGallery(galleryId)),
pictureId && dispatch(fetchGalleryPicture(galleryId, pictureId)),
]),
[]
);
Expand Down
6 changes: 5 additions & 1 deletion app/routes/polls/components/PollDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const PollDetail = () => {

const dispatch = useAppDispatch();

usePreparedEffect('fetchPoll', () => dispatch(fetchPoll(pollsId)), []);
usePreparedEffect(
'fetchPoll',
() => pollsId && dispatch(fetchPoll(pollsId)),
[]
);

const poll = useAppSelector((state) => selectPollById(state, pollsId));
const fetching = useAppSelector((state) => state.polls.fetching);
Expand Down
4 changes: 2 additions & 2 deletions app/routes/quotes/components/QuotePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ const QuotePage = () => {
usePreparedEffect(
'fetchQuotePage',
() =>
Promise.resolve([
Promise.all([
quoteId ? dispatch(fetchQuote(quoteId)) : dispatch(fetchAll({ query })),
dispatch(fetchEmojis()),
]),
[query]
[quoteId, query]
);

return (
Expand Down