Skip to content

Commit

Permalink
修复crash
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiWenda committed Jun 16, 2024
1 parent fc46dab commit d4641f0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion main/expressDocCurd.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ router.put('/:docId', async (req, res) => {
const oldFilename = oldFilepath.pop();
const oldDir = oldFilepath.join('/');
const filename = req.body.name;
const suffix = oldFilename.split('.', 2)[1]
const suffix = oldFilename.split('.').slice(1).join('.')
const tags = JSON.parse(req.body.tag);
const dir = tags.shift() || '';
const actualFilename = `${docId}#${filename}${tags.map(tag => '[' + tag.replace('/', ':') + ']').join('')}.${suffix}`
Expand Down
7 changes: 4 additions & 3 deletions src/components/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function LayoutComponent(props: {session: Session, config: Config, pluginManager
const forceUpdate = useForceUpdate();
const navigate = useNavigate();
const location = useLocation();
const [curPage, setCurPage] = useState<string>(location.pathname.split('/').shift() || 'note');
const [curPage, setCurPage] = useState<string>(location.pathname.split('/')[1] || 'note');
const [settingOpen, setSettingOpen] = useState(false);
const [refreshing, setRefreshing] = useState(false);
const [drawerWidth, setDrawerWidth] = useState(window.innerWidth / 2);
Expand Down Expand Up @@ -374,8 +374,9 @@ function LayoutComponent(props: {session: Session, config: Config, pluginManager
props.session.startKeyMonitor();
const docId = props.session.clientStore.getClientSetting('curDocId');
navigate(`/${e.key}/${docId}`);
} else if (e.key === 'test') {
navigate(`/${e.key}`);
} else if (e.key === 'produce') {
const pkbId = props.session.clientStore.getClientSetting('curPkbId');
navigate(`/${e.key}/${pkbId}`);
} else {
// props.session.stopKeyMonitor('header');
const lastSearch = props.session.clientStore.getClientSetting('curSearch');
Expand Down
68 changes: 41 additions & 27 deletions src/components/pkb-producer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ export default function PkbProducer({
const {userDocs} = useLoaderData();
const appRef = useRef<any>(null);
const { t } = useI18n();
const [selectId, setSelectId] = useState<string>('');
const [selectNodeId, setSelectNodeId] = useState<string>('');
const [editingTextId, setEditingTextId] = useState<string>('');
const [editingDocId, setEditingDocId] = useState<number>(-1);
const [boardX, setBoardX] = useState(70);
const [boardY, setBoardY] = useState(17);
const [showFilter, setShowFilter] = useState(false);
Expand All @@ -111,6 +112,7 @@ export default function PkbProducer({
}, [userDocs]);
useEffect(() => {
if (curDocId && Number(curDocId) > 0) {
session.clientStore.setClientSetting('curPkbId', Number(curDocId));
api_utils.getDocContent(Number(curDocId)).then((res) => {
const elements = JSON.parse(res.content).elements as readonly ExcalidrawElement[];
// @ts-ignore
Expand Down Expand Up @@ -347,27 +349,29 @@ export default function PkbProducer({
<Tooltip title={'进入途经点子图'}>
<NodeIndexOutlined onClick={() => {
excalidrawAPI?.updateScene({
elements: filterWithSelectElementId('up_down', excalidrawAPI?.getSceneElements()!, selectId)
elements: filterWithSelectElementId('up_down', excalidrawAPI?.getSceneElements()!, selectNodeId)
});
}}/>
</Tooltip>
<Tooltip title={'进入终点子图'} >
<BranchesOutlined onClick={() => {
excalidrawAPI?.updateScene({
elements: filterWithSelectElementId('up', excalidrawAPI?.getSceneElements()!, selectId)
elements: filterWithSelectElementId('up', excalidrawAPI?.getSceneElements()!, selectNodeId)
});
}} />
</Tooltip>
<Tooltip title={'进入起点子图'}>
<MergeOutlined onClick={() => {
excalidrawAPI?.updateScene({
elements: filterWithSelectElementId('down', excalidrawAPI?.getSceneElements()!, selectId)
elements: filterWithSelectElementId('down', excalidrawAPI?.getSceneElements()!, selectNodeId)
});
}}/>
</Tooltip>
</Space>
</Sidebar.Header>
<div onMouseEnter={() => {
<div
style={{height: '100%'}}
onMouseEnter={() => {
session.startKeyMonitor();
}} onMouseLeave={() => {
session.stopKeyMonitor('sidebar-enter');
Expand Down Expand Up @@ -414,6 +418,12 @@ export default function PkbProducer({
})
});
setEditingTextId('');
} else if (editingDocId > 0) {
console.log(`正在保存内容到文档 ${editingDocId}`);
session.reUploadFile(Path.root(), editingDocId).then(() => {
setEditingDocId(-1);
excalidrawAPI?.setToast({message: '节点保存成功', duration: 1000});
});
}
};

Expand Down Expand Up @@ -460,8 +470,9 @@ export default function PkbProducer({
const viewRoot = link.split('f=').pop()?.split('&').shift();
session.document.canonicalPath(Number(viewRoot)).then(path => {
session.changeViewRoot(path || Path.root()).then(() => {
setEditingDocId(docID);
setEditingTextId('');
setSelectId(element.id);
setSelectNodeId(element.id);
excalidrawAPI?.updateScene({appState: {openSidebar: {name: 'node-content'}}});
console.log('onLinkOpen', docID, viewRoot);
});
Expand Down Expand Up @@ -494,7 +505,7 @@ export default function PkbProducer({
loadDoc({id: -1, content}).then(() => {
setTimeout(() => {
setEditingTextId(textElementId!.id);
setSelectId(pointerDownState.hit.element!.id);
setSelectNodeId(pointerDownState.hit.element!.id);
excalidrawAPI?.updateScene({appState: {openSidebar: { name: 'node-content'}}});
});
});
Expand All @@ -507,28 +518,31 @@ export default function PkbProducer({
return (
<MainMenu>
<MainMenu.DefaultItems.LoadScene />
<MainMenu.Item icon={<CloudUploadOutlined />} onSelect={() => {
console.log('保存至EffectNote');
if (!excalidrawAPI) {
return false;
}
exportToClipboard({
elements: excalidrawAPI.getSceneElements(),
appState: excalidrawAPI.getAppState(),
files: excalidrawAPI.getFiles(),
type: 'json',
}).then(() => {
navigator.clipboard.readText().then(content => {
const docInfo = { ...userDocs.find((doc: any) => doc.id === Number(curDocId))!,
content: JSON.stringify(JSON.parse(content), undefined, 2)};
api_utils.updateDoc(Number(curDocId), docInfo).then(() => {
excalidrawAPI.setToast({message: '保存成功', duration: 1000});
{
Number(curDocId) > 0 &&
<MainMenu.Item icon={<CloudUploadOutlined />} onSelect={() => {
console.log('保存至EffectNote');
if (!excalidrawAPI) {
return false;
}
exportToClipboard({
elements: excalidrawAPI.getSceneElements(),
appState: excalidrawAPI.getAppState(),
files: excalidrawAPI.getFiles(),
type: 'json',
}).then(() => {
navigator.clipboard.readText().then(content => {
const docInfo = { ...userDocs.find((doc: any) => doc.id === Number(curDocId))!,
content: JSON.stringify(JSON.parse(content), undefined, 2)};
api_utils.updateDoc(Number(curDocId), docInfo).then(() => {
excalidrawAPI.setToast({message: '画板保存成功', duration: 1000});
});
});
});
});
}}>
保存至EffectNote
</MainMenu.Item>
}}>
保存至EffectNote
</MainMenu.Item>
}
<MainMenu.DefaultItems.SaveToActiveFile />
<MainMenu.DefaultItems.Export />
<MainMenu.DefaultItems.SaveAsImage />
Expand Down
2 changes: 2 additions & 0 deletions src/share/ts/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type ClientSettings = Theme & {
openFile: string;
curView: string;
curDocId: number;
curPkbId: number;
curTheme: string;
curSearch: string;
curSearchResult: string;
Expand All @@ -52,6 +53,7 @@ const default_client_settings: ClientSettings =
openFile: '0',
curView: 'note',
curDocId: -1,
curPkbId: -2,
curSearch: '',
curSearchResult: '',
recentDocId: [-1],
Expand Down

0 comments on commit d4641f0

Please sign in to comment.