فهرست منبع

refactor: Make the example React app reusable without duplication (#6188)

DanielJGeiger 2 سال پیش
والد
کامیت
8c1168ef33

+ 16 - 8
src/packages/excalidraw/example/App.tsx

@@ -80,7 +80,13 @@ const COMMENT_ICON_DIMENSION = 32;
 const COMMENT_INPUT_HEIGHT = 50;
 const COMMENT_INPUT_WIDTH = 150;
 
-export default function App() {
+export interface AppProps {
+  appTitle: string;
+  useCustom: (api: ExcalidrawImperativeAPI | null, customArgs?: any[]) => void;
+  customArgs?: any[];
+}
+
+export default function App({ appTitle, useCustom, customArgs }: AppProps) {
   const appRef = useRef<any>(null);
   const [viewModeEnabled, setViewModeEnabled] = useState(false);
   const [zenModeEnabled, setZenModeEnabled] = useState(false);
@@ -107,6 +113,8 @@ export default function App() {
   const [excalidrawAPI, setExcalidrawAPI] =
     useState<ExcalidrawImperativeAPI | null>(null);
 
+  useCustom(excalidrawAPI, customArgs);
+
   useHandleLibrary({ excalidrawAPI });
 
   useEffect(() => {
@@ -114,7 +122,7 @@ export default function App() {
       return;
     }
     const fetchData = async () => {
-      const res = await fetch("/rocket.jpeg");
+      const res = await fetch("/images/rocket.jpeg");
       const imageData = await res.blob();
       const reader = new FileReader();
       reader.readAsDataURL(imageData);
@@ -150,7 +158,7 @@ export default function App() {
           />
         )}
         <button
-          onClick={() => alert("This is dummy top right UI")}
+          onClick={() => alert("This is an empty top right UI")}
           style={{ height: "2.5rem" }}
         >
           {" "}
@@ -397,7 +405,7 @@ export default function App() {
           }}
         >
           <div className="comment-avatar">
-            <img src="doremon.png" alt="doremon" />
+            <img src="images/doremon.png" alt="doremon" />
           </div>
         </div>
       );
@@ -525,7 +533,7 @@ export default function App() {
   };
   return (
     <div className="App" ref={appRef}>
-      <h1> Excalidraw Example</h1>
+      <h1>{appTitle}</h1>
       <ExampleSidebar>
         <div className="button-wrapper">
           <button onClick={loadSceneOrLibrary}>Load Scene or Library</button>
@@ -611,15 +619,15 @@ export default function App() {
                   const collaborators = new Map();
                   collaborators.set("id1", {
                     username: "Doremon",
-                    avatarUrl: "doremon.png",
+                    avatarUrl: "images/doremon.png",
                   });
                   collaborators.set("id2", {
                     username: "Excalibot",
-                    avatarUrl: "excalibot.png",
+                    avatarUrl: "images/excalibot.png",
                   });
                   collaborators.set("id3", {
                     username: "Pika",
-                    avatarUrl: "pika.jpeg",
+                    avatarUrl: "images/pika.jpeg",
                   });
                   collaborators.set("id4", {
                     username: "fallback",

+ 4 - 1
src/packages/excalidraw/example/index.tsx

@@ -8,6 +8,9 @@ const root = createRoot(rootElement);
 
 root.render(
   <StrictMode>
-    <App />
+    <App
+      appTitle={"Excalidraw Example"}
+      useCustom={(api: any, args?: any[]) => {}}
+    />
   </StrictMode>,
 );

+ 0 - 0
src/packages/excalidraw/example/public/doremon.png → src/packages/excalidraw/example/public/images/doremon.png


+ 0 - 0
src/packages/excalidraw/example/public/excalibot.png → src/packages/excalidraw/example/public/images/excalibot.png


+ 0 - 0
src/packages/excalidraw/example/public/pika.jpeg → src/packages/excalidraw/example/public/images/pika.jpeg


+ 0 - 0
src/packages/excalidraw/example/public/rocket.jpeg → src/packages/excalidraw/example/public/images/rocket.jpeg


+ 2 - 2
src/packages/excalidraw/example/sidebar/ExampleSidebar.tsx

@@ -10,8 +10,8 @@ export default function Sidebar({ children }: { children: React.ReactNode }) {
           x
         </button>
         <div className="sidebar-links">
-          <button>Dummy Home</button>
-          <button>Dummy About</button>{" "}
+          <button>Empty Home</button>
+          <button>Empty About</button>{" "}
         </div>
       </div>
       <div className={`${open ? "sidebar-open" : ""}`}>