show reload alert dialog
This commit is contained in:
1 parent
78ee7bcc76
commit
1cced07da9
3 files changed
+21
-25
No files matched your search
@@ -342,9 +342,13 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
const file = readJson(editor.path) as TreeModel;
|
||||
editor.data = b3util.createTreeData(file.root);
|
||||
editor.autoId = b3util.refreshTreeDataId(editor.data);
|
||||
editor.graph.changeData(editor.data);
|
||||
editor.graph.layout();
|
||||
restoreViewport();
|
||||
editor.unsave = false;
|
||||
updateState();
|
||||
if (editor.graph) {
|
||||
editor.graph.changeData(editor.data);
|
||||
editor.graph.layout();
|
||||
restoreViewport();
|
||||
}
|
||||
};
|
||||
|
||||
const checkSubtree = () => {
|
||||
|
||||
@@ -28,10 +28,10 @@ export const Workspace: FC = () => {
|
||||
edit: useWorkspace((state) => state.edit),
|
||||
editing: useWorkspace((state) => state.editing),
|
||||
editors: useWorkspace((state) => state.editors),
|
||||
modifiedEditors: useWorkspace((state) => state.modifiedEditors),
|
||||
fileTree: useWorkspace((state) => state.fileTree),
|
||||
find: useWorkspace((state) => state.find),
|
||||
init: useWorkspace((state) => state.init),
|
||||
modifiedTime: useWorkspace((state) => state.modifiedTime),
|
||||
isShowingSearch: useWorkspace((state) => state.isShowingSearch),
|
||||
onShowingSearch: useWorkspace((state) => state.onShowingSearch),
|
||||
openProject: useWorkspace((state) => state.openProject),
|
||||
@@ -96,17 +96,11 @@ export const Workspace: FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const editor = workspace.editing;
|
||||
if (editor && workspace.modifiedEditors.includes(editor)) {
|
||||
if (editor?.alertReload) {
|
||||
if (isShowingAlert) {
|
||||
return;
|
||||
}
|
||||
setShowingAlert(true);
|
||||
const modifiedEditors = workspace.modifiedEditors.filter((v) => v !== editor);
|
||||
console.log(
|
||||
"modified:",
|
||||
editor.path,
|
||||
modifiedEditors.map((v) => v.path)
|
||||
);
|
||||
const alert = modal.confirm({
|
||||
centered: true,
|
||||
content: (
|
||||
@@ -123,21 +117,21 @@ export const Workspace: FC = () => {
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
editor.alertReload = false;
|
||||
editor.dispatch("reload");
|
||||
alert.destroy();
|
||||
keysRef.current?.focus();
|
||||
setShowingAlert(false);
|
||||
useWorkspace.setState({ modifiedEditors: modifiedEditors });
|
||||
}}
|
||||
>
|
||||
{t("reload")}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
editor.alertReload = false;
|
||||
alert.destroy();
|
||||
keysRef.current?.focus();
|
||||
setShowingAlert(false);
|
||||
useWorkspace.setState({ modifiedEditors: modifiedEditors });
|
||||
}}
|
||||
>
|
||||
{t("cancel")}
|
||||
@@ -147,7 +141,7 @@ export const Workspace: FC = () => {
|
||||
),
|
||||
});
|
||||
}
|
||||
}, [workspace.modifiedEditors, workspace.editing]);
|
||||
}, [workspace.editing, workspace.modifiedTime]);
|
||||
|
||||
const showSaveDialog = (editor: EditorStore) => {
|
||||
if (isShowingAlert) {
|
||||
|
||||
@@ -51,6 +51,8 @@ export class EditorStore {
|
||||
dragDstId?: string;
|
||||
unsave: boolean = false;
|
||||
modifiedTime: number = Date.now();
|
||||
alertReload: boolean = false;
|
||||
|
||||
historyStack: NodeModel[] = [];
|
||||
historyIndex: number = 0;
|
||||
selectedId?: string | null;
|
||||
@@ -130,9 +132,10 @@ export type WorkspaceStore = {
|
||||
allFiles: Map<string, FileMeta>;
|
||||
fileTree?: FileTreeType;
|
||||
editors: EditorStore[];
|
||||
modifiedEditors: EditorStore[];
|
||||
editing?: EditorStore;
|
||||
|
||||
modifiedTime: number;
|
||||
|
||||
isShowingSearch: boolean;
|
||||
onShowingSearch: (isShowingSearch: boolean) => void;
|
||||
|
||||
@@ -392,6 +395,8 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
}
|
||||
},
|
||||
|
||||
modifiedTime: 0,
|
||||
|
||||
isShowingSearch: false,
|
||||
onShowingSearch: (isShowingSearch) => {
|
||||
set({ isShowingSearch });
|
||||
@@ -500,17 +505,10 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
} else {
|
||||
const fullpath = fs.realpathSync(`${workspace.workdir}/${filename}`);
|
||||
const editor = workspace.find(fullpath);
|
||||
if (
|
||||
editor &&
|
||||
editor.modifiedTime + 500 < fs.statSync(fullpath).mtimeMs &&
|
||||
!workspace.modifiedEditors.includes(editor)
|
||||
) {
|
||||
if (editor && editor.modifiedTime + 500 < fs.statSync(fullpath).mtimeMs) {
|
||||
if (editor.unsave) {
|
||||
const modifiedEditors = workspace.modifiedEditors;
|
||||
console.log("modified1:", editor.path, modifiedEditors);
|
||||
modifiedEditors.push(editor);
|
||||
set({ modifiedEditors: modifiedEditors });
|
||||
console.log("modified2:", editor.path, modifiedEditors);
|
||||
editor.alertReload = true;
|
||||
set({ modifiedTime: Date.now() });
|
||||
} else {
|
||||
editor.dispatch("reload");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user