Skip to content

Commit

Permalink
fix: webdav file error
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyxh committed May 8, 2024
1 parent 58933bd commit 1fff691
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/filehandle/WebdavFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class WebdavFileSystemFileHandle implements FileSystemFileHandle {

this.fullPath = fullPath;
}

createSyncAccessHandle(): Promise<FileSystemSyncAccessHandle> {
throw new Error('Method not implemented.');
}
Expand Down
16 changes: 15 additions & 1 deletion src/filehandle/components/FileContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ interface IFileContentProps {
const FileContent: React.FC<IFileContentProps> = (props) => {
const { modal, message } = App.useApp();

const { webdavs, setWebdavs } = useUserStore();

const {
current,
children,
Expand Down Expand Up @@ -361,14 +363,26 @@ const FileContent: React.FC<IFileContentProps> = (props) => {
};

const handleDeleteFile = () => {
const names = selection.slice(0).map((file) => file.name);
const _selection = selection.slice(0);

const names = _selection
.filter((file) => !file.remote)
.map((file) => file.name);

modal.confirm({
title: '温馨提示',
icon: <ExclamationCircleFilled />,
content: '您确认要删除这个文件吗?',
async onOk() {
try {
let _webdavs = webdavs.slice(0);
selection.map((file) => {
if (file.remote) {
_webdavs = _webdavs.filter((webdav) => webdav.name !== file.name);
}
});
setWebdavs(_webdavs);

await Promise.all(names.map((name) => remove(name)));
} catch (err) {
message.error((err as Error).message);
Expand Down
38 changes: 25 additions & 13 deletions src/filehandle/md_editor/component/MDEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,38 @@ const MDEditor = forwardRef<IMDEditorExpose, IMDEditorProps>(
const editorRef = useRef<Editor>();
const mdStringRef = useRef('');

const creatingRef = useRef(false);

useImperativeHandle(ref, () => ({
getMarkdown() {
return editorRef.current ? getMDString(editorRef.current.ctx) : '';
}
}));

useMemo(() => {
(async () => {
if (editorRef.current) {
await editorRef.current.destroy(true);
}

createMDEditor(editorContainerRef.current!, markdown, onUpdate).then(
(value) => {
editorRef.current = value;
mdStringRef.current = markdown;
onChanged(false);
}
);
})();
if (creatingRef.current) {
return void 0;
}

if (editorRef.current) {
editorRef.current.destroy(true);
}

creatingRef.current = true;

createMDEditor(editorContainerRef.current!, markdown, onUpdate)
.then((value) => {
editorRef.current = value;
mdStringRef.current = markdown;
onChanged(false);
})
.finally(() => {
creatingRef.current = false;
});

return () => {
editorRef.current?.destroy(true);
};
}, [markdown]);

function onUpdate(md: string) {
Expand Down
6 changes: 6 additions & 0 deletions src/store/useUserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface UserState {

export interface UserActions {
addWebdav(webdav: WebdavInfo): void;
setWebdavs(webdavs: WebdavInfo[]): void;
}

const useAppStore = create<UserState & UserActions>((set) => ({
Expand All @@ -29,6 +30,11 @@ const useAppStore = create<UserState & UserActions>((set) => ({

return webdavs;
});
},
setWebdavs(webdavs) {
set({ webdavs });

setStorage('user', webdavs);
}
}));

Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
cors: true,
proxy: {
'/api': {
target: '',
target: 'http://8.222.131.201:8362',
changeOrigin: true,
ws: true,
rewrite: (path) => path.replace(/^\/api/, 'notes')
Expand Down

0 comments on commit 1fff691

Please sign in to comment.