Skip to content

Commit 5962c3c

Browse files
authored
change discourse tool icon from style to asset, misc lint fixes (#617)
1 parent d3b43a2 commit 5962c3c

3 files changed

Lines changed: 45 additions & 46 deletions

File tree

apps/roam/src/components/canvas/Tldraw.tsx

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { OnloadArgs } from "roamjs-components/types";
77
import renderWithUnmount from "roamjs-components/util/renderWithUnmount";
88

99
import {
10-
Editor as TldrawApp,
10+
Editor,
1111
TLEditorComponents,
1212
TLUiComponents,
1313
TldrawEditor,
@@ -92,11 +92,12 @@ import { getSetting } from "~/utils/extensionSettings";
9292
import { isPluginTimerReady, waitForPluginTimer } from "~/utils/pluginTimer";
9393
import { HistoryEntry } from "@tldraw/store";
9494
import { TLRecord } from "@tldraw/tlschema";
95-
import getCurrentUserDisplayName from "roamjs-components/queries/getCurrentUserDisplayName";
95+
import { WHITE_LOGO_SVG } from "~/icons";
9696

9797
declare global {
98+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
9899
interface Window {
99-
tldrawApps: Record<string, TldrawApp>;
100+
tldrawApps: Record<string, Editor>;
100101
}
101102
}
102103
export type DiscourseContextType = {
@@ -119,13 +120,15 @@ export const DEFAULT_WIDTH = 160;
119120
export const DEFAULT_HEIGHT = 64;
120121
export const MAX_WIDTH = "400px";
121122

123+
const ICON_URL = `data:image/svg+xml;utf8,${encodeURIComponent(WHITE_LOGO_SVG)}`;
124+
122125
export const isPageUid = (uid: string) =>
123126
!!window.roamAlphaAPI.pull("[:node/title]", [":block/uid", uid])?.[
124127
":node/title"
125128
];
126129

127130
const TldrawCanvas = ({ title }: { title: string }) => {
128-
const appRef = useRef<TldrawApp | null>(null);
131+
const appRef = useRef<Editor | null>(null);
129132
const lastInsertRef = useRef<VecModel>();
130133
const containerRef = useRef<HTMLDivElement>(null);
131134
const lastActionsRef = useRef<HistoryEntry<TLRecord>[]>(
@@ -290,7 +293,7 @@ const TldrawCanvas = ({ title }: { title: string }) => {
290293
isCreating: false,
291294
});
292295

293-
const handleRelationCreation = (app: TldrawApp, e: TLPointerEventInfo) => {
296+
const handleRelationCreation = (app: Editor, e: TLPointerEventInfo) => {
294297
// Handle relation creation on pointer_down
295298
if (e.type === "pointer" && e.name === "pointer_down") {
296299
const currentTool = app.getCurrentTool();
@@ -334,8 +337,12 @@ const TldrawCanvas = ({ title }: { title: string }) => {
334337
const util = app.getShapeUtil(relationShape);
335338
if (
336339
util &&
340+
// TODO: fix this
341+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
337342
typeof (util as any).handleCreateRelationsInRoam === "function"
338343
) {
344+
// TODO: fix this
345+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
339346
(util as any).handleCreateRelationsInRoam({
340347
arrow: relationShape,
341348
targetId: shapeAtPoint.id,
@@ -532,7 +539,7 @@ const TldrawCanvas = ({ title }: { title: string }) => {
532539
handleTldrawError as EventListener,
533540
);
534541
};
535-
}, []);
542+
}, [title]);
536543

537544
return (
538545
<div
@@ -552,8 +559,8 @@ const TldrawCanvas = ({ title }: { title: string }) => {
552559
<button
553560
className="rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700"
554561
onClick={() => {
555-
const handleUpgrade = async () => {
556-
await performUpgrade();
562+
const handleUpgrade = () => {
563+
performUpgrade();
557564
renderToast({
558565
id: "tldraw-upgrade",
559566
intent: "success",
@@ -675,13 +682,13 @@ const TldrawCanvas = ({ title }: { title: string }) => {
675682
<TldrawUi
676683
overrides={uiOverrides}
677684
components={customUiComponents}
678-
assetUrls={defaultEditorAssetUrls}
685+
assetUrls={{ icons: { discourseNodeIcon: ICON_URL } }}
679686
>
680687
<InsideEditorAndUiContext
681688
extensionAPI={extensionAPI}
682689
allNodes={allNodes}
683-
allRelationIds={allRelationIds}
684-
allAddReferencedNodeActions={allAddReferencedNodeActions}
690+
// allRelationIds={allRelationIds}
691+
// allAddReferencedNodeActions={allAddReferencedNodeActions}
685692
/>
686693
<CanvasDrawerPanel />
687694
<ClipboardPanel />
@@ -699,41 +706,42 @@ const TldrawCanvas = ({ title }: { title: string }) => {
699706
const InsideEditorAndUiContext = ({
700707
extensionAPI,
701708
allNodes,
702-
allRelationIds,
703-
allAddReferencedNodeActions,
709+
// allRelationIds,
710+
// allAddReferencedNodeActions,
704711
}: {
705712
extensionAPI: OnloadArgs["extensionAPI"];
706713
allNodes: DiscourseNode[];
707-
allRelationIds: string[];
708-
allAddReferencedNodeActions: string[];
714+
// allRelationIds: string[];
715+
// allAddReferencedNodeActions: string[];
709716
}) => {
710717
const editor = useEditor();
711718
const toasts = useToasts();
712719
const msg = useTranslation();
713720

714-
// https://tldraw.dev/examples/data/assets/hosted-images
715-
const ACCEPTED_IMG_TYPE = [
716-
"image/jpeg",
717-
"image/png",
718-
"image/gif",
719-
"image/svg+xml",
720-
"image/webp",
721-
];
722-
const isImage = (ext: string) => ACCEPTED_IMG_TYPE.includes(ext);
723-
const isCustomArrowShape = (shape: TLShape) => {
724-
// TODO: find a better way to identify custom arrow shapes
725-
// possibly migrate to shape.type or shape.name
726-
// or add as meta
727-
const allRelationIdSet = new Set(allRelationIds);
728-
const allAddReferencedNodeActionsSet = new Set(allAddReferencedNodeActions);
721+
// const isCustomArrowShape = (shape: TLShape) => {
722+
// // TODO: find a better way to identify custom arrow shapes
723+
// // possibly migrate to shape.type or shape.name
724+
// // or add as meta
725+
// const allRelationIdSet = new Set(allRelationIds);
726+
// const allAddReferencedNodeActionsSet = new Set(allAddReferencedNodeActions);
729727

730-
return (
731-
allRelationIdSet.has(shape.type) ||
732-
allAddReferencedNodeActionsSet.has(shape.type)
733-
);
734-
};
728+
// return (
729+
// allRelationIdSet.has(shape.type) ||
730+
// allAddReferencedNodeActionsSet.has(shape.type)
731+
// );
732+
// };
735733

736734
useEffect(() => {
735+
// https://tldraw.dev/examples/data/assets/hosted-images
736+
const ACCEPTED_IMG_TYPE = [
737+
"image/jpeg",
738+
"image/png",
739+
"image/gif",
740+
"image/svg+xml",
741+
"image/webp",
742+
];
743+
const isImage = (ext: string) => ACCEPTED_IMG_TYPE.includes(ext);
744+
737745
registerDefaultExternalContentHandlers(
738746
editor,
739747
{

apps/roam/src/components/canvas/tldrawStyles.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,7 @@ export default /* css */ `
6565
font-family: "Inter", sans-serif;
6666
} */
6767
68-
/* Discourse Graph ToolButton */
69-
button[data-value="discourse-tool"] div::before {
70-
content: "";
71-
display: inline-block;
72-
width: 18px;
73-
height: 18px;
74-
background-image: url("data:image/svg+xml,%3Csvg width='256' height='264' viewBox='0 0 256 264' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M156.705 252.012C140.72 267.995 114.803 267.995 98.8183 252.012L11.9887 165.182C-3.99622 149.197 -3.99622 123.28 11.9886 107.296L55.4035 63.8807C63.3959 55.8881 76.3541 55.8881 84.3467 63.8807C92.3391 71.8731 92.3391 84.8313 84.3467 92.8239L69.8751 107.296C53.8901 123.28 53.8901 149.197 69.8751 165.182L113.29 208.596C121.282 216.589 134.241 216.589 142.233 208.596C150.225 200.604 150.225 187.646 142.233 179.653L127.761 165.182C111.777 149.197 111.777 123.28 127.761 107.296C143.746 91.3105 143.746 65.3939 127.761 49.4091L113.29 34.9375C105.297 26.9452 105.297 13.9868 113.29 5.99432C121.282 -1.99811 134.241 -1.99811 142.233 5.99434L243.533 107.296C259.519 123.28 259.519 149.197 243.533 165.182L156.705 252.012ZM200.119 121.767C192.127 113.775 179.168 113.775 171.176 121.767C163.184 129.76 163.184 142.718 171.176 150.71C179.168 158.703 192.127 158.703 200.119 150.71C208.112 142.718 208.112 129.76 200.119 121.767Z' fill='%23000000'/%3E%3C/svg%3E");
75-
background-size: contain;
76-
background-repeat: no-repeat;
77-
}
68+
7869
7970
/* Maximize Tldraw Canvas */
8071
/* Used in conjunction with tailwind classes on the canvas container */

apps/roam/src/components/canvas/uiOverrides.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export const createUiOverrides = ({
311311

312312
tools["discourse-tool"] = {
313313
id: "discourse-tool",
314-
icon: "none",
314+
icon: "discourseNodeIcon",
315315
label: "tool.discourse-tool" as TLUiTranslationKey,
316316
kbd: discourseToolShortcut,
317317
readonlyOk: true,

0 commit comments

Comments
 (0)