-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apps/mobile): add toasts for all user-surfaceable actions
- Loading branch information
1 parent
4af59da
commit 9023d1d
Showing
9 changed files
with
239 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ComponentProps } from 'react'; | ||
import { BaseToast } from 'react-native-toast-message'; | ||
|
||
export const CustomToast = (props: ComponentProps<typeof BaseToast>) => { | ||
return ( | ||
<BaseToast | ||
{...props} | ||
style={{ borderLeftColor: 'transparent' }} | ||
contentContainerStyle={{ paddingHorizontal: 15 }} | ||
text1Style={{ | ||
fontSize: 15, | ||
fontWeight: '400', | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import { addListener, createListenerMiddleware } from '@reduxjs/toolkit'; | ||
import { CatApi } from '../services/CatApi'; | ||
import { AppDispatch, RootState } from '../store'; | ||
import { showToast } from '../thunks/showToast'; | ||
|
||
export const ToastMiddleware = createListenerMiddleware(); | ||
|
||
export const startAppListening = ToastMiddleware.startListening.withTypes< | ||
RootState, | ||
AppDispatch | ||
>(); | ||
|
||
export const addAppListener = addListener.withTypes<RootState, AppDispatch>(); | ||
|
||
const TITLE_SUCCESS = 'Success'; | ||
const TITLE_ERROR = 'Error'; | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.uploadImage.matchFulfilled, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `🩻 ${TITLE_SUCCESS}`, | ||
message: 'Image uploaded successfully', | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.uploadImage.matchRejected, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `🩻 ${TITLE_ERROR}`, | ||
message: [ | ||
'There was an error while uploading your image', | ||
action.error.message, | ||
].join('\n'), | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.deleteImage.matchFulfilled, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `🩻 ${TITLE_SUCCESS}`, | ||
message: 'Image deleted successfully', | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.deleteImage.matchRejected, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `🩻 ${TITLE_ERROR}`, | ||
message: [ | ||
'There was an error while deleting your image', | ||
action.error.message, | ||
].join('\n'), | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.upvoteImage.matchFulfilled, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `🔼 ${TITLE_SUCCESS}`, | ||
message: 'Your upvote was successful', | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.upvoteImage.matchRejected, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `🔼 ${TITLE_ERROR}`, | ||
message: [ | ||
'There was an error while sending your upvote', | ||
action.error.message, | ||
].join('\n'), | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.downvoteImage.matchFulfilled, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `🔽 ${TITLE_SUCCESS}`, | ||
message: 'Your downvote was successful', | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.downvoteImage.matchRejected, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `🔼 ${TITLE_ERROR}`, | ||
message: [ | ||
'There was an error while sending your downvote', | ||
action.error.message, | ||
].join('\n'), | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.favouriteImage.matchFulfilled, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `❤️ ${TITLE_SUCCESS}`, | ||
message: 'Favourited the kitty successfully', | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.favouriteImage.matchRejected, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `❤️ ${TITLE_ERROR}`, | ||
message: [ | ||
'There was an error while favouriting the image', | ||
action.error.message, | ||
].join('\n'), | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.unfavouriteImage.matchFulfilled, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `💔 ${TITLE_SUCCESS}`, | ||
message: 'Image unfavourited successfully', | ||
}) | ||
); | ||
}, | ||
}); | ||
|
||
startAppListening({ | ||
matcher: CatApi.endpoints.unfavouriteImage.matchRejected, | ||
effect: async (action, { dispatch }) => { | ||
await dispatch( | ||
showToast({ | ||
title: `❤️ ${TITLE_ERROR}`, | ||
message: [ | ||
'There was an error while unfavouriting the image', | ||
action.error.message, | ||
].join('\n'), | ||
}) | ||
); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Toast from 'react-native-toast-message'; | ||
import { createAppAsyncThunk } from '../overrides'; | ||
|
||
type ShowToastOptions = { | ||
title: string; | ||
message: string; | ||
}; | ||
|
||
export const showToast = createAppAsyncThunk( | ||
'app/showToast', | ||
async ({ title, message }: ShowToastOptions) => { | ||
Toast.show({ | ||
topOffset: 60, | ||
type: 'success', | ||
text1: title, | ||
text2: message, | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters