Skip to content

Commit 9d966ce

Browse files
committed
Use present action in footer button
1 parent 04ccc55 commit 9d966ce

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

excalidraw-app/App.tsx

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -929,29 +929,7 @@ const ExcalidrawWrapper = () => {
929929
</OverwriteConfirmDialog.Action>
930930
)}
931931
</OverwriteConfirmDialog>
932-
<AppFooter
933-
onChange={() => excalidrawAPI?.refresh()}
934-
onPresentation={() => {
935-
if (!excalidrawAPI) {
936-
return;
937-
}
938-
const selectedElementIds =
939-
excalidrawAPI.getAppState().selectedElementIds;
940-
const frames = excalidrawAPI
941-
.getSceneElements()
942-
.filter((e) => e.type === "frame");
943-
frames.sort((e1, e2) => e1.y - e2.y);
944-
const framesWithIndex = frames.map((f, index) => ({ ...f, index }));
945-
const selectedFrames = framesWithIndex.filter(
946-
(f) => f.id in selectedElementIds,
947-
);
948-
const frameIndex =
949-
selectedFrames.length === 0 ? 0 : selectedFrames[0].index;
950-
const newUrl = new URL(window.location.href);
951-
newUrl.hash = `#presentation=${frameIndex}`;
952-
window.open(newUrl.href, "_blank");
953-
}}
954-
/>
932+
<AppFooter onChange={() => excalidrawAPI?.refresh()} />
955933
{excalidrawAPI && <AIComponents excalidrawAPI={excalidrawAPI} />}
956934

957935
<TTDDialogTrigger />

excalidraw-app/components/AppFooter.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Button, Footer } from "@excalidraw/excalidraw/index";
2-
import React from "react";
3-
2+
import React, { useCallback } from "react";
43
import { useI18n } from "@excalidraw/excalidraw/i18n";
4+
import { useExcalidrawActionManager } from "@excalidraw/excalidraw/components/App";
5+
import { actionPresent } from "@excalidraw/excalidraw/actions";
56

67
import { isExcalidrawPlusSignedUser } from "../app_constants";
78

@@ -10,14 +11,13 @@ import { EncryptedIcon } from "./EncryptedIcon";
1011
import { ExcalidrawPlusAppLink } from "./ExcalidrawPlusAppLink";
1112

1213
export const AppFooter = React.memo(
13-
({
14-
onChange,
15-
onPresentation,
16-
}: {
17-
onChange: () => void;
18-
onPresentation: () => void;
19-
}) => {
14+
({ onChange }: { onChange: () => void }) => {
2015
const { t } = useI18n();
16+
const actionManager = useExcalidrawActionManager();
17+
const onPresent = useCallback(
18+
() => actionManager.executeAction(actionPresent),
19+
[actionManager],
20+
);
2121

2222
return (
2323
<Footer>
@@ -34,7 +34,7 @@ export const AppFooter = React.memo(
3434
) : (
3535
<EncryptedIcon />
3636
)}
37-
<Button onSelect={onPresentation} style={{ width: "fit-content" }}>
37+
<Button onSelect={onPresent} style={{ width: "fit-content" }}>
3838
{t("labels.present")}
3939
</Button>
4040
</div>

0 commit comments

Comments
 (0)