Skip to content

Commit

Permalink
Merge pull request #199 from Arnei/event-upload-progress-bar
Browse files Browse the repository at this point in the history
Add event upload progress
  • Loading branch information
Arnei authored Sep 14, 2023
2 parents a6e2763 + 621a532 commit 8caa17c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 13 deletions.
5 changes: 5 additions & 0 deletions app/src/actions/notificationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export const createNotification = (notification) => ({
payload: { notification, id: nextNotificationId++ },
});

export const createNotificationWithId = (notification, id) => ({
type: CREATE_NOTIFICATION,
payload: { notification, id: id },
});

export const removeNotification = (id) => ({
type: REMOVE_NOTIFICATION,
payload: { id },
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/shared/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Notifications = ({
onClick={() => closeNotification(notification.id)}
className="button-like-anchor fa fa-times close"
/>
<p>{t(notification.message)}</p>
<p>{t(notification.message, notification.parameter)}</p>
</div>
</li>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"SERIES_ADDED": "The series has been created",
"SERIES_NOT_SAVED": "The series could not be saved",
"EVENTS_CREATED": "The event has been created",
"EVENTS_UPLOAD_STARTED": "The event is being uploaded…",
"EVENTS_UPLOAD_STARTED": "The event is being uploaded… {{ progress }}%",
"EVENTS_NOT_CREATED": "The event could not be created",
"EVENTS_UPDATED_ALL": "All events have been successfully updated",
"EVENTS_NOT_UPDATED": "The event could not be saved",
Expand Down
15 changes: 15 additions & 0 deletions app/src/reducers/notificationReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ export const notifications = (state = initialState, action) => {
switch (type) {
case CREATE_NOTIFICATION: {
const { notification, id } = payload;
if (state.notifications.filter(e => e.id === id).length > 0) {
console.log("Notification with id: " + id + " already exists.")
return {
...state,
notifications: state.notifications.map((oldNotification) => {
if (oldNotification.id === id) {
return {
id: id,
...notification,
};
}
return oldNotification;
}),
};
}
return {
...state,
notifications: [
Expand Down
5 changes: 3 additions & 2 deletions app/src/selectors/notificationSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export const getNotifications = (state) => state.notifications.notifications;
export const getGlobalPositions = (state) =>
state.notifications.notificationPositionGlobal;

export const getNotificationById = (id) =>
createSelector(getNotifications, (notifications) =>
export const getNotificationById = createSelector(
getNotifications,
(notifications, id) =>
notifications.filter((notification) => notification.id === id)
);

Expand Down
24 changes: 17 additions & 7 deletions app/src/thunks/eventThunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import {
weekdays,
WORKFLOW_UPLOAD_ASSETS_NON_TRACK,
} from "../configs/modalConfig";
import { addNotification } from "./notificationThunks";
import { addNotification, addNotificationWithId } from "./notificationThunks";
import {
getAssetUploadOptions,
getSchedulingEditedEvents,
} from "../selectors/eventSelectors";
import { fetchSeriesOptions } from "./seriesThunks";
import { removeNotification } from "../actions/notificationActions";

// fetch events from server
export const fetchEvents = () => async (dispatch, getState) => {
Expand Down Expand Up @@ -438,13 +439,22 @@ export const postNewEvent = (values, metadataInfo, extendedMetadata) => async (
})
);

// Todo: process bar notification
// Process bar notification
var config = {
onUploadProgress: function(progressEvent) {
var percentCompleted = (progressEvent.loaded * 100) / progressEvent.total;
dispatch(addNotificationWithId(-42000, "success", "EVENTS_UPLOAD_STARTED", -1, { "progress": percentCompleted.toFixed(2) } ))
if (percentCompleted >= 100) {
dispatch(removeNotification(-42000))
}
},
headers: {
"Content-Type": "multipart/form-data",
},
};

axios
.post("/admin-ng/event/new", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
.post("/admin-ng/event/new", formData, config)
.then((response) => {
console.info(response);
dispatch(addNotification("success", "EVENTS_CREATED"));
Expand Down
19 changes: 17 additions & 2 deletions app/src/thunks/notificationThunks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
createNotification,
createNotificationWithId,
removeNotification,
} from "../actions/notificationActions";
import { getLastAddedNotification } from "../selectors/notificationSelector";
Expand All @@ -9,7 +10,7 @@ import {
ADMIN_NOTIFICATION_DURATION_WARNING,
} from "../configs/generalConfig";

export const addNotification = (type, key, duration, parameter, context) => (
export const addNotification = (type, key, duration, parameter, context, id) => (
dispatch,
getState
) => {
Expand Down Expand Up @@ -49,7 +50,12 @@ export const addNotification = (type, key, duration, parameter, context) => (
hidden: false,
context: context,
};
dispatch(createNotification(notification));
var dispatchedNotification;
if (!id) {
dispatchedNotification = dispatch(createNotification(notification));
} else {
dispatchedNotification = dispatch(createNotificationWithId(notification, id));
}

// Get newly created notification and its id
let latestNotification = getLastAddedNotification(getState());
Expand All @@ -65,4 +71,13 @@ export const addNotification = (type, key, duration, parameter, context) => (
latestNotification.duration
);
}

return dispatchedNotification.payload.id;
};

export const addNotificationWithId = (id, type, key, duration, parameter, context) => (
dispatch,
getState
) => {
dispatch(addNotification(type, key, duration, parameter, context, id))
}

0 comments on commit 8caa17c

Please sign in to comment.