-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ebd090
commit b005252
Showing
8 changed files
with
301 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react'; | ||
import { useOvermind } from 'app/overmind'; | ||
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { Menu } from '@codesandbox/components'; | ||
|
||
export const ContextMenu = ({ | ||
visible, | ||
setVisibility, | ||
position, | ||
sandboxId, | ||
}) => { | ||
const { | ||
actions: { | ||
editor: { forkExternalSandbox }, | ||
profile: { | ||
addFeaturedSandboxes, | ||
removeFeaturedSandboxes, | ||
changeSandboxPrivacy, | ||
deleteSandboxClicked, | ||
}, | ||
}, | ||
state: { | ||
user: loggedInUser, | ||
profile: { current: user }, | ||
}, | ||
} = useOvermind(); | ||
const location = useLocation(); | ||
|
||
if (!visible) return null; | ||
|
||
const myProfile = loggedInUser?.username === user.username; | ||
const likesPage = location.pathname === '/likes'; | ||
|
||
const isFeatured = user.featuredSandboxes | ||
.map(sandbox => sandbox.id) | ||
.includes(sandboxId); | ||
|
||
return ( | ||
<Menu.ContextMenu | ||
visible={visible} | ||
setVisibility={setVisibility} | ||
position={position} | ||
> | ||
{myProfile && !likesPage && ( | ||
<> | ||
{isFeatured ? ( | ||
<Menu.Item onSelect={() => removeFeaturedSandboxes({ sandboxId })}> | ||
Unpin sandbox | ||
</Menu.Item> | ||
) : ( | ||
<Menu.Item onSelect={() => addFeaturedSandboxes({ sandboxId })}> | ||
Pin sandbox | ||
</Menu.Item> | ||
)} | ||
<Menu.Divider /> | ||
</> | ||
)} | ||
<Menu.Item | ||
onSelect={() => { | ||
window.location.href = sandboxUrl({ id: sandboxId }); | ||
}} | ||
> | ||
Open sandbox | ||
</Menu.Item> | ||
<Menu.Item | ||
onSelect={() => { | ||
forkExternalSandbox({ sandboxId, openInNewWindow: true }); | ||
}} | ||
> | ||
Fork sandbox | ||
</Menu.Item> | ||
{myProfile && !likesPage && !isFeatured && ( | ||
<> | ||
<Menu.Divider /> | ||
<Menu.Item | ||
onSelect={() => changeSandboxPrivacy({ sandboxId, privacy: 1 })} | ||
> | ||
Make sandbox unlisted | ||
</Menu.Item> | ||
<Menu.Item | ||
onSelect={() => changeSandboxPrivacy({ sandboxId, privacy: 2 })} | ||
> | ||
Make sandbox private | ||
</Menu.Item> | ||
<Menu.Divider /> | ||
<Menu.Item onSelect={() => deleteSandboxClicked(sandboxId)}> | ||
Delete sandbox | ||
</Menu.Item> | ||
</> | ||
)} | ||
</Menu.ContextMenu> | ||
); | ||
}; |
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,119 @@ | ||
import React from 'react'; | ||
import { Grid, Column, Stack, Text, IconButton } from '@codesandbox/components'; | ||
import css from '@styled-system/css'; | ||
import { useOvermind } from 'app/overmind'; | ||
import { SandboxCard, SkeletonCard } from './SandboxCard'; | ||
import { SANDBOXES_PER_PAGE } from './constants'; | ||
|
||
export const LikedSandboxes = ({ menuControls }) => { | ||
const { | ||
actions: { | ||
profile: { likedSandboxesPageChanged }, | ||
}, | ||
state: { | ||
profile: { | ||
current: { username }, | ||
isLoadingSandboxes, | ||
currentLikedSandboxesPage, | ||
likedSandboxes, | ||
}, | ||
}, | ||
} = useOvermind(); | ||
|
||
// explicitly call it on first page render | ||
React.useEffect(() => { | ||
if (currentLikedSandboxesPage === 1) likedSandboxesPageChanged(1); | ||
}, [currentLikedSandboxesPage, likedSandboxesPageChanged]); | ||
|
||
const sandboxes = ( | ||
(likedSandboxes[username] && | ||
likedSandboxes[username][currentLikedSandboxesPage]) || | ||
[] | ||
) | ||
// only show public sandboxes on profile | ||
.filter(sandbox => sandbox.privacy === 0); | ||
|
||
return ( | ||
<Stack as="section" direction="vertical" gap={6}> | ||
<Stack justify="space-between" align="center"> | ||
<Text size={7} weight="bold"> | ||
Liked Sandboxes | ||
</Text> | ||
</Stack> | ||
|
||
<Grid | ||
rowGap={6} | ||
columnGap={6} | ||
css={{ | ||
gridTemplateColumns: 'repeat(auto-fit, minmax(300px, 1fr))', | ||
}} | ||
> | ||
{isLoadingSandboxes | ||
? Array(SANDBOXES_PER_PAGE) | ||
.fill(true) | ||
.map((_, index) => ( | ||
// eslint-disable-next-line | ||
<Column key={index}> | ||
<SkeletonCard /> | ||
</Column> | ||
)) | ||
: sandboxes.map((sandbox, index) => ( | ||
<Column key={sandbox.id}> | ||
<SandboxCard sandbox={sandbox} menuControls={menuControls} /> | ||
</Column> | ||
))} | ||
</Grid> | ||
<Pagination /> | ||
</Stack> | ||
); | ||
}; | ||
|
||
const Pagination = () => { | ||
const { | ||
actions: { | ||
profile: { likedSandboxesPageChanged }, | ||
}, | ||
state: { | ||
profile: { | ||
currentLikedSandboxesPage, | ||
current: { givenLikeCount }, | ||
}, | ||
}, | ||
} = useOvermind(); | ||
|
||
const numberOfPages = Math.ceil(givenLikeCount / SANDBOXES_PER_PAGE); | ||
|
||
return ( | ||
<nav role="navigation" aria-label="Pagination Navigation"> | ||
<Stack | ||
as="ul" | ||
gap={4} | ||
justify="center" | ||
align="center" | ||
css={css({ marginX: 0, marginY: 10, listStyle: 'none' })} | ||
> | ||
<li> | ||
<IconButton | ||
name="backArrow" | ||
title="Previous page" | ||
onClick={() => | ||
likedSandboxesPageChanged(currentLikedSandboxesPage - 1) | ||
} | ||
disabled={currentLikedSandboxesPage === 1} | ||
/> | ||
</li> | ||
<li> | ||
<IconButton | ||
name="backArrow" | ||
title="Next page" | ||
style={{ transform: 'scaleX(-1)' }} | ||
onClick={() => | ||
likedSandboxesPageChanged(currentLikedSandboxesPage + 1) | ||
} | ||
disabled={currentLikedSandboxesPage === numberOfPages} | ||
/> | ||
</li> | ||
</Stack> | ||
</nav> | ||
); | ||
}; |
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 @@ | ||
export const SANDBOXES_PER_PAGE = 15; |
Oops, something went wrong.