Skip to content

Commit 39c333a

Browse files
authored
Fixed several bugs (#200)
* fix: Fixed a bug of closing local notebook * fix: Fixed Chinese link url * refactor: Better debounce logic * fix: Fixed deleteNoteDialog memory leak * feat: Better reference jump in editor mode * doc: Updated the README.md
1 parent 7fdd325 commit 39c333a

9 files changed

Lines changed: 70 additions & 46 deletions

File tree

README.md

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
---
2-
tags: []
32
created: 2020-04-12T13:19:52.701Z
43
modified: 2020-05-11T11:14:44.140Z
54
---
65

76
![](./public/logo192.png)
87

9-
# 📝 Crossnote 交叉笔记 (beta)
8+
# 📝 Crossnote 交叉笔记
109

11-
> You can still check the deprecated alpha version README.md [here](./README.alpha.md).
12-
13-
**Attention: Breaking updates coming soon. Please check [this GitHub issue](https://github.com/0xGG/crossnote/issues/129) for more information.**
1410

1511
https://crossnote.app
1612

17-
Or checkout our latest development version V3 that comes with many fancy changes:
18-
19-
**V3**: https://0xgg.io/crossnote/
13+
Or checkout our latest development version: https://0xgg.io/crossnote/
2014

2115
---
2216

@@ -25,31 +19,21 @@ Or checkout our latest development version V3 that comes with many fancy changes
2519

2620
**Crossnote** is probably the world's first markdown notes reader & editor Progressive Web Application that works offline and supports syncing with arbitrary git repository right inside your browser.
2721

28-
We also offer an extension for VSCode (Still under development): [0xGG/vscode-crossnote](https://github.com/0xGG/vscode-crossnote) | [VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=shd101wyy.crossnote)
29-
3022
Let's open the [Welcome Notebook](https://crossnote.app/?repo=https%3A%2F%2Fgithub.com%2F0xGG%2Fwelcome-notebook.git&branch=master&filePath=README.md) in crossnote for more information! (Just click the `ADD` button once the webpage is open to add this notebook)
3123

3224
让我们在交叉笔记中打开 [欢迎笔记本](https://crossnote.app/?repo=https%3A%2F%2Fgithub.com%2F0xGG%2Fwelcome-notebook.git&branch=master&filePath=README.md) 以查看更详尽的介绍!(在网页打开后点击 `ADD` 按钮直接添加该笔记本)
3325

3426
由于服务器目前位于境外,所以国内用户第一次打开速度会略慢,但是第一次打开后程序就会被缓存了以供离线使用,往后打开速度就快了。
3527

36-
![Screenshot from 2020-05-20 22-19-46](https://i.loli.net/2020/05/20/avwbhzYotSFBPWL.png)
3728

38-
![Screenshot from 2020-05-20 22-18-43](https://i.loli.net/2020/05/20/9CDBljgFROm78eQ.png)
29+
![Screenshot from 2021-02-28 22-47-35](https://user-images.githubusercontent.com/1908863/109422675-89d1da00-7a17-11eb-9163-c50126114ff1.png)
30+
31+
![Screenshot from 2021-02-28 22-47-51](https://user-images.githubusercontent.com/1908863/109422670-876f8000-7a17-11eb-911f-8a8efee856ad.png)
3932

4033
## Development
4134

4235
Please check [this documentation](https://github.com/0xGG/welcome-notebook/tree/master/development).
4336

44-
## Crossnote V3
45-
46-
Crossnote V3 is currently under development on the `develop` branch of this repository.
47-
Please note that V3 is far from complete.
48-
The Crossnote V3 website is currently hosted on GitHub Pages: https://0xgg.io/crossnote/
49-
The Crossnote V3 supports modifying local files powered by the Chrome's [File System Access API](https://web.dev/file-system-access/):
50-
51-
![Peek 2021-02-15 15-30](https://user-images.githubusercontent.com/1908863/107917394-db538100-6fa2-11eb-8ef1-ea37844cb799.gif)
52-
5337
## License
5438

5539
AGPL3

src/components/ConfigureNotebookDialog.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import {
2+
Accordion,
3+
AccordionDetails,
4+
AccordionSummary,
25
Box,
36
Button,
47
Dialog,
58
DialogActions,
69
DialogContent,
710
DialogTitle,
8-
ExpansionPanel,
9-
ExpansionPanelDetails,
10-
ExpansionPanelSummary,
1111
Input,
1212
InputAdornment,
1313
Link,
1414
TextField,
1515
Typography,
1616
} from "@material-ui/core";
1717
import { ChevronDown } from "mdi-material-ui";
18-
import React, { useCallback, useEffect, useState } from "react";
18+
import React, { useCallback, useEffect, useRef, useState } from "react";
1919
import { useTranslation } from "react-i18next";
2020
import { CrossnoteContainer } from "../containers/crossnote";
2121
import { Notebook } from "../lib/notebook";
@@ -45,8 +45,16 @@ export default function ConfigureNotebookDialog(props: Props) {
4545
const [clickHardResetCount, setClickHardResetCount] = useState<number>(
4646
MaxClickDeleteCount,
4747
);
48+
const isMounted = useRef<boolean>(false);
4849
const { t } = useTranslation();
4950

51+
useEffect(() => {
52+
isMounted.current = true;
53+
return () => {
54+
isMounted.current = false;
55+
};
56+
}, []);
57+
5058
useEffect(() => {
5159
setClickDeleteCount(MaxClickDeleteCount);
5260
setClickHardResetCount(MaxClickDeleteCount);
@@ -82,7 +90,9 @@ export default function ConfigureNotebookDialog(props: Props) {
8290
try {
8391
await crossnoteContainer.updateNotebook(notebook);
8492
} catch (error) {}
85-
props.onClose();
93+
if (isMounted.current) {
94+
props.onClose();
95+
}
8696
}, [
8797
props,
8898
props.notebook,
@@ -100,16 +110,20 @@ export default function ConfigureNotebookDialog(props: Props) {
100110
try {
101111
await crossnoteContainer.deleteNotebook(notebook);
102112
} catch (error) {}
103-
props.onClose();
104-
}, [props.notebook]);
113+
if (isMounted.current) {
114+
props.onClose();
115+
}
116+
}, [props.notebook, props]);
105117

106118
const hardResetNotebook = useCallback(async () => {
107119
const notebook = props.notebook;
108120
try {
109121
await crossnoteContainer.hardResetNotebook(notebook);
110122
} catch (error) {}
111-
props.onClose();
112-
}, [props.notebook]);
123+
if (isMounted.current) {
124+
props.onClose();
125+
}
126+
}, [props.notebook, props]);
113127

114128
useEffect(() => {
115129
setClickDeleteCount(MaxClickDeleteCount);
@@ -134,17 +148,17 @@ export default function ConfigureNotebookDialog(props: Props) {
134148
autoCorrect={"off"}
135149
></TextField>
136150
{!props.notebook.isLocal && (
137-
<ExpansionPanel
151+
<Accordion
138152
elevation={2}
139153
expanded={expanded}
140154
onChange={() => setExpanded(!expanded)}
141155
>
142-
<ExpansionPanelSummary expandIcon={<ChevronDown></ChevronDown>}>
156+
<AccordionSummary expandIcon={<ChevronDown></ChevronDown>}>
143157
<Typography>{`${t("general/git-repository")} (${t(
144158
"general/optional",
145159
)})`}</Typography>
146-
</ExpansionPanelSummary>
147-
<ExpansionPanelDetails>
160+
</AccordionSummary>
161+
<AccordionDetails>
148162
<Box>
149163
<TextField
150164
label={t("general/url")}
@@ -220,8 +234,8 @@ export default function ConfigureNotebookDialog(props: Props) {
220234
</Box>
221235
) : null}
222236
</Box>
223-
</ExpansionPanelDetails>
224-
</ExpansionPanel>
237+
</AccordionDetails>
238+
</Accordion>
225239
)}
226240
</DialogContent>
227241
<DialogActions>

src/components/DeleteNoteDialog.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
DialogTitle,
88
} from "@material-ui/core";
99
import { TabNode } from "flexlayout-react";
10-
import React from "react";
10+
import React, { useEffect, useRef } from "react";
1111
import { useTranslation } from "react-i18next";
1212
import { CrossnoteContainer } from "../containers/crossnote";
1313
import { Note } from "../lib/note";
@@ -21,9 +21,17 @@ interface Props {
2121

2222
export function DeleteNoteDialog(props: Props) {
2323
const { t } = useTranslation();
24+
const isMounted = useRef<boolean>(false);
2425
const note = props.note;
2526
const crossnoteContainer = CrossnoteContainer.useContainer();
2627

28+
useEffect(() => {
29+
isMounted.current = true;
30+
return () => {
31+
isMounted.current = false;
32+
};
33+
}, []);
34+
2735
return (
2836
<Dialog open={props.open} onClose={props.onClose}>
2937
<DialogTitle>{t("delete-note-dialog/title")}</DialogTitle>
@@ -41,7 +49,9 @@ export function DeleteNoteDialog(props: Props) {
4149
note.notebookPath,
4250
note.filePath,
4351
);
44-
props.onClose();
52+
if (isMounted.current) {
53+
props.onClose();
54+
}
4555
}}
4656
>
4757
{t("general/Delete")}

src/components/GraphView.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { debounce } from "@0xgg/echomd";
12
import {
23
createStyles,
34
makeStyles,
@@ -61,12 +62,13 @@ export default function GraphView(props: Props) {
6162
setWidth(graphViewPanel.current.offsetWidth);
6263
setHeight(graphViewPanel.current.offsetHeight);
6364
};
64-
window.addEventListener("resize", resize);
65-
props.tabNode.setEventListener("resize", resize);
65+
const debouncedResize = debounce(resize, 1000);
66+
window.addEventListener("resize", debouncedResize);
67+
props.tabNode.setEventListener("resize", debouncedResize);
6668
resize();
6769

6870
return () => {
69-
window.removeEventListener("resize", resize);
71+
window.removeEventListener("resize", debouncedResize);
7072
props.tabNode.removeEventListener("resize");
7173
};
7274
}, [graphViewPanel, props.tabNode]);

src/components/NoteCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export default function NoteCard(props: Props) {
388388
notebook: crossnoteContainer.getNotebookAtPath(
389389
note.notebookPath,
390390
),
391-
reference,
391+
reference: Object.assign({}, reference) as Reference,
392392
},
393393
name: `📝 ` + note.title,
394394
});

src/components/NotePanel.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,17 @@ export default function NotePanel(props: Props) {
625625
},
626626
);
627627
}
628-
}*/
628+
}*/ else if (
629+
editor
630+
) {
631+
const lineNo = (props.reference.parentToken.map || [])[0];
632+
if (typeof lineNo === "number") {
633+
editor.setCursor({ line: editor.lastLine(), ch: 0 });
634+
setTimeout(function () {
635+
editor.setCursor({ line: lineNo, ch: 0 });
636+
}, 10);
637+
}
638+
}
629639
}
630640
}, [props.reference, editorMode, editor, previewElement]);
631641

src/containers/crossnote.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,9 @@ function useCrossnoteContainer(initialState: InitialState) {
490490
notebookPath: notebook.dir,
491491
});
492492
await crossnote.deleteNotebook(notebook._id);
493-
} catch (error) {}
493+
} catch (error) {
494+
console.error(error);
495+
}
494496
let selectedNotebook: Notebook = null;
495497
setNotebooks((notebooks) =>
496498
notebooks.filter((n) => {

src/lib/crossnote.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ export default class Crossnote {
274274

275275
public async deleteNotebook(notebookID: string) {
276276
const notebook = await this.notebookDB.get(notebookID);
277-
await pfs.rmdir(notebook.dir);
277+
if (!notebook.directoryHandle) {
278+
await pfs.rmdir(notebook.dir);
279+
}
278280
await this.notebookDB.remove(notebook);
279281
}
280282
public async updateNotebook(notebook: Notebook) {

src/lib/notebook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class Notebook {
168168
tokens[i + 1].type === "text"
169169
) {
170170
if (token.attrs.length && token.attrs[0][0] === "href") {
171-
const link = token.attrs[0][1];
171+
const link = decodeURI(token.attrs[0][1]);
172172
const text = tokens[i + 1].content.trim();
173173
if (
174174
link.match(/https?:\/\//) ||

0 commit comments

Comments
 (0)