Handling progress delete event in UI

pull/1407/head
LASER-Yi 3 years ago
parent fe0a34aae5
commit 0031e69db6

@ -28,4 +28,4 @@ def show_progress(id, header, name, value, count):
def hide_progress(id): def hide_progress(id):
event_stream(type="progress", action="delete", payload={"id": id}) event_stream(type="progress", action="delete", payload=id)

@ -91,8 +91,8 @@ class SocketIOClient {
forIn(element, (ids, key) => { forIn(element, (ids, key) => {
ids = uniq(ids); ids = uniq(ids);
const action = handler[key as SocketIO.Action]; const action = handler[key];
if (action) { if (typeof action == "function") {
action(ids); action(ids);
} else if (anyAction === undefined) { } else if (anyAction === undefined) {
log("warning", "Unhandle action of SocketIO event", key, type); log("warning", "Unhandle action of SocketIO event", key, type);

@ -9,6 +9,7 @@ import {
siteAddNotifications, siteAddNotifications,
siteAddProgress, siteAddProgress,
siteInitializationFailed, siteInitializationFailed,
siteRemoveProgress,
siteUpdateOffline, siteUpdateOffline,
systemUpdateLanguagesAll, systemUpdateLanguagesAll,
systemUpdateSettings, systemUpdateSettings,
@ -72,6 +73,13 @@ export function createDefaultReducer(): SocketIO.Reducer[] {
reduxStore.dispatch(siteAddProgress(progress)); reduxStore.dispatch(siteAddProgress(progress));
} }
}, },
delete: (ids) => {
setTimeout(() => {
ids?.forEach((id) => {
reduxStore.dispatch(siteRemoveProgress(id));
});
}, 3 * 1000);
},
}, },
{ {
key: "series", key: "series",

@ -1,6 +1,4 @@
namespace SocketIO { namespace SocketIO {
type Action = "update" | "delete";
type EventType = NumEventType | NullEventType | SpecialEventType; type EventType = NumEventType | NullEventType | SpecialEventType;
type NumEventType = type NumEventType =
@ -25,18 +23,21 @@ namespace SocketIO {
type SpecialEventType = "message" | "progress"; type SpecialEventType = "message" | "progress";
type ReducerCreator<E extends EventType, T> = ValueOf< type ReducerCreator<E extends EventType, U, D = never> = ValueOf<
{ {
[P in E]: { [P in E]: {
key: P; key: P;
any?: () => void; any?: () => void;
} & Partial<Record<Action, ActionFn<T>>>; update?: ActionFn<T>;
delete?: ActionFn<D extends never ? T : D>;
} & LooseObject;
// TODO: Typing
} }
>; >;
type Event = { type Event = {
type: EventType; type: EventType;
action: Action; action: string;
payload: any; payload: any;
}; };
@ -46,9 +47,9 @@ namespace SocketIO {
| ReducerCreator<NumEventType, number> | ReducerCreator<NumEventType, number>
| ReducerCreator<NullEventType, null> | ReducerCreator<NullEventType, null>
| ReducerCreator<"message", string> | ReducerCreator<"message", string>
| ReducerCreator<"progress", CustomEvent.Progress>; | ReducerCreator<"progress", CustomEvent.Progress, string>;
type ActionRecord = OptionalRecord<EventType, OptionalRecord<Action, any[]>>; type ActionRecord = OptionalRecord<EventType, StrictObject<any[]>>;
namespace CustomEvent { namespace CustomEvent {
type Progress = ReduxStore.Progress; type Progress = ReduxStore.Progress;

@ -86,7 +86,7 @@ const ProgressToast: FunctionComponent<ProgressHolderProps> = ({
const remove = useCallback(() => removeProgress(id), [removeProgress, id]); const remove = useCallback(() => removeProgress(id), [removeProgress, id]);
useEffect(() => { useEffect(() => {
const handle = setTimeout(remove, 5 * 1000); const handle = setTimeout(remove, 10 * 1000);
return () => { return () => {
clearTimeout(handle); clearTimeout(handle);
}; };

Loading…
Cancel
Save