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 all commits
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
2 changes: 1 addition & 1 deletion app/components/HeaderNotifications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const NotificationsDropdown = () => {
usePreparedEffect(
'fetchNotificationDropdownData',
() =>
Promise.all([
Promise.allSettled([
dispatch(fetchNotificationFeed()),
dispatch(fetchNotificationData()),
]),
Expand Down
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.allSettled([
dispatch(fetchAllWithType(GroupType.Committee)),
dispatch(fetchAllWithType(GroupType.Grade)),
dispatch(fetch({ query })),
]),
[]
[query]
);

const columns = [
Expand Down
2 changes: 1 addition & 1 deletion app/routes/admin/groups/components/GroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const GroupPage = () => {
usePreparedEffect(
'fetchAllGroups',
() =>
Promise.all([
Promise.allSettled([
dispatch(fetchAll()),
groupId && dispatch(fetchGroup(groupId)),
]),
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.allSettled([
dispatch(fetchPopular()),
dispatch(fetchAll({ next: false, query })),
]),
[]
[query]
);

const headlineEvents = articles.slice(0, HEADLINE_EVENTS);
Expand Down
6 changes: 5 additions & 1 deletion app/routes/bdb/components/AddSemester.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ const AddSemester = () => {

usePreparedEffect(
'fetchAddSemester',
() => Promise.all([dispatch(fetchSemesters()), dispatch(fetchAllAdmin())]),
() =>
Promise.allSettled([
dispatch(fetchSemesters()),
dispatch(fetchAllAdmin()),
]),
[companyId]
);

Expand Down
16 changes: 8 additions & 8 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',
() =>
Promise.all([
companyId &&
Promise.allSettled([
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
2 changes: 1 addition & 1 deletion app/routes/company/components/CompanyDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const CompanyDetail = () => {
'fetchDetailedCompany',
() =>
companyId &&
Promise.all([
Promise.allSettled([
dispatch(fetch(companyId)),
dispatch(
fetchEventsForCompany({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ const CompanyInterestList = () => {

usePreparedEffect(
'fetchCompanyInterestList',
() => Promise.all([dispatch(fetchAll()), dispatch(fetchSemesters())]),
() =>
Promise.allSettled([dispatch(fetchAll()), dispatch(fetchSemesters())]),
[]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ const CompanyInterestPage = () => {
usePreparedEffect(
'fetchCompanyInterestPage',
() => {
Promise.all([
Promise.allSettled([
edit && dispatch(fetchSemesters()),
edit &&
companyInterestId &&
Expand Down
2 changes: 1 addition & 1 deletion app/routes/contact/components/ContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ContactForm = () => {
usePreparedEffect(
'fetchGroups',
() =>
Promise.all([
Promise.allSettled([
dispatch(fetchAllWithType(GroupType.Committee)),
// The revue board group does not exist in the local dev environment.
// It should be added to the fixtures, so that the propagateError flag can be removed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Statistics = () => {
usePreparedEffect(
'fetchStatisticsGroups',
() =>
Promise.all([
Promise.allSettled([
dispatch(fetchAllWithType(GroupType.Committee)),
dispatch(fetchAllWithType(GroupType.Revue)),
]),
Expand Down
2 changes: 1 addition & 1 deletion app/routes/events/components/EventEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const EventEditor = () => {
usePreparedEffect(
'fetchEventEdit',
() =>
Promise.all([
Promise.allSettled([
eventIdOrSlug && dispatch(fetchEvent(eventIdOrSlug)),
dispatch(fetchImageGallery()),
]),
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.allSettled([
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
2 changes: 1 addition & 1 deletion app/routes/overview/components/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Overview = () => {
usePreparedEffect(
'fetchIndex',
() =>
Promise.all([
Promise.allSettled([
loggedIn && shouldFetchQuote && dispatch(fetchRandomQuote()),
dispatch(fetchReadmes(loggedIn ? 4 : 2)),
dispatch(fetchData()),
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
3 changes: 2 additions & 1 deletion app/routes/photos/components/GalleryDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ const GalleryDetail = () => {
usePreparedEffect(
'fetchGalleryDetail',
() =>
Promise.all([
galleryId &&
Promise.allSettled([
dispatch(fetch(galleryId)).catch(),
dispatch(fetchGallery(galleryId)).catch(() =>
dispatch(fetchGalleryMetadata(galleryId))
Expand Down
2 changes: 1 addition & 1 deletion app/routes/photos/components/GalleryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const GalleryEditor = () => {
() =>
!isNew &&
galleryId &&
Promise.all([
Promise.allSettled([
dispatch(fetch(Number(galleryId))),
dispatch(fetchGallery(galleryId)),
]),
Expand Down
5 changes: 3 additions & 2 deletions 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',
() =>
Promise.all([
galleryId &&
Promise.allSettled([
dispatch(fetchGallery(galleryId)),
dispatch(fetchGalleryPicture(galleryId, pictureId)),
pictureId && dispatch(fetchGalleryPicture(galleryId, pictureId)),
]),
[galleryId, pictureId]
);
Expand Down
5 changes: 3 additions & 2 deletions 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',
() =>
Promise.all([
dispatch(fetchGalleryPicture(galleryId, pictureId)),
galleryId &&
Promise.allSettled([
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.allSettled([
quoteId ? dispatch(fetchQuote(quoteId)) : dispatch(fetchAll({ query })),
dispatch(fetchEmojis()),
]),
[query]
[quoteId, query]
);

return (
Expand Down
2 changes: 1 addition & 1 deletion app/routes/users/components/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const UserProfile = () => {
usePreparedEffect(
'fetchUserProfile',
() =>
Promise.all([
Promise.allSettled([
dispatch(fetchAllWithType(GroupType.Grade)),
isCurrentUser && dispatch(fetchPrevious()),
isCurrentUser && dispatch(fetchUpcoming()),
Expand Down
2 changes: 1 addition & 1 deletion app/routes/users/components/UserSettingsNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const UserSettingsNotifications = () => {
usePreparedEffect(
'fetchUserSettingsNotifications',
() =>
Promise.all([
Promise.allSettled([
dispatch(fetchNotificationAlternatives()),
dispatch(fetchNotificationSettings()),
]),
Expand Down
2 changes: 1 addition & 1 deletion app/routes/users/components/UserSettingsOAuth2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const UserSettingsOAuth2 = () => {
usePreparedEffect(
'fetchUserSettingsOAuth2',
() =>
Promise.all([
Promise.allSettled([
dispatch(fetchOAuth2Applications()),
dispatch(fetchOAuth2Grants()),
]),
Expand Down