Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
console, admin
Browse files Browse the repository at this point in the history
  • Loading branch information
botlikes456 committed Jan 25, 2021
1 parent 68d7554 commit b2f637e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/pages/console/connected-space/subject-view/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface SpaceDefs {

export interface SubjectContext {
defs: SpaceDefs;
save: () => void;
save: (immediately?: boolean) => Promise<void>;
}

const Context = React.createContext<SubjectContext>({} as SubjectContext);
Expand Down Expand Up @@ -89,18 +89,27 @@ export const SubjectContextProvider = (props: {
setDefs(computeSpaceDefs(available, space));
}, [ space, available ]);

const save = () => {
const save = async (immediately: boolean = false) => {
if (saveTimeoutHandle) {
clearTimeout(saveTimeoutHandle);
}
setSaveTimeoutHandle(setTimeout(async () => {
if (immediately) {
setSaveTimeoutHandle(null);
if (doSave) {
await doSave(subject);
} else {
await saveSubject(subject);
}
}, 3000));
} else {
setSaveTimeoutHandle(setTimeout(async () => {
setSaveTimeoutHandle(null);
if (doSave) {
await doSave(subject);
} else {
await saveSubject(subject);
}
}, 3000));
}
};

return <Context.Provider value={{ defs, save }}>{children}</Context.Provider>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ export const Chart = (props: {
event.stopPropagation();
setSettingsVisible(true);
};
const onCloseSettings = () => {
const onCloseSettings = async () => {
await saveSubject(true);
setSettingsVisible(false);
saveSubject();
};
const onDeleteConfirmClicked = () => {
onDeleteChart(chart);
Expand Down

0 comments on commit b2f637e

Please sign in to comment.