Skip to content

Commit

Permalink
feat(export-page): set default export filename to current page name
Browse files Browse the repository at this point in the history
  • Loading branch information
begoat committed May 15, 2022
1 parent 8195353 commit dee58bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
exportToPngImgUrl,
savePngImgUrl,
useEventListener,
usePageName,
getExportName,
} from "./utils";

const HIDE_UI_KEY_LIST = ["Escape"];
Expand All @@ -20,7 +20,7 @@ function App() {
defaultIgnoreClassName.join(" ")
);
const [imageUrl, setImageUrl] = useState("");
const pageName = usePageName();
const [pageName, setPageName] = useState("logseq_export");
const visible = useAppVisible();
useEventListener(
"keydown",
Expand All @@ -44,6 +44,9 @@ function App() {
useEffect(() => {
if (visible) {
exportOnce();
getExportName().then((name) => {
setPageName(name);
});
}
}, [visible]);

Expand Down
13 changes: 4 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@ export const useSidebarVisible = () => {
return visible;
};

export const usePageName = () => {
const [name, setName] = useState("");
const isMounted = useMountedState();
React.useEffect(() => {
if (isMounted()) {
setName("123123");
}
}, []);
return name;
export const getExportName = async () => {
const currentPage = await logseq.Editor.getCurrentPage();
return currentPage?.name;
};

/**
Expand Down Expand Up @@ -123,6 +117,7 @@ export const exportToPngImgUrl = (
// https://html2canvas.hertzen.com/configuration
allowTaint: true,
useCORS: true,
imageTimeout: 5000,
backgroundColor: bgColor,
ignoreElements: (element) => {
return ignoreClassNameList.some((i) => {
Expand Down

0 comments on commit dee58bc

Please sign in to comment.