Fix library dnd (#2314)

This commit is contained in:
David Luzar 2020-10-30 21:01:41 +01:00 committed by GitHub
parent 8a50916ef2
commit ba3f548b91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 261 additions and 168 deletions

View file

@ -145,7 +145,6 @@ import {
isBindingElementType,
} from "../element/typeChecks";
import { actionFinalize, actionDeleteSelected } from "../actions";
import { loadLibrary } from "../data/localStorage";
import throttle from "lodash.throttle";
import { LinearElementEditor } from "../element/linearElementEditor";
@ -1266,7 +1265,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
history.resumeRecording();
this.scene.replaceAllElements(this.scene.getElements());
this.initializeSocketClient({ showLoadingState: false });
await this.initializeSocketClient({ showLoadingState: false });
};
closePortal = () => {
@ -3729,7 +3728,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
});
}
const libraryShapes = event.dataTransfer.getData(MIME_TYPES.excalidraw);
const libraryShapes = event.dataTransfer.getData(MIME_TYPES.excalidrawlib);
if (libraryShapes !== "") {
this.addElementsFromPasteOrLibrary(
JSON.parse(libraryShapes),
@ -4040,7 +4039,7 @@ declare global {
setState: React.Component<any, AppState>["setState"];
history: SceneHistory;
app: InstanceType<typeof App>;
library: ReturnType<typeof loadLibrary>;
library: typeof Library;
};
}
}
@ -4064,7 +4063,7 @@ if (
get: () => history,
},
library: {
get: () => loadLibrary(),
value: Library,
},
});
}

View file

@ -39,12 +39,12 @@ import { Tooltip } from "./Tooltip";
import "./LayerUI.scss";
import { LibraryUnit } from "./LibraryUnit";
import { loadLibrary, saveLibrary } from "../data/localStorage";
import { ToolButton } from "./ToolButton";
import { saveLibraryAsJSON, importLibraryFromJSON } from "../data/json";
import { muteFSAbortError } from "../utils";
import { BackgroundPickerAndDarkModeToggle } from "./BackgroundPickerAndDarkModeToggle";
import clsx from "clsx";
import { Library } from "../data/library";
interface LayerUIProps {
actionManager: ActionManager;
@ -223,7 +223,7 @@ const LibraryMenu = ({
resolve("loading");
}, 100);
}),
loadLibrary().then((items) => {
Library.loadLibrary().then((items) => {
setLibraryItems(items);
setIsLoading("ready");
}),
@ -238,18 +238,18 @@ const LibraryMenu = ({
}, []);
const removeFromLibrary = useCallback(async (indexToRemove) => {
const items = await loadLibrary();
const items = await Library.loadLibrary();
const nextItems = items.filter((_, index) => index !== indexToRemove);
saveLibrary(nextItems);
Library.saveLibrary(nextItems);
setLibraryItems(nextItems);
}, []);
const addToLibrary = useCallback(
async (elements: LibraryItem) => {
const items = await loadLibrary();
const items = await Library.loadLibrary();
const nextItems = [...items, elements];
onAddToLibrary();
saveLibrary(nextItems);
Library.saveLibrary(nextItems);
setLibraryItems(nextItems);
},
[onAddToLibrary],