-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from Program-AR/url-share
Url share
- Loading branch information
Showing
15 changed files
with
390 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
REACT_APP_API_URL=http://localhost:3001 | ||
REACT_APP_PB_APP_URL=http://localhost:3000 | ||
REACT_APP_VERSION=$npm_package_version | ||
REACT_APP_GOOGLE_ANALYTICS_KEY=G-xxxxxx #Not necessary, can be omitted for development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/components/creator/Editor/ActionButtons/ShareChallenge/ShareButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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 { ShareButtons, CopyToClipboardButton } from "./ShareModalButtons"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
export const ShareButton = () => { | ||
|
||
const [dialogOpen, setDialogOpen] = useState<boolean>(false) | ||
|
||
return <> | ||
<ShareDialog open={dialogOpen} setDialogOpen={setDialogOpen} /> | ||
<CreatorActionButton onClick={() => { setDialogOpen(true) }} startIcon={<DownloadIcon />} nametag='share' isshortversion={true} /> | ||
</> | ||
|
||
} | ||
|
||
const ShareDialog = ({ open, setDialogOpen }: { open: boolean, setDialogOpen: (open: boolean) => void }) => { | ||
|
||
const { t } = useTranslation('creator'); | ||
|
||
return <> | ||
<Dialog open={open} onClose={() => { setDialogOpen(false) }}> | ||
<DialogTitle>{t('editor.buttons.share')}</DialogTitle> | ||
<DialogContent > | ||
<ShareModal /> | ||
</DialogContent> | ||
</Dialog > | ||
</> | ||
} | ||
|
||
export const ShareModal = () => { | ||
const { sharedId } = useContext(CreatorContext) | ||
|
||
const sharedLink = process.env.REACT_APP_PB_APP_URL + `/#/desafio/guardado/${sharedId}` | ||
|
||
return <Stack> | ||
{sharedId ? | ||
<Stack direction='row'> | ||
<TextField | ||
sx={{ width: '100%', margin: 1}} | ||
defaultValue={sharedLink} | ||
InputProps={{ | ||
readOnly: true, | ||
endAdornment: ( | ||
<InputAdornment position="end"> | ||
<CopyToClipboardButton textToCopy={sharedLink} /> | ||
</InputAdornment> | ||
) | ||
}} | ||
/> | ||
</Stack> | ||
: <></> | ||
} | ||
<ShareButtons /> | ||
</Stack> | ||
} | ||
|
||
|
||
|
||
|
90 changes: 90 additions & 0 deletions
90
src/components/creator/Editor/ActionButtons/ShareChallenge/ShareModalButtons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
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 <> | ||
<IconButtonTooltip icon={<ContentCopyIcon />} onClick={handleClick} tooltip={t('editor.buttons.copyToClipboard')} /> | ||
<Snackbar | ||
open={openSnackbar} | ||
onClose={() => setOpenSnackbar(false)} | ||
autoHideDuration={2000} | ||
message={t('editor.buttons.copiedToClipboard')} | ||
/> | ||
</> | ||
} | ||
|
||
export const ShareButtons = () => { | ||
const { sharedId } = useContext(CreatorContext) | ||
|
||
return <> | ||
<Stack direction="row" justifyContent="space-between" alignItems='center'> | ||
{// If the challenge has already been saved, show Save, else show Share, which saves for the first time. | ||
sharedId ? <SaveButton /> : <ShareUrlButton /> | ||
} | ||
<DownloadButton /> | ||
</Stack> | ||
</> | ||
} | ||
|
||
const ShareUrlButton = () => | ||
<ChallengeUpsertButton Icon={<ShareIcon />} nametag="shareUrl" challengeUpsert={PilasBloquesApi.shareChallenge} /> | ||
|
||
const SaveButton = () => | ||
<ChallengeUpsertButton Icon={<SaveIcon />} nametag="save" challengeUpsert={PilasBloquesApi.saveChallenge} /> | ||
|
||
export const ChallengeUpsertButton = ({ Icon, challengeUpsert, nametag }: { Icon: ReactNode, nametag: string, challengeUpsert: (challenge: SerializedChallenge) => Promise<SerializedChallenge> }) => { | ||
|
||
const { setSharedId } = useContext(CreatorContext) | ||
const userLoggedIn = !!LocalStorage.getUser() | ||
const [serverError, setServerError] = useState<boolean>(false) | ||
const { t } = useTranslation('creator'); | ||
const [savedSnackbar, setSavedSnackbarOpen] = useState(false) | ||
|
||
const handleClick = async () => { | ||
try { | ||
const savedChallenge = await challengeUpsert(LocalStorage.getCreatorChallenge()!) | ||
setSharedId(savedChallenge.sharedId!) | ||
setSavedSnackbarOpen(true) | ||
} | ||
catch (error) { | ||
setServerError(true) | ||
} | ||
} | ||
|
||
return <> | ||
<Snackbar | ||
open={savedSnackbar} | ||
onClose={() => setSavedSnackbarOpen(false)} | ||
autoHideDuration={2000} | ||
message={t('editor.buttons.savedCorrectly')} | ||
/> | ||
<Tooltip title={!userLoggedIn ? t('editor.loginWarning') : ''} followCursor> | ||
<div> | ||
<CreatorActionButton data-testid="upsertButton" onClick={handleClick} disabled={!userLoggedIn} startIcon={Icon} variant='contained' nametag={nametag} /> | ||
</div> | ||
</Tooltip> | ||
<DialogSnackbar open={serverError} onClose={() => setServerError(false)} message={t('editor.serverError')} /> | ||
</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { LocalStorage } from "../../localStorage" | ||
import { EmberView } from "../emberView/EmberView" | ||
import { Header } from "../header/Header" | ||
import { EMBER_IMPORTED_CHALLENGE_PATH } from "../ImportedChallengeView" | ||
import { CreatorViewHeader } from "./Editor/CreatorViewMode" | ||
|
||
export const SharedChallengeView = () => { | ||
|
||
const challenge = LocalStorage.getImportedChallenge() | ||
|
||
return <> | ||
<Header CenterComponent={<CreatorViewHeader title={challenge.titulo} />} /> | ||
<EmberView height='100%' path={EMBER_IMPORTED_CHALLENGE_PATH} /> | ||
</> | ||
} | ||
|
Oops, something went wrong.