Skip to content

Commit

Permalink
Corrected loading state on Activities, corrected loading more button …
Browse files Browse the repository at this point in the history
…behaviour
  • Loading branch information
mikozet committed Aug 13, 2023
1 parent 8858798 commit c6071df
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 65 deletions.
34 changes: 14 additions & 20 deletions src/store/activity/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { formatCirclesValue } from '~/utils/format';

const { ActivityTypes, ActivityFilterTypes } = core.activity;

export const PAGE_SIZE = 10;
export const PAGE_SIZE = 2;

export function initializeActivities() {
const lastSeenAt = getLastSeen();
Expand Down Expand Up @@ -194,6 +194,19 @@ export function checkFinishedActivities({
}
}
setLastReceivedTransaction(DateTime.now().toISO());

if (
`/profile/${mutualActivities.mutualAddress}` ===
window.location.pathname
) {
dispatch(
loadMoreActivitiesMutual(mutualActivities.mutualAddress, {
fromOffsetZero: true,
withLoader: false,
liveRefresh: true,
}),
);
}
}

dispatch({
Expand All @@ -204,19 +217,6 @@ export function checkFinishedActivities({
lastTimestamp,
},
});

if (
`/profile/${mutualActivities.mutualAddress}` ===
window.location.pathname
) {
dispatch(
loadMoreActivitiesMutual(mutualActivities.mutualAddress, {
fromOffsetZero: true,
withLoader: false,
liveRefresh: true,
}),
);
}
} catch {
dispatch({
type: ActionTypes.ACTIVITIES_UPDATE_ERROR,
Expand Down Expand Up @@ -350,9 +350,3 @@ export function resetActivities({ isClearingStorage = true } = {}) {
type: ActionTypes.ACTIVITIES_RESET,
};
}

export function resetMutualActivities() {
return {
type: ActionTypes.ACTIVITIES_MUTUAL_RESET,
};
}
61 changes: 17 additions & 44 deletions src/store/activity/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DateTime } from 'luxon';

import core from '~/services/core';
import web3 from '~/services/web3';
import { PAGE_SIZE } from '~/store/activity/actions';
import ActionTypes from '~/store/activity/types';

// Every item in the activities list has an unique hash identifier
Expand All @@ -21,8 +22,7 @@ export const CATEGORIES = [
const initialStateCategory = {
activities: [],
isError: false,
isLoading: false,
isLoadingMore: false,
isLoadingMore: true,
isMoreAvailable: true,
lastTimestamp: 0,
lastUpdatedAt: null,
Expand Down Expand Up @@ -151,31 +151,23 @@ const activityReducer = (state = initialState, action) => {
},
});
case ActionTypes.ACTIVITIES_LOAD_MORE_SUCCESS: {
// Nothing more to add ..
if (action.meta.activities.length === 0) {
return update(state, {
categories: {
[action.meta.category]: {
isLoadingMore: { $set: false },
isMoreAvailable: { $set: false },
},
},
});
}

// Add new activities
const newActivities = mergeActivities(
state.categories[action.meta.category].activities,
action.meta.activities,
);

// Update offset and add new objects
return update(state, {
categories: {
[action.meta.category]: {
activities: { $set: newActivities },
isLoadingMore: { $set: false },
offset: { $set: action.meta.offset },
...(action.meta.activities.length < PAGE_SIZE
? { isMoreAvailable: { $set: false } }
: {}),
activities: { $set: newActivities },
...(action.meta.activities.length >= PAGE_SIZE
? { offset: { $set: action.meta.offset } }
: {}),
},
},
});
Expand All @@ -196,28 +188,20 @@ const activityReducer = (state = initialState, action) => {
},
});
case ActionTypes.ACTIVITIES_MUTUAL_LOAD_MORE_SUCCESS: {
// Nothing more to add ..
if (action.meta.activities.length === 0) {
return update(state, {
mutualActivities: {
isLoadingMore: { $set: false },
isMoreAvailable: { $set: false },
},
});
}

// Add new activities
const newActivities = mergeActivities(
state.mutualActivities.activities,
action.meta.activities,
);

// Update offset and add new objects
return update(state, {
mutualActivities: {
activities: { $set: newActivities },
isLoadingMore: { $set: false },
offset: { $set: action.meta.offset },
...(action.meta.activities.length < PAGE_SIZE
? { isMoreAvailable: { $set: false } }
: {}),
lastUpdatedAt: { $set: DateTime.local().toISO() },
lastTimestamp: { $set: action.meta.lastTimestamp },
},
Expand All @@ -234,36 +218,25 @@ const activityReducer = (state = initialState, action) => {
return update(state, {
categories: {
[action.meta.category]: {
isLoading: { $set: true },
isError: { $set: false },
},
},
});
case ActionTypes.ACTIVITIES_UPDATE_SUCCESS: {
// Nothing to add .. array is empty
if (action.meta.activities.length === 0) {
return update(state, {
categories: {
[action.meta.category]: {
isLoading: { $set: false },
lastUpdatedAt: { $set: DateTime.local().toISO() },
},
},
});
}

// Add new activities
const newActivities = mergeActivities(
state.categories[action.meta.category].activities,
action.meta.activities,
);

// Update timestamps and add new objects
return update(state, {
categories: {
[action.meta.category]: {
activities: { $set: newActivities },
isLoading: { $set: false },
...(action.meta.activities.length < PAGE_SIZE
? { isMoreAvailable: { $set: false } }
: {}),
isLoadingMore: { $set: false },
lastTimestamp: { $set: action.meta.lastTimestamp },
lastUpdatedAt: { $set: DateTime.local().toISO() },
},
Expand All @@ -274,7 +247,7 @@ const activityReducer = (state = initialState, action) => {
return update(state, {
categories: {
[action.meta.category]: {
isLoading: { $set: false },
isLoadingMore: { $set: false },
isError: { $set: true },
},
},
Expand Down
1 change: 0 additions & 1 deletion src/store/activity/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default createTypes(
'ACTIVITIES_LOAD_MORE_ERROR',
'ACTIVITIES_LOAD_MORE_SUCCESS',
'ACTIVITIES_MUTUAL_ADDRESS_UPDATE',
'ACTIVITIES_MUTUAL_INITIALIZE',
'ACTIVITIES_MUTUAL_LOAD_MORE',
'ACTIVITIES_MUTUAL_LOAD_MORE_ERROR',
'ACTIVITIES_MUTUAL_LOAD_MORE_SUCCESS',
Expand Down
2 changes: 2 additions & 0 deletions src/utils/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function translateErrorForUser(error) {
} else if (error.code == ErrorCodes.SAFE_NOT_FOUND) {
// error: `Could not find Safe with address ${safeAddress}`,
text = error.message;
} else if (error.code == ErrorCodes.INVALID_OPTIONS) {
text = `${error.message}. ${translate('ErrorCodes.GeneralErrorMessage')}`;
} else {
text = `${error.message}. ${translate('ErrorCodes.GeneralErrorMessage')}`;
}
Expand Down

0 comments on commit c6071df

Please sign in to comment.