Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing feature explainer #1477

Merged
merged 14 commits into from
Sep 2, 2021
2 changes: 1 addition & 1 deletion packages/common-components/src/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IDialogClasses {
}

interface IDialogProps
extends Omit<IModalProps, "setActive" | "closePosition" | "children"> {
extends Omit<IModalProps, "closePosition" | "children"> {
accept: () => void
reject: () => void
injectedClass?: IDialogClasses
Expand Down
104 changes: 45 additions & 59 deletions packages/common-components/src/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CloseSvg } from "../Icons/icons/Close.icon"
const useStyles = makeStyles(
({ animation, constants, breakpoints, palette, overrides, zIndex }: ITheme) =>
createStyles({
// JSS in CSS goes here
root: {
position: "fixed",
zIndex: zIndex?.layer3,
Expand All @@ -23,11 +22,6 @@ const useStyles = makeStyles(
borderBottomRightRadius: 0,
transitionDuration: `${animation.transform}ms`,
transitionProperty: "opacity",
"&.closable": {
"&:before": {
cursor: "pointer"
}
},
"&:before": {
content: "''",
display: "block",
Expand Down Expand Up @@ -97,24 +91,23 @@ const useStyles = makeStyles(
},
closeIcon: {
...constants.icon,
borderRadius: "50%",
width: 15,
height: 15,
display: "block",
top: 0,
backgroundColor: palette.common?.white.main,
cursor: "pointer",
position: "absolute",
"& svg": {
height: 15,
width: 15
stroke: palette.common?.black.main
},
"&.right": {
transform: "translate(50%, -50%)",
transform: "translate(-50%, 50%)",
right: 0,
...overrides?.Modal?.closeIcon?.right
},
"&.left": {
left: 0,
transform: "translate(-50%, -50%)",
transform: "translate(50%, -50%)",
...overrides?.Modal?.closeIcon?.left
},
"&.none": {
Expand All @@ -127,19 +120,20 @@ const useStyles = makeStyles(

interface IModalClasses {
inner?: string
close?: string
closeIcon?: string
}

interface IModalProps {
className?: string
active: boolean
setActive?: (state: boolean) => void
injectedClass?: IModalClasses
closePosition?: "left" | "right" | "none"
children?: ReactNode | ReactNode[]
maxWidth?: "xs" | "sm" | "md" | "lg" | "xl" | number
onModalBodyClick?: (e: React.MouseEvent) => void
onClickOutside?: (e?: React.MouseEvent) => void
testId?: string
onClose?: () => void
}

const Modal = ({
Expand All @@ -148,66 +142,58 @@ const Modal = ({
closePosition = "right",
injectedClass,
active = false,
setActive,
maxWidth = "sm",
onModalBodyClick,
testId
testId,
onClose,
onClickOutside
}: IModalProps) => {
const classes = useStyles()

const ref = useRef(null)

const handleClose = () => {
if (active && setActive) {
setActive(false)
}
onClose && onClose()
}

useOnClickOutside(ref, () => handleClose())
useOnClickOutside(ref, () => onClickOutside && onClickOutside())

if (!active) return null

return <article
className={clsx(
classes.root,
className,
setActive ? "closable" : "",
"active"
)}
onClick={onModalBodyClick}
>
<section
data-testid={`modal-container-${testId}`}
ref={ref}
style={
maxWidth && typeof maxWidth == "number"
? {
width: "100%",
maxWidth: maxWidth
}
: {}
}
className={clsx(
classes.inner,
return (
<article
className={clsx(classes.root, className, "active")}
onClick={onModalBodyClick}
>
<section
data-testid={`modal-container-${testId}`}
ref={ref}
style={
maxWidth && typeof maxWidth == "number"
? {
width: "100%",
maxWidth: maxWidth
}
: {}
}
className={clsx(
classes.inner,
injectedClass?.inner,
typeof maxWidth != "number" ? maxWidth : ""
)}
>
{setActive && (
<div
onClick={() => handleClose()}
className={clsx(
classes.closeIcon,
injectedClass?.close,
closePosition
)}
>
<CloseSvg />
</div>
)}
{children}
</section>
</article>
)}
>
{closePosition !== "none" && (
<div
onClick={handleClose}
className={clsx(classes.closeIcon, injectedClass?.closeIcon, closePosition)}
>
<CloseSvg />
</div>
)}
{children}
</section>
</article>
)
}

export default Modal
Expand Down
2 changes: 1 addition & 1 deletion packages/common-components/src/stories/Modal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export const ModalStory = (): React.ReactNode => {
</Button>
<Modal
active={active}
setActive={setActive}
maxWidth={select("Max width position", maxWidthOptions, "md")}
closePosition={select("Close position", closePositionOptions, "left")}
onClose={() => setActive(false)}
>
<Typography>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Voluptas,
Expand Down
2 changes: 1 addition & 1 deletion packages/files-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const App = () => {
<Modal
active
closePosition="none"
setActive={resetError}
onClose={resetError}
>
<Typography>
An error occurred and has been logged. If you would like to
Expand Down
11 changes: 7 additions & 4 deletions packages/files-ui/src/Components/Elements/CustomModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const useStyles = makeStyles(({ constants, breakpoints }: CSFTheme) =>
}
},
inner: {
backgroundColor: constants.modalDefault.backgroundColor,
color: constants.modalDefault.color,
[breakpoints.down("md")]: {
backgroundColor: constants.modalDefault.background,
top: "unset",
bottom: 0,
left: 0,
Expand All @@ -25,8 +26,10 @@ const useStyles = makeStyles(({ constants, breakpoints }: CSFTheme) =>
borderRadiusRightBottom: 0
}
},
close: {
[breakpoints.down("md")]: {}
closeIcon : {
"& svg": {
stroke: constants.modalDefault.closeIconColor
}
}
})
)
Expand All @@ -49,7 +52,7 @@ const CustomModal: React.FC<ICustomModal> = ({
<Modal
className={clsx(classes.root, className)}
injectedClass={{
close: clsx(classes.close, injectedClass?.close),
closeIcon: clsx(classes.closeIcon, injectedClass?.closeIcon),
inner: clsx(classes.inner, injectedClass?.inner)
}}
{...rest}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const useStyles = makeStyles(({ breakpoints, constants }: CSFTheme) =>
minHeight: 550
},
[breakpoints.down("sm")]: {
backgroundColor: constants?.modalDefault?.background,
backgroundColor: constants?.modalDefault?.backgroundColor,
top: "unset",
bottom: 0,
left: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ const useStyles = makeStyles(
alignItems: "center"
},
modalRoot: {
zIndex: zIndex?.blocker,
[breakpoints.down("md")]: {}
zIndex: zIndex?.blocker
},
modalInner: {
backgroundColor: constants.createShareModal.backgroundColor,
color: constants.createShareModal.color,
backgroundColor: constants.modalDefault.backgroundColor,
color: constants.modalDefault.color,
[breakpoints.down("md")]: {
bottom:
Number(constants?.mobileButtonHeight) + constants.generalUnit,
Expand All @@ -54,12 +53,12 @@ const useStyles = makeStyles(
lineHeight: "22px"
},
heading: {
color: constants.createShareModal.color,
color: constants.modalDefault.color,
fontWeight: typography.fontWeight.semibold,
marginBottom: 10
},
iconBacking: {
backgroundColor: constants.createShareModal.iconBackingColor,
backgroundColor: constants.modalDefault.iconBackingColor,
width: 48,
height: 48,
borderRadius: 24,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ const useStyles = makeStyles(
}
},
heading: {
color: constants.createShareModal.color,
color: constants.modalDefault.color,
fontWeight: typography.fontWeight.semibold,
marginBottom: 10
},
iconBacking: {
backgroundColor: constants.createShareModal.iconBackingColor,
backgroundColor: constants.modalDefault.iconBackingColor,
width: 48,
height: 48,
borderRadius: 24,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { useFilesApi } from "../../../Contexts/FilesApiContext"
import { ROUTE_LINKS } from "../../FilesRoutes"
import SharedFolderRow from "./views/FileSystemItem/SharedFolderRow"
import { SharedFolderModalMode } from "./types"
import SharingExplainerModal from "../../SharingExplainerModal"
import { useSharingExplainerModalFlag } from "./hooks/useSharingExplainerModalFlag"

export const desktopSharedGridSettings = "69px 3fr 120px 190px 150px 45px !important"
export const mobileSharedGridSettings = "3fr 80px 45px !important"
Expand Down Expand Up @@ -101,24 +103,25 @@ const useStyles = makeStyles(
}
)

type SortingType = "name" | "size" | "date_uploaded"

const SharedFolderOverview = () => {
const classes = useStyles()
const { filesApiClient } = useFilesApi()
const { buckets, isLoadingBuckets, refreshBuckets } = useFiles()
const [createOrEditSharedFolderMode, setCreateOrEditSharedFolderMode] = useState<SharedFolderModalMode | undefined>(undefined)
const [bucketToEdit, setBucketToEdit] = useState<BucketKeyPermission | undefined>(undefined)
const [direction, setDirection] = useState<SortDirection>("ascend")
const [column, setColumn] = useState<"name" | "size" | "date_uploaded">("name")
const [column, setColumn] = useState<SortingType>("name")
const { redirect } = useHistory()
const { desktop } = useThemeSwitcher()
const [bucketToDelete, setBucketToDelete] = useState<BucketKeyPermission | undefined>(undefined)
const [isDeleteBucketModalOpen, setIsDeleteBucketModalOpen] = useState(false)
const [isDeletingSharedFolder, setIsDeletingSharedFolder] = useState(false)
const bucketsToShow = useMemo(() => buckets.filter(b => b.type === "share" && b.status !== "deleting"), [buckets])
const { hasSeenSharingExplainerModal, hideModal } = useSharingExplainerModalFlag()

const handleSortToggle = (
targetColumn: "name" | "size" | "date_uploaded"
) => {
const handleSortToggle = (targetColumn: SortingType) => {
if (column !== targetColumn) {
setColumn(targetColumn)
setDirection("descend")
Expand Down Expand Up @@ -261,6 +264,10 @@ const SharedFolderOverview = () => {
</Table>
)}
</article>
<SharingExplainerModal
showModal={hasSeenSharingExplainerModal}
onHide={hideModal}
/>
<CreateOrEditSharedFolderModal
mode={createOrEditSharedFolderMode}
isModalOpen={!!createOrEditSharedFolderMode}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useLocalStorage } from "@chainsafe/browser-storage-hooks"
import { useCallback } from "react"
import { useEffect, useState } from "react"

export const DISMISSED_SHARING_EXPLAINER_KEY = "csf.dismissedSharingExplainer"

export const useSharingExplainerModalFlag = () => {
const { localStorageGet, localStorageSet } = useLocalStorage()
const [hasSeenSharingExplainerModal, setHasSeenSharingExplainerModal] = useState(false)
const dismissedFlag = localStorageGet(DISMISSED_SHARING_EXPLAINER_KEY)

useEffect(() => {
Tbaut marked this conversation as resolved.
Show resolved Hide resolved
if (dismissedFlag === "false"){
setHasSeenSharingExplainerModal(true)
}
}, [dismissedFlag])

useEffect(() => {
// the dismiss flag was never set
if (dismissedFlag === null) {
localStorageSet(DISMISSED_SHARING_EXPLAINER_KEY, "false")
setHasSeenSharingExplainerModal(true)
}
}, [dismissedFlag, localStorageSet])

const hideModal = useCallback(() => {
localStorageSet(DISMISSED_SHARING_EXPLAINER_KEY, "true")
setHasSeenSharingExplainerModal(false)
}, [localStorageSet])

return { hasSeenSharingExplainerModal, hideModal }
}
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ const FileSystemItem = ({
}}
closePosition="none"
active={editing === cid}
setActive={() => setEditing("")}
onClose={() => setEditing("")}
>
<FormikProvider value={formik}>
<Form className={classes.renameModal}>
Expand Down
Loading