Move game information edition

This commit is contained in:
Jeremie Pardou-Piquemal 2021-06-25 22:37:53 +02:00 committed by Jérémie Pardou-Piquemal
parent 4af63ed864
commit 394f967b81
8 changed files with 83 additions and 59 deletions

View file

@ -0,0 +1,37 @@
import React from "react";
import { useTranslation } from "react-i18next";
import BoardConfig from "./BoardConfig";
import Touch from "./ui/Touch";
import Modal from "./ui/Modal";
const EditInfoButton = () => {
const { t } = useTranslation();
const [show, setShow] = React.useState(false);
return (
<>
<Touch
onClick={() => setShow((prev) => !prev)}
alt={t("Edit game info")}
title={t("Edit game info")}
label={t("Edit game info")}
icon={"new-message"}
/>
<Modal
title={t("Edit game information")}
setShow={setShow}
show={show}
position="left"
>
<section>
<BoardConfig />
</section>
</Modal>
</>
);
};
export default EditInfoButton;

View file

@ -12,6 +12,7 @@ import ImageDropNPaste from "./ImageDropNPaste";
import AddItemButton from "./AddItemButton"; import AddItemButton from "./AddItemButton";
import { MessageButton } from "./message"; import { MessageButton } from "./message";
import { insideClass } from "./utils"; import { insideClass } from "./utils";
import EditInfoButton from "./EditInfoButton";
const StyledBoardView = styled.div` const StyledBoardView = styled.div`
width: 100vw; width: 100vw;
@ -66,6 +67,7 @@ const ActionBar = styled.div`
export const MainView = ({ export const MainView = ({
edit: editMode = false, edit: editMode = false,
mediaLibraries, mediaLibraries,
mediaHandlers,
itemMap, itemMap,
actionMap, actionMap,
ItemFormComponent, ItemFormComponent,
@ -94,7 +96,7 @@ export const MainView = ({
return ( return (
<StyledBoardView> <StyledBoardView>
<MediaLibraryProvider libraries={mediaLibraries}> <MediaLibraryProvider libraries={mediaLibraries} {...mediaHandlers}>
<BoardContainer> <BoardContainer>
<ImageDropNPaste> <ImageDropNPaste>
<Board <Board
@ -114,6 +116,7 @@ export const MainView = ({
</BoardContainer> </BoardContainer>
<ActionBar> <ActionBar>
{!editMode && <MessageButton />} {!editMode && <MessageButton />}
{editMode && <EditInfoButton />}
<div className="spacer" /> <div className="spacer" />
<Touch <Touch
onClick={() => setMoveFirst(false)} onClick={() => setMoveFirst(false)}

View file

@ -1,28 +1,37 @@
import React, { useContext } from "react"; import React, { useContext } from "react";
import {
uploadResourceImage,
listResourceImage,
deleteResourceImage,
} from "../../utils/api";
export const MediaLibraryContext = React.createContext({}); export const MediaLibraryContext = React.createContext({});
export const MediaLibraryProvider = ({ children, libraries = [] }) => { const noop = () => {};
const addMedia = React.useCallback(async ({ boxId, resourceId }, file) => {
const filePath = await uploadResourceImage(boxId, resourceId, file); export const MediaLibraryProvider = ({
children,
libraries = [],
uploadMedia = noop,
listMedia = noop,
deleteMedia = noop,
}) => {
const addMedia = React.useCallback(
async ({ boxId, resourceId }, file) => {
const filePath = await uploadMedia(boxId, resourceId, file);
return { return {
type: "local", type: "local",
content: filePath, content: filePath,
}; };
}, []); },
[uploadMedia]
);
const removeMedia = React.useCallback(async (key) => { const removeMedia = React.useCallback(
return await deleteResourceImage(key); async (key) => {
}, []); return await deleteMedia(key);
},
[deleteMedia]
);
const getLibraryMedia = React.useCallback( const getLibraryMedia = React.useCallback(
async ({ boxId, resourceId }) => listResourceImage(boxId, resourceId), async ({ boxId, resourceId }) => listMedia(boxId, resourceId),
[] [listMedia]
); );
return ( return (

View file

@ -197,10 +197,9 @@
"Go back to studio": "Go back to studio", "Go back to studio": "Go back to studio",
"Create a new game": "Add a game", "Create a new game": "Add a game",
"New game": "New game", "New game": "New game",
"Edit game info": "Edit game information", "Edit game info": "Configuration",
"Want to continue later?": "Want to continue later?", "Want to continue later?": "Want to continue later?",
"You can save the current session on your computer to load it later!": "You can save the current session on your computer to load it later!", "You can save the current session on your computer to load it later!": "You can save the current session on your computer to load it later!",
"Edit game information": "Edit game information",
"Help & info": "Help & info", "Help & info": "Help & info",
"Load previously exported work?": "Load previously exported work?", "Load previously exported work?": "Load previously exported work?",
"Load session": "Load session", "Load session": "Load session",

View file

@ -195,10 +195,9 @@
"Go back to studio": "Retourner au studio", "Go back to studio": "Retourner au studio",
"Create a new game": "Ajouter un jeu", "Create a new game": "Ajouter un jeu",
"New game": "Nouveau jeu", "New game": "Nouveau jeu",
"Edit game info": "Éditer les informations sur le jeu", "Edit game info": "Paramétrage",
"Want to continue later?": "Vous souhaitez continuer plus tard ?", "Want to continue later?": "Vous souhaitez continuer plus tard ?",
"You can save the current session on your computer to load it later!": "Vous pouvez sauvegarder la partie en cours sur votre ordinateur pour la continuer plus tard.", "You can save the current session on your computer to load it later!": "Vous pouvez sauvegarder la partie en cours sur votre ordinateur pour la continuer plus tard.",
"Edit game information": "Modifier les informations du jeu",
"Help & info": "Aide & Informations", "Help & info": "Aide & Informations",
"Load previously exported work?": "Charger une sauvegarde précédente ?", "Load previously exported work?": "Charger une sauvegarde précédente ?",
"Load session": "Charger une partie", "Load session": "Charger une partie",

View file

@ -7,6 +7,18 @@ import useC2C from "../../components/hooks/useC2C";
import WelcomeModal from "./WelcomeModal"; import WelcomeModal from "./WelcomeModal";
import NavBar from "./NavBar"; import NavBar from "./NavBar";
import {
uploadResourceImage,
listResourceImage,
deleteResourceImage,
} from "../../utils/api";
const mediaHandlers = {
uploadMedia: uploadResourceImage,
listMedia: listResourceImage,
deleteMedia: deleteResourceImage,
};
export const BoardView = (props) => { export const BoardView = (props) => {
const { isMaster } = useC2C("board"); const { isMaster } = useC2C("board");
@ -18,7 +30,7 @@ export const BoardView = (props) => {
<> <>
<NavBar editMode={props.edit} /> <NavBar editMode={props.edit} />
<WelcomeModal show={showWelcomeModal} setShow={setShowWelcomeModal} /> <WelcomeModal show={showWelcomeModal} setShow={setShowWelcomeModal} />
<MainView {...props} /> <MainView {...props} mediaHandlers={mediaHandlers} />
</> </>
); );
}; };

View file

@ -1,19 +0,0 @@
import React from "react";
import { useTranslation } from "react-i18next";
import Modal from "../../components/ui/Modal";
import BoardConfig from "../../components/BoardConfig";
const InfoModal = ({ show, setShow }) => {
const { t } = useTranslation();
return (
<Modal title={t("Edit game information")} setShow={setShow} show={show}>
<section>
<BoardConfig />
</section>
</Modal>
);
};
export default InfoModal;

View file

@ -16,7 +16,6 @@ import useC2C from "../../components/hooks/useC2C";
import useLocalStorage from "../../hooks/useLocalStorage"; import useLocalStorage from "../../hooks/useLocalStorage";
import InfoModal from "./InfoModal"; import InfoModal from "./InfoModal";
import InfoEditModal from "./InfoEditModal";
import LoadGameModal from "./LoadGameModal"; import LoadGameModal from "./LoadGameModal";
import LoadSessionModal from "./LoadSessionModal"; import LoadSessionModal from "./LoadSessionModal";
import ChangeGameModal from "./ChangeGameModal"; import ChangeGameModal from "./ChangeGameModal";
@ -141,7 +140,6 @@ const NavBar = ({ editMode }) => {
const [showLoadGameModal, setShowLoadGameModal] = React.useState(false); const [showLoadGameModal, setShowLoadGameModal] = React.useState(false);
const [showSaveGameModal, setShowSaveGameModal] = React.useState(false); const [showSaveGameModal, setShowSaveGameModal] = React.useState(false);
const [showEditInfoModal, setShowEditInfoModal] = React.useState(false);
const [showChangeGameModal, setShowChangeGameModal] = React.useState(false); const [showChangeGameModal, setShowChangeGameModal] = React.useState(false);
const [showInfoModal, setShowInfoModal] = React.useState(false); const [showInfoModal, setShowInfoModal] = React.useState(false);
const [showLink, setShowLink] = React.useState(false); const [showLink, setShowLink] = React.useState(false);
@ -268,14 +266,6 @@ const NavBar = ({ editMode }) => {
icon={editMode ? "save" : "download"} icon={editMode ? "save" : "download"}
/> />
<div className="spacer" /> <div className="spacer" />
{editMode && (
<Touch
onClick={() => setShowEditInfoModal((prev) => !prev)}
alt={t("Edit game info")}
title={t("Edit game info")}
icon={"new-message"}
/>
)}
<Touch <Touch
onClick={() => setShowInfoModal((prev) => !prev)} onClick={() => setShowInfoModal((prev) => !prev)}
alt={t("Help & info")} alt={t("Help & info")}
@ -289,12 +279,6 @@ const NavBar = ({ editMode }) => {
{!editMode && ( {!editMode && (
<WelcomeModal show={showLink} setShow={setShowLink} welcome={false} /> <WelcomeModal show={showLink} setShow={setShowLink} welcome={false} />
)} )}
{editMode && (
<InfoEditModal
show={showEditInfoModal}
setShow={setShowEditInfoModal}
/>
)}
{!editMode && ( {!editMode && (
<LoadSessionModal <LoadSessionModal
show={showLoadGameModal} show={showLoadGameModal}