diff --git a/locales/en-us/creator.json b/locales/en-us/creator.json index f72eedc4..265192dc 100644 --- a/locales/en-us/creator.json +++ b/locales/en-us/creator.json @@ -95,10 +95,16 @@ "buttons": { "discardChallenge": "Discard challenge", "discardChallengeShort": "Discard", - "download": "Download", + "download": "Download challenge", + "downloadShort": "Download", "share": "Share challenge", "shareUrl": "Share via url", + "shareUrlShort": "Share", "save": "Save challenge", + "saveShort": "Save", + "savedCorrectly": "Challenge was saved correctly", + "copyToClipboard": "Copy to clipboard", + "copiedToClipboard": "Copied to clipboard", "preview": "Challenge preview", "previewShort": "Preview", "keepEditing": "Keep editing", diff --git a/locales/es-ar/creator.json b/locales/es-ar/creator.json index 5962566c..b5c7c04a 100644 --- a/locales/es-ar/creator.json +++ b/locales/es-ar/creator.json @@ -95,10 +95,16 @@ "buttons": { "discardChallenge": "Descartar desafío", "discardChallengeShort": "Descartar", - "download": "Descargar", + "download": "Descargar desafío", + "downloadShort": "Descargar", "share": "Compartir desafío", "shareUrl": "Compartir por url", + "shareUrlShort": "Compartir", + "copyToClipboard": "Copiar al portapapeles", + "copiedToClipboard": "Copiado al portapapeles", "save": "Guardar desafío", + "saveShort": "Guardar", + "savedCorrectly": "El desafío fue guardado correctamente", "preview": "Ver desafío", "previewShort": "Ver", "keepEditing": "Seguir editando", diff --git a/src/components/creator/Editor/ActionButtons/ShareButton.tsx b/src/components/creator/Editor/ActionButtons/ShareButton.tsx deleted file mode 100644 index c41f255c..00000000 --- a/src/components/creator/Editor/ActionButtons/ShareButton.tsx +++ /dev/null @@ -1,101 +0,0 @@ -import { SerializedChallenge } from "../../../serializedChallenge"; -import { LocalStorage } from "../../../../localStorage"; -import { CreatorActionButton } from "./CreatorActionButton"; -import DownloadIcon from '@mui/icons-material/Download'; -import ShareIcon from '@mui/icons-material/Share'; -import SaveIcon from '@mui/icons-material/Save'; -import { PilasBloquesApi } from "../../../../pbApi"; -import { ReactNode, useContext, useState } from "react"; -import { Dialog, DialogContent, DialogTitle, Stack, Tooltip } from "@mui/material"; -import { DownloadButton } from "./DownloadButton"; -import { CreatorContext } from "../CreatorContext"; -import { DialogSnackbar } from "../../../dialogSnackbar/DialogSnackbar"; -import { useTranslation } from "react-i18next"; - -export const ShareButton = () => { - - const [dialogOpen, setDialogOpen] = useState(false) - - return <> - - { setDialogOpen(true) }} startIcon={} nametag='share' isshortversion={true} /> - - -} - -const ShareDialog = ({ open, setDialogOpen }: { open: boolean, setDialogOpen: (open: boolean) => void }) => { - const { shareId } = useContext(CreatorContext) - - return <> - { setDialogOpen(false) }}> - Compartir desafio - - - { `http://localhost:3000/#/desafio/guardado/${shareId}` } - - - - - -} - -const Buttons = () => { - const { shareId } = useContext(CreatorContext) - - return <> - - {shareId ? : } - - - -} - -const ShareUrlButton = () => { - - const shareChallenge = async (): Promise => { - const challenge: SerializedChallenge = LocalStorage.getCreatorChallenge()! - const sharedChallenge = await PilasBloquesApi.shareChallenge(challenge) - - return sharedChallenge.sharedId - } - - return } nametag="shareUrl" challengeUpsert={shareChallenge}/> -} -const SaveButton = () => { - - const saveChallenge = async (): Promise => { - const savedChallenge = await PilasBloquesApi.saveChallenge(LocalStorage.getCreatorChallenge()!) - return savedChallenge.sharedId - } - - return } nametag="save" challengeUpsert={saveChallenge}/> -} - -const ChallengeUpsertButton = ({Icon, challengeUpsert, nametag}: {Icon: ReactNode, nametag: string, challengeUpsert: () => Promise}) => { - - const { setShareId } = useContext(CreatorContext) - const userLoggedIn = !!LocalStorage.getUser() - const [serverError, setServerError] = useState(false) - const { t } = useTranslation('creator'); - - const handleClick = async () => { - try{ - setShareId(await challengeUpsert()) - } - catch(error){ - setServerError(true) - } - } - - return <> - -
- -
-
- setServerError(false)} message={t('editor.serverError')}/> - -} - - - diff --git a/src/components/creator/Editor/ActionButtons/ShareChallenge/ShareButton.tsx b/src/components/creator/Editor/ActionButtons/ShareChallenge/ShareButton.tsx new file mode 100644 index 00000000..14e0f851 --- /dev/null +++ b/src/components/creator/Editor/ActionButtons/ShareChallenge/ShareButton.tsx @@ -0,0 +1,68 @@ +import { CreatorActionButton } from "../CreatorActionButton"; +import DownloadIcon from '@mui/icons-material/Download'; +import { useContext, useState } from "react"; +import { Dialog, DialogContent, DialogTitle, InputAdornment, Stack, TextField } from "@mui/material"; +import { CreatorContext } from "../../CreatorContext"; +import { Buttons, CopyToClipboardButton } from "./ShareModalButtons"; +import { useTranslation } from "react-i18next"; + +export const ShareButton = () => { + + const [dialogOpen, setDialogOpen] = useState(false) + + return <> + + { setDialogOpen(true) }} startIcon={} nametag='share' isshortversion={true} /> + + +} + +const ShareDialog = ({ open, setDialogOpen }: { open: boolean, setDialogOpen: (open: boolean) => void }) => { + + const { t } = useTranslation('creator'); + + return <> + { setDialogOpen(false) }}> + {t('editor.buttons.share')} + + + + + +} + +const ShareModal = () => { + const { shareId } = useContext(CreatorContext) + + const APP_URL = 'https://pilasbloques.program.ar/online' + const DEV_URL = 'localhost:3000' + + const sharedLink = (process.env.NODE_ENV === 'production' ? APP_URL : DEV_URL) + `/#/desafio/guardado/${shareId}` + + //const link: string = `http://localhost:3000/#/desafio/guardado/${shareId}` + + return + {shareId ? + + + + + ) + }} + /> + + : <> + } + + +} + + + + diff --git a/src/components/creator/Editor/ActionButtons/ShareChallenge/ShareModalButtons.tsx b/src/components/creator/Editor/ActionButtons/ShareChallenge/ShareModalButtons.tsx new file mode 100644 index 00000000..3696a35a --- /dev/null +++ b/src/components/creator/Editor/ActionButtons/ShareChallenge/ShareModalButtons.tsx @@ -0,0 +1,106 @@ +import ShareIcon from '@mui/icons-material/Share'; +import SaveIcon from '@mui/icons-material/Save'; +import ContentCopyIcon from '@mui/icons-material/ContentCopy'; +import { ReactNode, useContext, useState } from "react" +import { IconButtonTooltip } from "../../SceneEdition/IconButtonTooltip" +import { Snackbar, Stack, Tooltip } from "@mui/material" +import { CreatorContext } from '../../CreatorContext'; +import { LocalStorage } from '../../../../../localStorage'; +import { PilasBloquesApi } from '../../../../../pbApi'; +import { CreatorActionButton } from '../CreatorActionButton'; +import { DialogSnackbar } from '../../../../dialogSnackbar/DialogSnackbar'; +import { useTranslation } from 'react-i18next'; +import { SerializedChallenge } from '../../../../serializedChallenge'; +import { DownloadButton } from '../DownloadButton'; + +export const CopyToClipboardButton = ({ textToCopy }: { textToCopy: string }) => { + + const [openSnackbar, setOpenSnackbar] = useState(false) + + const { t } = useTranslation('creator'); + + const handleClick = () => { + setOpenSnackbar(true) + navigator.clipboard.writeText(textToCopy) + } + + return <> + } onClick={handleClick} tooltip={t('editor.buttons.copyToClipboard')} /> + setOpenSnackbar(false)} + autoHideDuration={2000} + message={t('editor.buttons.copiedToClipboard')} + /> + +} + +export const Buttons = () => { + const { shareId } = useContext(CreatorContext) + + return <> + + {shareId ? : } + + + +} + +const ShareUrlButton = () => { + + const shareChallenge = async (): Promise => { + const challenge: SerializedChallenge = LocalStorage.getCreatorChallenge()! + const sharedChallenge = await PilasBloquesApi.shareChallenge(challenge) + + return sharedChallenge.sharedId + } + + return } nametag="shareUrl" challengeUpsert={shareChallenge} /> +} +const SaveButton = () => { + const [openSnackbar, setOpenSnackbar] = useState(false) + + const { t } = useTranslation('creator'); + + const saveChallenge = async (): Promise => { + const savedChallenge = await PilasBloquesApi.saveChallenge(LocalStorage.getCreatorChallenge()!) + setOpenSnackbar(true) + return savedChallenge.sharedId + } + + return <> + } nametag="save" challengeUpsert={saveChallenge} /> + setOpenSnackbar(false)} + autoHideDuration={2000} + message={t('editor.buttons.savedCorrectly')} + /> + +} + +const ChallengeUpsertButton = ({ Icon, challengeUpsert, nametag }: { Icon: ReactNode, nametag: string, challengeUpsert: () => Promise }) => { + + const { setShareId } = useContext(CreatorContext) + const userLoggedIn = !!LocalStorage.getUser() + const [serverError, setServerError] = useState(false) + const { t } = useTranslation('creator'); + + const handleClick = async () => { + try { + setShareId(await challengeUpsert()) + } + catch (error) { + setServerError(true) + } + } + + return <> + +
+ +
+
+ setServerError(false)} message={t('editor.serverError')} /> + +} \ No newline at end of file diff --git a/src/components/creator/Editor/Editor.tsx b/src/components/creator/Editor/Editor.tsx index 93e58538..96607895 100644 --- a/src/components/creator/Editor/Editor.tsx +++ b/src/components/creator/Editor/Editor.tsx @@ -11,7 +11,7 @@ import { useThemeContext } from "../../../theme/ThemeContext"; import { useNavigate } from "react-router-dom"; import { LocalStorage } from "../../../localStorage"; import { useEffect } from "react"; -import { ShareButton } from "./ActionButtons/ShareButton"; +import { ShareButton } from "./ActionButtons/ShareChallenge/ShareButton"; export const CreatorEditor = () => { const { theme } = useThemeContext()