Updated Toast alerts, progress mvp

• Updated:
- Toast alerts
This commit is contained in:
mgabdev 2020-12-07 23:39:13 -05:00
parent 5422c013e1
commit 05c5dcb581
28 changed files with 205 additions and 109 deletions

View File

@ -148,7 +148,6 @@ const fetchAccountFail = (id, error) => ({
type: ACCOUNT_FETCH_FAIL,
id,
error,
skipAlert: true,
})
/**
@ -178,12 +177,14 @@ const followAccountRequest = (id, locked) => ({
const followAccountSuccess = (relationship, alreadyFollowing) => ({
type: ACCOUNT_FOLLOW_SUCCESS,
showToast: true,
relationship,
alreadyFollowing,
})
const followAccountFail = (error, locked) => ({
type: ACCOUNT_FOLLOW_FAIL,
showToast: true,
error,
locked,
})
@ -210,12 +211,14 @@ const unfollowAccountRequest = (id) => ({
const unfollowAccountSuccess = (relationship, statuses) => ({
type: ACCOUNT_UNFOLLOW_SUCCESS,
showToast: true,
relationship,
statuses,
})
const unfollowAccountFail = (error) => ({
type: ACCOUNT_UNFOLLOW_FAIL,
showToast: true,
error,
})
@ -243,12 +246,14 @@ const blockAccountRequest = (id) => ({
const blockAccountSuccess = (relationship, statuses) => ({
type: ACCOUNT_BLOCK_SUCCESS,
showToast: true,
relationship,
statuses,
})
const blockAccountFail = (error) => ({
type: ACCOUNT_BLOCK_FAIL,
showToast: true,
error,
})
@ -274,11 +279,13 @@ const unblockAccountRequest = (id) => ({
const unblockAccountSuccess = (relationship) => ({
type: ACCOUNT_UNBLOCK_SUCCESS,
showToast: true,
relationship,
})
const unblockAccountFail = (error) => ({
type: ACCOUNT_UNBLOCK_FAIL,
showToast: true,
error,
})
@ -305,12 +312,14 @@ const muteAccountRequest = (id) => ({
const muteAccountSuccess = (relationship, statuses) => ({
type: ACCOUNT_MUTE_SUCCESS,
showToast: true,
relationship,
statuses,
})
const muteAccountFail = (error) => ({
type: ACCOUNT_MUTE_FAIL,
showToast: true,
error,
})
@ -336,11 +345,13 @@ const unmuteAccountRequest = (id) => ({
const unmuteAccountSuccess = (relationship) => ({
type: ACCOUNT_UNMUTE_SUCCESS,
showToast: true,
relationship,
})
const unmuteAccountFail = (error) => ({
type: ACCOUNT_UNMUTE_FAIL,
showToast: true,
error,
})
@ -377,6 +388,7 @@ const fetchFollowersSuccess = (id, accounts, next) => ({
const fetchFollowersFail = (id, error) => ({
type: FOLLOWERS_FETCH_FAIL,
showToast: true,
id,
error,
})
@ -419,6 +431,7 @@ const expandFollowersSuccess = (id, accounts, next) => ({
const expandFollowersFail = (id, error) => ({
type: FOLLOWERS_EXPAND_FAIL,
showToast: true,
id,
error,
})
@ -456,6 +469,7 @@ const fetchFollowingSuccess = (id, accounts, next) => ({
const fetchFollowingFail = (id, error) => ({
type: FOLLOWING_FETCH_FAIL,
showToast: true,
id,
error,
})
@ -498,6 +512,7 @@ const expandFollowingSuccess = (id, accounts, next) => ({
const expandFollowingFail = (id, error) => ({
type: FOLLOWING_EXPAND_FAIL,
showToast: true,
id,
error,
})
@ -575,6 +590,7 @@ const fetchFollowRequestsSuccess = (accounts, next) => ({
const fetchFollowRequestsFail = (error) => ({
type: FOLLOW_REQUESTS_FETCH_FAIL,
showToast: true,
error,
})
@ -610,6 +626,7 @@ const expandFollowRequestsSuccess = (accounts, next) => ({
const expandFollowRequestsFail = (error) => ({
type: FOLLOW_REQUESTS_EXPAND_FAIL,
showToast: true,
error,
})
@ -634,11 +651,13 @@ const authorizeFollowRequestRequest = (id) => ({
const authorizeFollowRequestSuccess = (id) => ({
type: FOLLOW_REQUEST_AUTHORIZE_SUCCESS,
showToast: true,
id,
})
const authorizeFollowRequestFail = (id, error) => ({
type: FOLLOW_REQUEST_AUTHORIZE_FAIL,
showToast: true,
id,
error,
})
@ -664,11 +683,13 @@ const rejectFollowRequestRequest = (id) => ({
const rejectFollowRequestSuccess = (id) => ({
type: FOLLOW_REQUEST_REJECT_SUCCESS,
showToast: true,
id,
})
const rejectFollowRequestFail = (id, error) => ({
type: FOLLOW_REQUEST_REJECT_FAIL,
showToast: true,
id,
error,
})

View File

@ -39,6 +39,7 @@ export const fetchBlocksSuccess = (accounts, next) => ({
export const fetchBlocksFail = (error) => ({
type: BLOCKS_FETCH_FAIL,
showToast: true,
error,
})
@ -75,5 +76,6 @@ export const expandBlocksSuccess = (accounts, next) => ({
export const expandBlocksFail = (error) => ({
type: BLOCKS_EXPAND_FAIL,
showToast: true,
error,
})

View File

@ -43,6 +43,7 @@ const fetchBookmarkedStatusesSuccess = (statuses, next) => ({
const fetchBookmarkedStatusesFail = (error) => ({
type: BOOKMARKED_STATUSES_FETCH_FAIL,
showToast: true,
error,
})
@ -81,5 +82,6 @@ const expandBookmarkedStatusesSuccess = (statuses, next) => ({
const expandBookmarkedStatusesFail = (error) => ({
type: BOOKMARKED_STATUSES_EXPAND_FAIL,
showToast: true,
error,
})

View File

@ -106,6 +106,7 @@ export const expandChatMessagesSuccess = (chatConversationId, chatMessages, next
export const expandChatMessagesFail = (chatConversationId, error, isLoadingMore) => ({
type: CHAT_CONVERSATION_MESSAGES_EXPAND_FAIL,
showToast: true,
chatConversationId,
error,
skipLoading: !isLoadingMore,

View File

@ -48,6 +48,7 @@ export const sendChatMessageSuccess = (chatMessage) => ({
const sendChatMessageFail = (error) => ({
type: CHAT_MESSAGES_SEND_FAIL,
showToast: true,
error,
})
@ -77,9 +78,11 @@ const deleteChatMessageRequest = (chatMessageId) => ({
const deleteChatMessageSuccess = () => ({
type: CHAT_MESSAGES_DELETE_SUCCESS,
showToast: true,
})
const deleteChatMessageFail = (error) => ({
type: CHAT_MESSAGES_DELETE_FAIL,
showToast: true,
error,
})

View File

@ -398,11 +398,13 @@ const submitComposeRequest = () => ({
const submitComposeSuccess = (status) => ({
type: COMPOSE_SUBMIT_SUCCESS,
showToast: true,
status,
})
const submitComposeFail = (error) => ({
type: COMPOSE_SUBMIT_FAIL,
showToast: true,
error,
})
@ -466,6 +468,7 @@ const uploadComposeSuccess = (media) => ({
const uploadComposeFail = (error) => ({
type: COMPOSE_UPLOAD_FAIL,
showToast: true,
error,
})
@ -496,6 +499,7 @@ const changeUploadComposeSuccess = (media) => ({
const changeUploadComposeFail = (error, decrement = false) => ({
type: COMPOSE_UPLOAD_CHANGE_FAIL,
error,
showToast: true,
decrement: decrement,
})

View File

@ -43,6 +43,7 @@ const fetchFavoritedStatusesSuccess = (statuses, next) => ({
const fetchFavoritedStatusesFail = (error) => ({
type: FAVORITED_STATUSES_FETCH_FAIL,
showToast: true,
error,
})
@ -81,5 +82,6 @@ const expandFavoritedStatusesSuccess = (statuses, next) => ({
const expandFavoritedStatusesFail = (error) => ({
type: FAVORITED_STATUSES_EXPAND_FAIL,
showToast: true,
error,
})
})

View File

@ -30,8 +30,8 @@ const fetchFiltersSuccess = (filters) => ({
filters,
})
const fetchFiltersFail = (err) => ({
const fetchFiltersFail = (error) => ({
type: FILTERS_FETCH_FAIL,
err,
error,
skipAlert: true,
})

View File

@ -26,5 +26,6 @@ const fetchGroupCategoriesSuccess = (categories) => ({
const fetchGroupCategoriesFail = (error) => ({
type: GROUP_CATEGORIES_FETCH_FAIL,
showToast: true,
error,
})

View File

@ -100,11 +100,13 @@ const createGroupRequest = (id) => ({
const createSuccess = (group) => ({
type: GROUP_CREATE_SUCCESS,
showToast: true,
group,
})
const createFail = (error) => ({
type: GROUP_CREATE_FAIL,
showToast: true,
error,
})
@ -151,11 +153,13 @@ const updateGroupRequest = (id) => ({
const updateGroupSuccess = (group) => ({
type: GROUP_UPDATE_SUCCESS,
showToast: true,
group,
})
const updateGroupFail = (error) => ({
type: GROUP_UPDATE_FAIL,
showToast: true,
error,
})

View File

@ -153,6 +153,7 @@ const fetchGroupSuccess = (group) => ({
const fetchGroupFail = (groupId, error) => ({
type: GROUP_FETCH_FAIL,
showToast: true,
groupId,
error,
})
@ -233,6 +234,7 @@ export const fetchGroupsSuccess = (groups, tab) => ({
const fetchGroupsFail = (error, tab) => ({
type: GROUPS_FETCH_FAIL,
showToast: true,
error,
tab,
})
@ -273,6 +275,7 @@ const fetchGroupsByCategorySuccess = (groups, category) => ({
const fetchGroupsByCategoryFail = (error, category) => ({
type: GROUPS_BY_CATEGORY_FETCH_FAIL,
showToast: true,
error,
category,
})
@ -313,6 +316,7 @@ export const fetchGroupsByTagSuccess = (groups, tag) => ({
export const fetchGroupsByTagFail = (error, tag) => ({
type: GROUPS_BY_TAG_FETCH_FAIL,
showToast: true,
error,
tag,
})
@ -340,11 +344,13 @@ const joinGroupRequest = (groupId) => ({
const joinGroupSuccess = (relationship) => ({
type: GROUP_JOIN_SUCCESS,
showToast: true,
relationship
})
const joinGroupFail = (error) => ({
type: GROUP_JOIN_FAIL,
showToast: true,
error,
})
@ -371,11 +377,13 @@ const leaveGroupRequest = (groupId) => ({
const leaveGroupSuccess = (relationship) => ({
type: GROUP_LEAVE_SUCCESS,
showToast: true,
relationship,
})
const leaveGroupFail = (error) => ({
type: GROUP_LEAVE_FAIL,
showToast: true,
error,
})
@ -414,6 +422,7 @@ const fetchMembersSuccess = (groupId, accounts, next) => ({
const fetchMembersFail = (groupId, error) => ({
type: GROUP_MEMBERS_FETCH_FAIL,
showToast: true,
groupId,
error,
})
@ -458,6 +467,7 @@ const expandMembersSuccess = (groupId, accounts, next) => ({
const expandMembersFail = (groupId, error) => ({
type: GROUP_MEMBERS_EXPAND_FAIL,
showToast: true,
groupId,
error,
})
@ -497,6 +507,7 @@ const fetchRemovedAccountsSuccess = (groupId, accounts, next) => ({
const fetchRemovedAccountsFail = (groupId, error) => ({
type: GROUP_REMOVED_ACCOUNTS_FETCH_FAIL,
showToast: true,
groupId,
error,
})
@ -541,6 +552,7 @@ const expandRemovedAccountsSuccess = (groupId, accounts, next) => ({
const expandRemovedAccountsFail = (groupId, error) => ({
type: GROUP_REMOVED_ACCOUNTS_EXPAND_FAIL,
showToast: true,
groupId,
error,
})
@ -570,12 +582,14 @@ const removeRemovedAccountRequest = (groupId, accountId) => ({
const removeRemovedAccountSuccess = (groupId, accountId) => ({
type: GROUP_REMOVED_ACCOUNTS_REMOVE_SUCCESS,
showToast: true,
groupId,
accountId,
})
const removeRemovedAccountFail = (groupId, accountId, error) => ({
type: GROUP_REMOVED_ACCOUNTS_REMOVE_FAIL,
showToast: true,
groupId,
accountId,
error,
@ -606,12 +620,14 @@ const createRemovedAccountRequest = (groupId, accountId) => ({
const createRemovedAccountSuccess = (groupId, accountId) => ({
type: GROUP_REMOVED_ACCOUNTS_CREATE_SUCCESS,
showToast: true,
groupId,
accountId,
})
const createRemovedAccountFail = (groupId, accountId, error) => ({
type: GROUP_REMOVED_ACCOUNTS_CREATE_FAIL,
showToast: true,
groupId,
accountId,
error,
@ -643,12 +659,14 @@ const groupRemoveStatusRequest = (groupId, statusId) => ({
const groupRemoveStatusSuccess = (groupId, statusId) => ({
type: GROUP_REMOVE_STATUS_SUCCESS,
showToast: true,
groupId,
statusId,
})
const groupRemoveStatusFail = (groupId, statusId, error) => ({
type: GROUP_REMOVE_STATUS_FAIL,
showToast: true,
groupId,
statusId,
error,
@ -680,12 +698,14 @@ const updateRoleRequest = (groupId, accountId) => ({
const updateRoleSuccess = (groupId, accountId) => ({
type: GROUP_UPDATE_ROLE_SUCCESS,
showToast: true,
groupId,
accountId,
})
const updateRoleFail = (groupId, accountId, error) => ({
type: GROUP_UPDATE_ROLE_FAIL,
showToast: true,
groupId,
accountId,
error,
@ -760,6 +780,7 @@ const fetchJoinRequestsSuccess = (id, accounts, next) => ({
const fetchJoinRequestsFail = (id, error) => ({
type: GROUP_JOIN_REQUESTS_FETCH_FAIL,
showToast: true,
id,
error,
})
@ -802,6 +823,7 @@ const expandJoinRequestsSuccess = (id, accounts, next) => ({
const expandJoinRequestsFail = (id, error) => ({
type: GROUP_JOIN_REQUESTS_EXPAND_FAIL,
showToast: true,
id,
error,
})
@ -821,12 +843,14 @@ export const approveJoinRequest = (accountId, groupId) => (dispatch, getState) =
const approveJoinRequestSuccess = (accountId, groupId) => ({
type: GROUP_JOIN_REQUESTS_APPROVE_SUCCESS,
showToast: true,
accountId,
groupId,
})
const approveJoinRequestFail = (accountId, groupId, error) => ({
type: GROUP_JOIN_REQUESTS_APPROVE_FAIL,
showToast: true,
accountId,
groupId,
error,
@ -847,12 +871,14 @@ export const rejectJoinRequest = (accountId, groupId) => (dispatch, getState) =>
const rejectJoinRequestSuccess = (accountId, groupId) => ({
type: GROUP_JOIN_REQUESTS_REJECT_SUCCESS,
showToast: true,
accountId,
groupId,
})
const rejectJoinRequestFail = (accountId, groupId, error) => ({
type: GROUP_JOIN_REQUESTS_REJECT_FAIL,
showToast: true,
accountId,
groupId,
error,
@ -881,12 +907,14 @@ const pinGroupStatusRequest = (groupId) => ({
const pinGroupStatusSuccess = (groupId, statusId) => ({
type: GROUP_PIN_STATUS_SUCCESS,
showToast: true,
groupId,
statusId,
})
const pinGroupStatusFail = (groupId, statusId, error) => ({
type: GROUP_PIN_STATUS_FAIL,
showToast: true,
groupId,
statusId,
error,
@ -915,12 +943,14 @@ const unpinGroupStatusRequest = (groupId) => ({
const unpinGroupStatusSuccess = (groupId, statusId) => ({
type: GROUP_UNPIN_STATUS_SUCCESS,
showToast: true,
groupId,
statusId,
})
const unpinGroupStatusFail = (groupId, statusId, error) => ({
type: GROUP_UNPIN_STATUS_FAIL,
showToast: true,
groupId,
statusId,
error,

View File

@ -557,6 +557,7 @@ const expandLikesSuccess = (statusId, accounts, next) => ({
const expandLikesFail = (statusId, error) => ({
type: LIKES_EXPAND_FAIL,
showToast: true,
statusId,
error,
})

View File

@ -109,6 +109,7 @@ const fetchListsSuccess = (lists) => ({
const fetchListsFail = (error) => ({
type: LISTS_FETCH_FAIL,
showToast: true,
error,
})
@ -169,11 +170,13 @@ export const createListRequest = () => ({
export const createListSuccess = (list) => ({
type: LIST_CREATE_SUCCESS,
showToast: true,
list,
})
export const createListFail = (error) => ({
type: LIST_CREATE_FAIL,
showToast: true,
error,
})
@ -201,11 +204,13 @@ export const updateListRequest = id => ({
export const updateListSuccess = list => ({
type: LIST_UPDATE_SUCCESS,
showToast: true,
list,
})
export const updateListFail = (id, error) => ({
type: LIST_UPDATE_FAIL,
showToast: true,
id,
error,
})
@ -234,11 +239,13 @@ export const deleteListRequest = (id) => ({
export const deleteListSuccess = (id) => ({
type: LIST_DELETE_SUCCESS,
showToast: true,
id,
})
export const deleteListFail = (id, error) => ({
type: LIST_DELETE_FAIL,
showToast: true,
id,
error,
})
@ -271,6 +278,7 @@ export const fetchListAccountsSuccess = (id, accounts, next) => ({
export const fetchListAccountsFail = (id, error) => ({
type: LIST_ACCOUNTS_FETCH_FAIL,
showToast: true,
id,
error,
})
@ -346,12 +354,14 @@ const addToListRequest = (listId, accountId) => ({
const addToListSuccess = (listId, accountId) => ({
type: LIST_EDITOR_ADD_SUCCESS,
showToast: true,
listId,
accountId,
})
const addToListFail = (listId, accountId, error) => ({
type: LIST_EDITOR_ADD_FAIL,
showToast: true,
listId,
accountId,
error,
@ -385,12 +395,14 @@ const removeFromListRequest = (listId, accountId) => ({
const removeFromListSuccess = (listId, accountId) => ({
type: LIST_EDITOR_REMOVE_SUCCESS,
showToast: true,
listId,
accountId,
})
const removeFromListFail = (listId, accountId, error) => ({
type: LIST_EDITOR_REMOVE_FAIL,
showToast: true,
listId,
accountId,
error,
@ -439,10 +451,11 @@ const fetchAccountListsSuccess = (id, lists) => ({
lists,
})
const fetchAccountListsFail = (id, err) => ({
const fetchAccountListsFail = (id, error) => ({
type: LIST_ADDER_LISTS_FETCH_FAIL,
showToast: true,
id,
err,
error,
})
/**

View File

@ -43,6 +43,7 @@ const fetchMutesSuccess = (accounts, next) => ({
const fetchMutesFail = (error) => ({
type: MUTES_FETCH_FAIL,
showToast: true,
error,
})
@ -79,6 +80,7 @@ const expandMutesSuccess = (accounts, next) => ({
export const expandMutesFail = (error) => ({
type: MUTES_EXPAND_FAIL,
showToast: true,
error,
})

View File

@ -218,6 +218,7 @@ const expandNotificationsSuccess = (notifications, next, isLoadingMore) => ({
const expandNotificationsFail = (error, isLoadingMore) => ({
type: NOTIFICATIONS_EXPAND_FAIL,
error,
showToast: true,
skipLoading: !isLoadingMore,
})

View File

@ -29,11 +29,13 @@ const voteRequest = () => ({
const voteSuccess = (poll) => ({
type: POLL_VOTE_SUCCESS,
showToast: true,
poll,
})
const voteFail = (error) => ({
type: POLL_VOTE_FAIL,
showToast: true,
error,
})

View File

@ -65,11 +65,13 @@ const submitReportRequest = () => ({
const submitReportSuccess = (report) => ({
type: REPORT_SUBMIT_SUCCESS,
showToast: true,
report,
})
const submitReportFail = (error) => ({
type: REPORT_SUBMIT_FAIL,
showToast: true,
error,
})

View File

@ -86,6 +86,7 @@ const fetchSearchSuccess = (results) => ({
const fetchSearchFail = (error) => ({
type: SEARCH_FETCH_FAIL,
showToast: true,
error,
})

View File

@ -107,10 +107,12 @@ const removeShortcutsRequest = () => ({
const removeShortcutsSuccess = (shortcutId) => ({
type: SHORTCUTS_REMOVE_SUCCESS,
showToast: true,
shortcutId,
})
const removeShortcutsFail = (error) => ({
type: SHORTCUTS_REMOVE_FAIL,
showToast: true,
error,
})

View File

@ -11,7 +11,7 @@ export const loadStatusRevisions = (statusId) => (dispatch, getState) => {
dispatch(loadStatusRevisionsRequest())
api(getState).get(`/api/v1/statuses/${statusId}/revisions`)
.then(res => dispatch(loadStatusRevisionsSuccess(res.data)))
.catch(() => dispatch(loadStatusRevisionsFail()))
.catch((error) => dispatch(loadStatusRevisionsFail(error)))
}
const loadStatusRevisionsRequest = () => ({
@ -23,7 +23,8 @@ const loadStatusRevisionsSuccess = (data) => ({
revisions: data,
})
const loadStatusRevisionsFail = () => ({
const loadStatusRevisionsFail = (error) => ({
type: STATUS_REVISIONS_LOAD_FAIL,
error: true,
})
showToast: true,
error,
})

View File

@ -250,6 +250,7 @@ const fetchCommentsSuccess = (id, descendants) => ({
const fetchCommentsFail = (id, error) => ({
type: COMMENTS_FETCH_FAIL,
showToast: true,
id,
error,
skipAlert: true,

View File

@ -180,6 +180,7 @@ const expandTimelineSuccess = (timeline, statuses, next, partial, isLoadingRecen
const expandTimelineFail = (timeline, error, isLoadingMore) => ({
type: TIMELINE_EXPAND_FAIL,
showToast: true,
timeline,
error,
skipLoading: !isLoadingMore,

View File

@ -1,8 +1,3 @@
import {
TOAST_TYPE_ERROR,
TOAST_TYPE_SUCCESS,
} from '../constants'
export const TOAST_SHOW = 'TOAST_SHOW'
export const TOAST_DISMISS = 'TOAST_DISMISS'
export const TOAST_CLEAR = 'TOAST_CLEAR'
@ -10,9 +5,9 @@ export const TOAST_CLEAR = 'TOAST_CLEAR'
/**
*
*/
export const dismissToast = (alert) => ({
export const dismissToast = (toastKey) => ({
type: TOAST_DISMISS,
alert,
toastKey,
})
/**
@ -25,17 +20,8 @@ export const clearToast = () => ({
/**
*
*/
export const showToast = (type, message) => ({
export const showToast = (toastType, toastData) => ({
type: TOAST_SHOW,
toastType: type,
message,
toastType,
toastData,
})
export const showToastError = (message) => {
return showToast(TOAST_TYPE_ERROR, message)
}
export const showToastSucess = (message) => {
console.log("showToastSucess:", message)
return showToast(TOAST_TYPE_SUCCESS, message)
}

View File

@ -44,11 +44,13 @@ const saveUserProfileInformationRequest = () => ({
const saveUserProfileInformationSuccess = (userProfileData) => ({
type: SAVE_USER_PROFILE_INFORMATION_FETCH_SUCCESS,
showToast: true,
userProfileData,
})
const saveUserProfileInformationFail = (error) => ({
type: SAVE_USER_PROFILE_INFORMATION_FETCH_FAIL,
showToast: true,
error,
})

View File

@ -8,60 +8,63 @@ import Toast from '../components/toast'
class ToastsContainer extends React.PureComponent {
handleOnDismiss = (key) => {
this.props.dispatch(dismissToast(key))
handleOnDismiss = (toastKey) => {
this.props.dispatch(dismissToast(toastKey))
}
render() {
// const { notifications } = this.props
const notifications = [
{
key: '1',
title: 'Error',
to: 'to',
image: 'https://gab.com/media/user/58077e8a49705.jpg',
message: 'Unable to follow @andrew',
date: new Date(),
isImageAccount: true,
},
{
key: '2',
title: 'Success',
to: 'to',
image: 'https://gab.com/media/user/58077e8a49705.jpg',
message: 'Your gab was posted. Click here to view',
date: new Date(),
isImageAccount: false,
},
{
key: '3',
title: '',
to: 'to',
image: 'https://gab.com/media/user/58077e8a49705.jpg',
message: 'Unable to follow @andrew',
date: new Date(),
isImageAccount: true,
},
{
key: '4',
title: '',
to: 'to',
image: 'https://gab.com/media/user/58077e8a49705.jpg',
message: 'Your gab was posted. Click here to view',
date: new Date(),
isImageAccount: false,
},
{
key: '5',
title: '',
to: 'to',
message: 'Your gab was deleted',
date: new Date(),
isImageAccount: false,
},
]
const { notifications } = this.props
const hasNotifications = Array.isArray(notifications) && notifications.length > 0
console.log("notifications:", notifications)
// const notifications = [
// {
// key: '1',
// title: 'Error',
// to: 'to',
// image: 'https://gab.com/media/user/58077e8a49705.jpg',
// message: 'Unable to follow @andrew',
// date: new Date(),
// isImageAccount: true,
// },
// {
// key: '2',
// title: 'Success',
// to: 'to',
// image: 'https://gab.com/media/user/58077e8a49705.jpg',
// message: 'Your gab was posted. Click here to view',
// date: new Date(),
// isImageAccount: false,
// },
// {
// key: '3',
// title: '',
// to: 'to',
// image: 'https://gab.com/media/user/58077e8a49705.jpg',
// message: 'Unable to follow @andrew',
// date: new Date(),
// isImageAccount: true,
// },
// {
// key: '4',
// title: '',
// to: 'to',
// image: 'https://gab.com/media/user/58077e8a49705.jpg',
// message: 'Your gab was posted. Click here to view',
// date: new Date(),
// isImageAccount: false,
// },
// {
// key: '5',
// title: '',
// to: 'to',
// message: 'Your gab was deleted',
// date: new Date(),
// isImageAccount: false,
// },
// ]
const hasNotifications = !!notifications && notifications.size > 0
const containerClasses = CX({
d: 1,
@ -80,17 +83,17 @@ class ToastsContainer extends React.PureComponent {
return (
<div className={containerClasses}>
{
!hasNotifications && notifications.map((notification) => (
hasNotifications && notifications.map((notification) => (
<Toast
onDismiss={this.handleOnDismiss}
key={notification.key}
id={notification.key}
title={notification.title}
to={notification.to}
image={notification.image}
message={notification.message}
date={notification.date}
isImageAccount={notification.isImageAccount}
id={notification.get('key')}
key={`toast-${notification.get('key')}`}
title={notification.get('title', '')}
to={notification.get('to', null)}
image={notification.get('image', null)}
message={notification.get('message', null)}
date={notification.get('date', null)}
isImageAccount={notification.get('isImageAccount', null)}
/>
))
}
@ -101,11 +104,9 @@ class ToastsContainer extends React.PureComponent {
}
const mapStateToProps = (state) => {
const notifications = getToasts(state)
if (!notifications) return {}
return { notifications }
}
const mapStateToProps = (state) => ({
notifications: state.get('toasts')
})
ToastsContainer.propTypes = {
notifications: PropTypes.array,

View File

@ -1,18 +1,27 @@
// import { showAlertForError } from '../actions/alerts';
import isObject from 'lodash.isobject'
import { showToast } from '../actions/toasts'
import {
TOAST_TYPE_ERROR,
TOAST_TYPE_SUCCESS,
} from '../constants'
const defaultFailSuffix = 'FAIL';
const defaultSuccessSuffix = 'SUCCESS'
const defaultFailSuffix = 'FAIL'
export default function errorsMiddleware() {
return ({ dispatch }) => next => action => {
// : todo : use skipAlert!
if (action.type && !action.skipAlert) {
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
return ({ dispatch }) => (next) => (action) => {
if (isObject(action) && action.type && action.showToast) {
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g')
const isSuccess = new RegExp(`${defaultSuccessSuffix}$`, 'g')
if (action.type.match(isFail)) {
// dispatch(showAlertForError(action.error));
}
dispatch(showToast(TOAST_TYPE_ERROR, action))
} else if (action.type.match(isSuccess)) {
dispatch(showToast(TOAST_TYPE_SUCCESS, action))
}
}
return next(action);
};
};
return next(action)
}
}

View File

@ -1,3 +1,4 @@
import isObject from 'lodash.isobject'
import { showLoading, hideLoading } from 'react-redux-loading-bar'
const defaultTypeSuffixes = ['PENDING', 'FULFILLED', 'REJECTED']
@ -5,8 +6,8 @@ const defaultTypeSuffixes = ['PENDING', 'FULFILLED', 'REJECTED']
export default function loadingBarMiddleware(config = {}) {
const promiseTypeSuffixes = config.promiseTypeSuffixes || defaultTypeSuffixes
return ({ dispatch }) => next => (action) => {
if (action.type && action.type.indexOf('TIMELINE') > -1) {
return ({ dispatch }) => (next) => (action) => {
if (isObject(action) && action.type && action.type.indexOf('TIMELINE') > -1) {
const [PENDING, FULFILLED, REJECTED] = promiseTypeSuffixes
const isPending = new RegExp(`${PENDING}$`, 'g')

View File

@ -10,13 +10,13 @@ const initialState = ImmutableList([])
export default function toasts(state = initialState, action) {
switch(action.type) {
case TOAST_SHOW:
return state.push(ImmutableMap({
return state.set(state.size, ImmutableMap({
key: state.size > 0 ? state.last().get('key') + 1 : 0,
message: action.message,
message: 'action.message',
type: action.toastType,
}))
case TOAST_DISMISS:
return state.filterNot(item => item.get('key') === action.toast.key)
return state.filterNot(item => item.get('key') === action.toastKey)
case TOAST_CLEAR:
return state.clear()
default: