import React from "react"; import { ProjectName } from "../components/ProjectName"; import { saveAsJSON, loadFromJSON } from "../data"; import { load, save } from "../components/icons"; import { ToolButton } from "../components/ToolButton"; import { t } from "../i18n"; import useIsMobile from "../is-mobile"; import { register } from "./register"; import { KEYS } from "../keys"; export const actionChangeProjectName = register({ name: "changeProjectName", perform: (_elements, appState, value) => { return { appState: { ...appState, name: value }, commitToHistory: false }; }, PanelComponent: ({ appState, updateData }) => ( updateData(name)} /> ), }); export const actionChangeExportBackground = register({ name: "changeExportBackground", perform: (_elements, appState, value) => { return { appState: { ...appState, exportBackground: value }, commitToHistory: false, }; }, PanelComponent: ({ appState, updateData }) => ( ), }); export const actionChangeShouldAddWatermark = register({ name: "changeShouldAddWatermark", perform: (_elements, appState, value) => { return { appState: { ...appState, shouldAddWatermark: value }, commitToHistory: false, }; }, PanelComponent: ({ appState, updateData }) => ( ), }); export const actionSaveScene = register({ name: "saveScene", perform: (elements, appState, value) => { saveAsJSON(elements, appState).catch((error) => console.error(error)); return { commitToHistory: false }; }, keyTest: (event) => { return event.key === "s" && event[KEYS.CTRL_OR_CMD]; }, PanelComponent: ({ updateData }) => ( updateData(null)} /> ), }); export const actionLoadScene = register({ name: "loadScene", perform: ( elements, appState, { elements: loadedElements, appState: loadedAppState, error }, ) => { return { elements: loadedElements, appState: { ...loadedAppState, errorMessage: error, }, commitToHistory: false, }; }, PanelComponent: ({ updateData }) => ( { loadFromJSON() .then(({ elements, appState }) => { updateData({ elements: elements, appState: appState }); }) .catch((error) => { // if user cancels, ignore the error if (error.name === "AbortError") { return; } updateData({ error: error.message }); }); }} /> ), });