Skip to content

Commit

Permalink
using shorter id
Browse files Browse the repository at this point in the history
  • Loading branch information
dlopezalvas committed Nov 29, 2023
1 parent c8d8200 commit 2ffe770
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
10 changes: 2 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const router = createHashRouter([{
errorElement: <PBError />
},
{
path: "/sharedChallenge/:id",
path: "/desafio/guardado/:id",
element: <SharedChallengeView/>,
errorElement: <PBError />,
loader: async ({ params }) => {
Expand Down Expand Up @@ -116,10 +116,4 @@ function App() {
);
}

export default App;



//{"escena":"new EscenaManic([\"[[-,-,-],[-,-,-],[-,-,A]]\"])","bloques":["MoverACasillaDerecha"],"estiloToolbox":"sinCategorias","debugging":true,"titulo":"Escribí tu título...","enunciado":"Así se verá tu **enunciado**...","consignaInicial":"","customCover":"blob:http://localhost:3000/f7988f0f-27e3-4e2c-88f0-dd5a20fafb38","shouldShowMultipleScenarioHelp":false}

//{"_id":"6564e082bc8a2e429cab11cc","fileVersion":1,"title":"Escribí tu título...","statement":{"description":"Así se verá tu **enunciado**..."},"scene":{"type":"Duba","maps":[[["-","-","-"],["-","-","A"],["-","-","-"]]]},"toolbox":{"blocks":["MoverACasillaDerecha"]},"stepByStep":true,"user":"65158e7ccb667d2909c9c0d0","__v":0}
export default App;
54 changes: 29 additions & 25 deletions src/components/creator/Editor/ActionButtons/ShareButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ShareIcon from '@mui/icons-material/Share';
import SaveIcon from '@mui/icons-material/Save';
import { PilasBloquesApi } from "../../../../pbApi";
import { useContext, useState } from "react";
import { Dialog, DialogContent, DialogTitle, Stack } from "@mui/material";
import { Dialog, DialogContent, DialogTitle, Stack, Tooltip } from "@mui/material";
import { DownloadButton } from "./DownloadButton";
import { CreatorContext } from "../CreatorContext";

Expand All @@ -15,56 +15,60 @@ 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} />
<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 ShareDialog = ({ open, setDialogOpen }: { open: boolean, setDialogOpen: (open: boolean) => void }) => {
const { shareId, setShareId } = useContext(CreatorContext)

const handleShareClick = async () => {
const challengeId: string = (await shareChallenge())._id
const challengeId: string = (await shareChallenge()).sharedId
setShareId(challengeId)
}

return <>
<Dialog open={open} onClose={() => {setDialogOpen(false)}}>
<DialogTitle>Compartir desafio</DialogTitle>
<DialogContent>
<Stack>
{`https://${window.location.hostname}/#/sharedChallenge/${shareId}`}
<Buttons handleShareClick={handleShareClick}/>
</Stack>
</DialogContent>
</Dialog>
</>
<Dialog open={open} onClose={() => { setDialogOpen(false) }}>
<DialogTitle>Compartir desafio</DialogTitle>
<DialogContent>
<Stack>
{`https://${window.location.hostname}/online/#/desafio/guardado/${shareId}`}
<Buttons handleShareClick={handleShareClick} />
</Stack>
</DialogContent>
</Dialog>
</>
}

const Buttons = ({handleShareClick}: {handleShareClick: () => void}) => {
const Buttons = ({ handleShareClick }: { handleShareClick: () => void }) => {
const { shareId } = useContext(CreatorContext)

return <>
<Stack direction="row" justifyContent="space-between">
{shareId ? <SaveButton/> : <ShareUrlButton handleShareClick={handleShareClick}/>}
<DownloadButton/>
</Stack>
</>
<Stack direction="row" justifyContent="space-between">
{shareId ? <SaveButton /> : <ShareUrlButton handleShareClick={handleShareClick} />}
<DownloadButton />
</Stack>
</>
}

const ShareUrlButton = ({handleShareClick}: {handleShareClick: () => void}) =>
<CreatorActionButton onClick={handleShareClick} startIcon={<ShareIcon/>} variant='contained' nametag="shareUrl"/>
const ShareUrlButton = ({ handleShareClick }: { handleShareClick: () => void }) => {

const userLoggedIn = !!LocalStorage.getUser()

return <CreatorActionButton onClick={handleShareClick} disabled={!userLoggedIn} startIcon={<ShareIcon />} variant='contained' nametag="shareUrl"/>
}

const SaveButton = () => {
const { setShareId } = useContext(CreatorContext)

const handleClick = async () => {
const challenge = await PilasBloquesApi.saveChallenge(LocalStorage.getCreatorChallenge()!)
setShareId(challenge._id)
setShareId(challenge.sharedId)
}

return <CreatorActionButton onClick={handleClick} startIcon={<SaveIcon/>} variant='contained' nametag="save"/>
return <CreatorActionButton onClick={handleClick} startIcon={<SaveIcon />} variant='contained' nametag="save" />
}

const shareChallenge = () => {
Expand Down

0 comments on commit 2ffe770

Please sign in to comment.