Skip to content

Commit

Permalink
styles(media): adjustments from design feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dcshzj committed Nov 10, 2023
1 parent c6c108f commit 2301e3b
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const createMediaFolderModalTemplate: StoryFn<
<CreateMediaFolderModal
originalSelectedMedia={originalSelectedMedia}
mediaLabels={getMediaLabels("images")}
mediaType="images"
subDirectories={{ directories: [] }}
mediaData={[
MOCK_MEDIA_ITEM_ONE,
Expand Down
53 changes: 37 additions & 16 deletions src/components/CreateMediaFolderModal/CreateMediaFolderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ import { UseMutateAsyncFunction } from "react-query"
import { DirectorySettingsSchema } from "components/DirectorySettingsModal"
import { ImagePreviewCard } from "components/ImagePreviewCard"

import { FilePreviewCard } from "layouts/Media/components"

import { getSelectedMediaDto } from "utils/media"

import { GetMediaSubdirectoriesDto, MediaData } from "types/directory"
import { MiddlewareError } from "types/error"
import {
MediaFolderCreationInfo,
MediaFolderTypes,
MediaLabels,
SelectedMediaDto,
} from "types/media"

interface CreateMediaFolderModalProps {
originalSelectedMedia: SelectedMediaDto[]
mediaLabels: MediaLabels
mediaType: MediaFolderTypes
subDirectories: GetMediaSubdirectoriesDto | undefined
mediaData: (MediaData | undefined)[]
isWriteDisabled: boolean | undefined
Expand Down Expand Up @@ -84,6 +88,7 @@ const getButtonLabel = (
export const CreateMediaFolderModal = ({
originalSelectedMedia,
mediaLabels,
mediaType,
subDirectories,
mediaData,
isWriteDisabled,
Expand Down Expand Up @@ -158,17 +163,19 @@ export const CreateMediaFolderModal = ({
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(onSubmit)}>
<ModalContent my="4rem">
<ModalCloseButton />
<ModalCloseButton top="1.5rem" insetEnd="2rem" />

<ModalHeader pt="2rem" pb={0} px="2rem">
Create a new {singularDirectoryLabel}
{originalSelectedMedia.length > 0
? ` with ${originalSelectedMedia.length} ${
originalSelectedMedia.length === 1
? singularMediaLabel
: pluralMediaLabel
}`
: ""}
<Text as="h4" textStyle="h4" mr="2.5rem">
Create a new {singularDirectoryLabel}
{originalSelectedMedia.length > 0
? ` with ${originalSelectedMedia.length} ${
originalSelectedMedia.length === 1
? singularMediaLabel
: pluralMediaLabel
}`
: ""}
</Text>
</ModalHeader>

<ModalBody px="2rem" pt="1rem" pb={0}>
Expand Down Expand Up @@ -213,15 +220,28 @@ export const CreateMediaFolderModal = ({
py="1rem"
>
<SimpleGrid columns={3} spacing="1.5rem" w="100%">
{mediaData.map(
(data) =>
{mediaData.map((data) =>
data && mediaType === "images" ? (
<ImagePreviewCard
key={data.name}
name={data.name}
addedTime={data.addedTime}
mediaUrl={data.mediaUrl}
imageHeight="10.5rem"
isSelected={methods
.watch("selectedPages")
.some(
(selectedData) =>
selectedData.filePath === data.mediaPath
)}
isMenuNeeded={false}
onClick={() => handleSelect(data)}
onCheck={() => handleSelect(data)}
/>
) : (
data && (
<ImagePreviewCard
key={data.name}
<FilePreviewCard
name={data.name}
addedTime={data.addedTime}
mediaUrl={data.mediaUrl}
imageHeight="10.5rem"
isSelected={methods
.watch("selectedPages")
.some(
Expand All @@ -233,6 +253,7 @@ export const CreateMediaFolderModal = ({
onCheck={() => handleSelect(data)}
/>
)
)
)}
</SimpleGrid>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DeleteMediaModal/DeleteMediaModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const DeleteMediaModal = ({
{selectedMedia.length === 1 && (
<>
<ModalHeader>
<Text as="h4" textStyle="h4">
<Text as="h4" textStyle="h4" mr="2.5rem">
Delete {selectedMedia[0].filePath.split("/").pop()}?
</Text>
</ModalHeader>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MoveMediaModal/MoveMediaModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const MoveMediaModal = ({
<ModalCloseButton />

<ModalHeader>
<Text as="h4" textStyle="h4">
<Text as="h4" textStyle="h4" mr="2.5rem">
Move{" "}
{selectedMedia.length === 1
? getLastChildOfPath(selectedMedia[0].filePath)
Expand Down
17 changes: 15 additions & 2 deletions src/layouts/Media/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export const Media = (): JSX.Element => {
<CreateMediaFolderModal
originalSelectedMedia={selectedMedia}
mediaLabels={getMediaLabels(mediaType)}
mediaType={mediaType}
subDirectories={mediaFolderSubdirectories}
mediaData={files.map(({ data }) => data) || []}
isWriteDisabled={isWriteDisabled}
Expand Down Expand Up @@ -467,7 +468,11 @@ export const Media = (): JSX.Element => {
<Menu.List>
<Menu.Item onClick={() => onMoveModalOpen()}>
<Icon as={BiFolderOpen} mr="1rem" fontSize="1.25rem" />
Move images to album
Move{" "}
{selectedMedia.length === 1
? singularMediaLabel
: pluralMediaLabel}{" "}
to {singularDirectoryLabel}
</Menu.Item>

{directoryLevel < MAX_MEDIA_LEVELS && (
Expand All @@ -479,7 +484,10 @@ export const Media = (): JSX.Element => {
mr="1rem"
fontSize="1.25rem"
/>
Create new album with images
Create new {singularDirectoryLabel} with{" "}
{selectedMedia.length === 1
? singularMediaLabel
: pluralMediaLabel}
</Menu.Item>
)}

Expand Down Expand Up @@ -638,9 +646,14 @@ export const Media = (): JSX.Element => {
data && (
<FilePreviewCard
name={data.name}
isSelected={selectedMedia.some(
(selectedData) =>
selectedData.filePath === data.mediaPath
)}
onOpen={() =>
setIndividualMedia(getSelectedMediaDto(data))
}
onCheck={() => handleSelect(data)}
onDelete={onDeleteModalOpen}
onMove={onMoveModalOpen}
/>
Expand Down
159 changes: 110 additions & 49 deletions src/layouts/Media/components/FilePreviewCard.tsx
Original file line number Diff line number Diff line change
@@ -1,81 +1,142 @@
import {
LinkBox,
LinkOverlay,
Icon,
Text,
Divider,
HStack,
Box,
} from "@chakra-ui/react"
import { Box, Divider, HStack, Icon, Text } from "@chakra-ui/react"
import { Checkbox } from "@opengovsg/design-system-react"
import { BiChevronRight, BiEditAlt, BiFolder, BiTrash } from "react-icons/bi"
import { Link as RouterLink, useRouteMatch } from "react-router-dom"

import { Card, CardBody } from "components/Card"
import { ContextMenu } from "components/ContextMenu"

import useRedirectHook from "hooks/useRedirectHook"

import { BxFileArchiveSolid } from "assets"

interface FilePreviewCardProps {
name: string
isSelected: boolean
isMenuNeeded?: boolean
onOpen?: () => void
onClick?: () => void
onCheck?: () => void
onDelete?: () => void
onMove?: () => void
}

export const FilePreviewCard = ({
name,
isSelected,
isMenuNeeded = true,
onOpen,
onClick,
onCheck,
onDelete,
onMove,
}: FilePreviewCardProps): JSX.Element => {
const { url } = useRouteMatch()
const { setRedirectToPage } = useRedirectHook()
const encodedName = encodeURIComponent(name)

return (
<Box position="relative" h="100%">
<LinkBox position="relative" h="100%">
<LinkOverlay
as={RouterLink}
to={`${url}/editMediaSettings/${encodedName}`}
<Box position="relative" h="100%" data-group>
{/* Checkbox overlay */}
<Checkbox
position="absolute"
left="1rem"
top="0.5rem"
h="3.25rem"
w="3.25rem"
size="md"
p="1rem"
variant="transparent"
display={isSelected ? "inline-block" : "none"}
_groupHover={{
bg: "transparent",
display: "inline-block",
}}
_focusWithin={{
outline: "none",
}}
zIndex={1}
isChecked={isSelected}
onChange={() => {
if (onCheck) onCheck()
}}
/>

<Box
position="relative"
h="100%"
_hover={{ bg: undefined }}
onClick={(e) => {
// For some weird reason, the onClick event is treated as a submit event
// We can safely disable the default behaviour here since we define the
// onClick behaviour ourselves
e.preventDefault()

if (onClick) {
onClick()
} else {
setRedirectToPage(`${url}/editMediaSettings/${encodedName}`)
}
}}
>
<Card
variant="multi"
_groupHover={{ bg: "interaction.muted.main-hover" }}
>
<Card variant="multi">
<CardBody>
<Icon as={BxFileArchiveSolid} fontSize="1.5rem" fill="icon.alt" />
<Text textStyle="body-1" color="text.label" noOfLines={3}>
{name}
</Text>
</CardBody>
</Card>
</LinkOverlay>
</LinkBox>
<ContextMenu onOpen={onOpen}>
<ContextMenu.Button />
<ContextMenu.List>
<ContextMenu.Item
icon={<BiEditAlt />}
as={RouterLink}
to={`${url}/editMediaSettings/${encodedName}`}
>
<Text>Edit details</Text>
</ContextMenu.Item>
<ContextMenu.Item icon={<BiFolder />} onClick={onMove}>
<HStack spacing="4rem" alignItems="center">
<Text>Move to</Text>
<Icon as={BiChevronRight} fontSize="1.25rem" />
</HStack>
</ContextMenu.Item>
<>
<Divider />
<CardBody>
{!isSelected && (
<Icon
as={BxFileArchiveSolid}
fontSize="1.5rem"
fill="icon.alt"
_groupHover={{
display: "none",
}}
/>
)}
<Text
textStyle="body-1"
color="text.label"
noOfLines={3}
ml={isSelected ? "2.5rem" : 0}
_groupHover={{ marginLeft: "2.5rem" }}
>
{name}
</Text>
</CardBody>
</Card>
</Box>

{isMenuNeeded && (
<ContextMenu onOpen={onOpen}>
<ContextMenu.Button />
<ContextMenu.List>
<ContextMenu.Item
icon={<BiTrash />}
color="interaction.critical.default"
onClick={onDelete}
icon={<BiEditAlt />}
as={RouterLink}
to={`${url}/editMediaSettings/${encodedName}`}
>
Delete file
<Text>Edit details</Text>
</ContextMenu.Item>
<ContextMenu.Item icon={<BiFolder />} onClick={onMove}>
<HStack spacing="4rem" alignItems="center">
<Text>Move to</Text>
<Icon as={BiChevronRight} fontSize="1.25rem" />
</HStack>
</ContextMenu.Item>
</>
</ContextMenu.List>
</ContextMenu>
<>
<Divider />
<ContextMenu.Item
icon={<BiTrash />}
color="interaction.critical.default"
onClick={onDelete}
>
Delete file
</ContextMenu.Item>
</>
</ContextMenu.List>
</ContextMenu>
)}
</Box>
)
}

0 comments on commit 2301e3b

Please sign in to comment.