Skip to content

Commit

Permalink
saved correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dlopezalvas committed Dec 1, 2023
1 parent c71387a commit 0affc09
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions locales/en-us/creator.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"shareUrlShort": "Share",
"save": "Save challenge",
"saveShort": "Save",
"savedCorrectly": "Challenge was saved correctly",
"copyToClipboard": "Copy to clipboard",
"copiedToClipboard": "Copied to clipboard",
"preview": "Challenge preview",
Expand Down
1 change: 1 addition & 0 deletions locales/es-ar/creator.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import { DownloadButton } from '../DownloadButton';

export const CopyToClipboardButton = ({ textToCopy }: { textToCopy: string }) => {

const [open, setOpen] = useState(false)
const [openSnackbar, setOpenSnackbar] = useState(false)

const { t } = useTranslation('creator');

const handleClick = () => {
setOpen(true)
setOpenSnackbar(true)
navigator.clipboard.writeText(textToCopy)
}

return <>
<IconButtonTooltip icon={<ContentCopyIcon />} onClick={handleClick} tooltip={t('editor.buttons.copyToClipboard')}/>
<IconButtonTooltip icon={<ContentCopyIcon />} onClick={handleClick} tooltip={t('editor.buttons.copyToClipboard')} />
<Snackbar
open={open}
onClose={() => setOpen(false)}
open={openSnackbar}
onClose={() => setOpenSnackbar(false)}
autoHideDuration={2000}
message={t('editor.buttons.copiedToClipboard')}
/>
Expand Down Expand Up @@ -58,13 +58,25 @@ const ShareUrlButton = () => {
return <ChallengeUpsertButton Icon={<ShareIcon />} nametag="shareUrl" challengeUpsert={shareChallenge} />
}
const SaveButton = () => {
const [openSnackbar, setOpenSnackbar] = useState(false)

const { t } = useTranslation('creator');

const saveChallenge = async (): Promise<string> => {
const savedChallenge = await PilasBloquesApi.saveChallenge(LocalStorage.getCreatorChallenge()!)
setOpenSnackbar(true)
return savedChallenge.sharedId
}

return <ChallengeUpsertButton Icon={<SaveIcon />} nametag="save" challengeUpsert={saveChallenge} />
return <>
<ChallengeUpsertButton Icon={<SaveIcon />} nametag="save" challengeUpsert={saveChallenge} />
<Snackbar
open={openSnackbar}
onClose={() => setOpenSnackbar(false)}
autoHideDuration={2000}
message={t('editor.buttons.savedCorrectly')}
/>
</>
}

const ChallengeUpsertButton = ({ Icon, challengeUpsert, nametag }: { Icon: ReactNode, nametag: string, challengeUpsert: () => Promise<string> }) => {
Expand All @@ -75,20 +87,20 @@ const ChallengeUpsertButton = ({ Icon, challengeUpsert, nametag }: { Icon: React
const { t } = useTranslation('creator');

const handleClick = async () => {
try{
try {
setShareId(await challengeUpsert())
}
catch(error){
catch (error) {
setServerError(true)
}
}

return <>
<Tooltip title={!userLoggedIn ? t('editor.loginWarning') : '' } followCursor>
<Tooltip title={!userLoggedIn ? t('editor.loginWarning') : ''} followCursor>
<div>
<CreatorActionButton onClick={handleClick} disabled={!userLoggedIn} startIcon={Icon} variant='contained' nametag={nametag} />
</div>
</Tooltip>
<DialogSnackbar open={serverError} onClose={() => setServerError(false)} message={t('editor.serverError')}/>
<DialogSnackbar open={serverError} onClose={() => setServerError(false)} message={t('editor.serverError')} />
</>
}

0 comments on commit 0affc09

Please sign in to comment.