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

feat: replace native confirm #612

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/web/src/components/Bytes/CommentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const CommentModal: FC<Props> = ({ trigger, video }) => {
}
panelClassName="max-w-lg lg:ml-9"
show={show}
autoClose
onClose={() => setShow(false)}
>
<div className="no-scrollbar max-h-[40vh] overflow-y-auto pt-3">
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/components/Common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ const Header: FC<Props> = ({ className }) => {
</div>
{showFilter && <CategoryFilters />}
</div>

<Modal
title="Search"
onClose={() => setSearchModal(false)}
Expand Down
143 changes: 73 additions & 70 deletions apps/web/src/components/Common/VideoCard/VideoOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LENS_PERIPHERY_ABI } from '@abis/LensPeriphery'
import Confirm from '@components/UIElements/Confirm'
import DropMenu, { NextLink } from '@components/UIElements/DropMenu'
import { Menu } from '@headlessui/react'
import useAppStore from '@lib/store'
Expand All @@ -17,7 +18,7 @@ import {
useHidePublicationMutation
} from 'lens'
import type { FC } from 'react'
import React from 'react'
import React, { useState } from 'react'
import toast from 'react-hot-toast'
import type { CustomErrorWithData } from 'utils'
import {
Expand Down Expand Up @@ -56,6 +57,7 @@ const VideoOptions: FC<Props> = ({
setShowReport,
showOnHover = true
}) => {
const [showConfirm, setShowConfirm] = useState(false)
const selectedChannel = useAppStore((state) => state.selectedChannel)
const selectedChannelId = usePersistStore((state) => state.selectedChannelId)
const isVideoOwner = selectedChannel?.id === video?.profile?.id
Expand All @@ -77,13 +79,7 @@ const VideoOptions: FC<Props> = ({
})

const onHideVideo = () => {
if (
confirm(
'This will hide your video from lens, are you sure want to continue?\n\nNote: This cannot be reverted.'
)
) {
hideVideo({ variables: { request: { publicationId: video?.id } } })
}
hideVideo({ variables: { request: { publicationId: video?.id } } })
}

const onClickReport = () => {
Expand Down Expand Up @@ -225,73 +221,80 @@ const VideoOptions: FC<Props> = ({
}

return (
<DropMenu
trigger={
<div
onClick={() => Analytics.track(TRACK.CLICK_VIDEO_OPTIONS)}
className={clsx(
'py-1 text-white group-hover:visible md:text-inherit',
showOnHover && 'lg:invisible'
)}
role="button"
>
<ThreeDotsOutline className="h-3.5 w-3.5" />
</div>
}
>
<div className="bg-secondary mt-0.5 w-36 overflow-hidden rounded-xl border border-gray-200 p-1 shadow dark:border-gray-800">
<div className="flex flex-col rounded-lg text-sm transition duration-150 ease-in-out">
{isVideoOwner && (
<>
{pinnedVideoId !== video.id && (
<>
<Confirm
showConfirm={showConfirm}
setShowConfirm={setShowConfirm}
action={onHideVideo}
/>
<DropMenu
trigger={
<div
onClick={() => Analytics.track(TRACK.CLICK_VIDEO_OPTIONS)}
className={clsx(
'py-1 text-white group-hover:visible md:text-inherit',
showOnHover && 'lg:invisible'
)}
role="button"
>
<ThreeDotsOutline className="h-3.5 w-3.5" />
</div>
}
>
<div className="bg-secondary mt-0.5 w-36 overflow-hidden rounded-xl border border-gray-200 p-1 shadow dark:border-gray-800">
<div className="flex flex-col rounded-lg text-sm transition duration-150 ease-in-out">
{isVideoOwner && (
<>
{pinnedVideoId !== video.id && (
<Menu.Item
as="button"
className="flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800"
onClick={() => onPinVideo()}
>
<PinOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Pin Video</span>
</Menu.Item>
)}
<Menu.Item
as={NextLink}
href={getPublicationMediaUrl(video)}
target="_blank"
>
<div className="flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800">
<ExternalOutline className="h-3 w-3" />
<span className="whitespace-nowrap">Raw Video</span>
</div>
</Menu.Item>
<Menu.Item
as="button"
className="flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800"
onClick={() => onPinVideo()}
className="inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 text-red-500 opacity-100 hover:bg-red-100 dark:hover:bg-red-900"
onClick={() => setShowConfirm(true)}
>
<PinOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Pin Video</span>
<TrashOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Delete</span>
</Menu.Item>
)}
<Menu.Item
as={NextLink}
href={getPublicationMediaUrl(video)}
target="_blank"
>
<div className="flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800">
<ExternalOutline className="h-3 w-3" />
<span className="whitespace-nowrap">Raw Video</span>
</div>
</Menu.Item>
<Menu.Item
as="button"
className="inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 text-red-500 opacity-100 hover:bg-red-100 dark:hover:bg-red-900"
onClick={() => onHideVideo()}
>
<TrashOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Delete</span>
</Menu.Item>
</>
)}
<button
type="button"
onClick={() => setShowShare(true)}
className="inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800"
>
<ShareOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Share</span>
</button>
<button
type="button"
onClick={() => onClickReport()}
className="hhover:opacity-100 inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800"
>
<FlagOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Report</span>
</button>
</>
)}
<button
type="button"
onClick={() => setShowShare(true)}
className="inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800"
>
<ShareOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Share</span>
</button>
<button
type="button"
onClick={() => onClickReport()}
className="hhover:opacity-100 inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800"
>
<FlagOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Report</span>
</button>
</div>
</div>
</div>
</DropMenu>
</DropMenu>
</>
)
}

Expand Down
37 changes: 37 additions & 0 deletions apps/web/src/components/UIElements/Confirm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Dispatch, FC } from 'react'
import React from 'react'

import { Button } from './Button'
import Modal from './Modal'

type Props = {
showConfirm: boolean
setShowConfirm: Dispatch<boolean>
action: () => void
}

const Confirm: FC<Props> = ({ showConfirm, setShowConfirm, action }) => {
return (
<Modal
title="Confirmation"
panelClassName="max-w-lg"
show={showConfirm}
onClose={() => setShowConfirm(false)}
>
<div className="pt-4">
<h5 className="pb-3">Are you sure want to continue?</h5>
<span className="text-red-500 opacity-75">
This cannot be reverted.
</span>
<div className="flex justify-end space-x-2 pt-2">
<Button variant="hover" onClick={() => setShowConfirm(false)}>
Cancel
</Button>
<Button onClick={action}>Confirm</Button>
</div>
</div>
</Modal>
)
}

export default Confirm
10 changes: 2 additions & 8 deletions apps/web/src/components/UIElements/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,18 @@ type Props = {
onClose?: () => void
children: React.ReactNode
panelClassName?: string
autoClose?: boolean
}

const Modal: FC<Props> = ({
show,
onClose,
children,
title,
panelClassName,
autoClose = true
panelClassName
}) => {
return (
<Transition appear show={show} as={Fragment}>
<Dialog
as="div"
className="relative z-20"
onClose={() => (onClose && !autoClose ? onClose?.() : null)}
>
<Dialog as="div" className="relative z-20" onClose={() => onClose?.()}>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
Expand Down
69 changes: 36 additions & 33 deletions apps/web/src/components/Watch/CommentOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import FlagOutline from '@components/Common/Icons/FlagOutline'
import ThreeDotsOutline from '@components/Common/Icons/ThreeDotsOutline'
import Confirm from '@components/UIElements/Confirm'
import DropMenu from '@components/UIElements/DropMenu'
import useAppStore from '@lib/store'
import type { Publication } from 'lens'
import { useHidePublicationMutation } from 'lens'
import type { Dispatch, FC } from 'react'
import React from 'react'
import React, { useState } from 'react'
import toast from 'react-hot-toast'
import { AiOutlineDelete } from 'react-icons/ai'
import { Analytics, TRACK } from 'utils'
Expand All @@ -16,6 +17,7 @@ type Props = {
}

const CommentOptions: FC<Props> = ({ comment, setShowReport }) => {
const [showConfirm, setShowConfirm] = useState(false)
const selectedChannel = useAppStore((state) => state.selectedChannel)

const [hideComment] = useHidePublicationMutation({
Expand All @@ -34,46 +36,47 @@ const CommentOptions: FC<Props> = ({ comment, setShowReport }) => {
})

const onHideComment = () => {
if (
confirm(
'This will hide your comment from lens, are you sure want to continue?\n\nNote: This cannot be reverted.'
)
) {
hideComment({ variables: { request: { publicationId: comment?.id } } })
}
hideComment({ variables: { request: { publicationId: comment?.id } } })
}

return (
<DropMenu
trigger={
<div className="p-1">
<ThreeDotsOutline className="h-3.5 w-3.5" />
</div>
}
>
<div className="bg-secondary mt-0.5 w-36 overflow-hidden rounded-lg border border-gray-200 p-1 shadow dark:border-gray-800">
<div className="flex flex-col rounded-lg text-sm transition duration-150 ease-in-out">
{selectedChannel?.id === comment?.profile?.id && (
<>
<Confirm
showConfirm={showConfirm}
setShowConfirm={setShowConfirm}
action={onHideComment}
/>
<DropMenu
trigger={
<div className="p-1">
<ThreeDotsOutline className="h-3.5 w-3.5" />
</div>
}
>
<div className="bg-secondary mt-0.5 w-36 overflow-hidden rounded-xl border border-gray-200 p-1 shadow dark:border-gray-800">
<div className="flex flex-col rounded-lg text-sm transition duration-150 ease-in-out">
{selectedChannel?.id === comment?.profile?.id && (
<button
type="button"
onClick={() => setShowConfirm(true)}
className="inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 text-red-500 hover:bg-red-100 dark:hover:bg-red-900"
>
<AiOutlineDelete className="text-base" />
<span className="whitespace-nowrap">Delete</span>
</button>
)}
<button
type="button"
onClick={() => onHideComment()}
className="inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 text-red-500 hover:bg-red-100 dark:hover:bg-red-900"
onClick={() => setShowReport(true)}
className="inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800"
>
<AiOutlineDelete className="text-base" />
<span className="whitespace-nowrap">Delete</span>
<FlagOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Report</span>
</button>
)}
<button
type="button"
onClick={() => setShowReport(true)}
className="inline-flex items-center space-x-2 rounded-lg px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800"
>
<FlagOutline className="h-3.5 w-3.5" />
<span className="whitespace-nowrap">Report</span>
</button>
</div>
</div>
</div>
</DropMenu>
</DropMenu>
</>
)
}

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Watch/SuggestedVideoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ const SuggestedVideoCard: FC<Props> = ({ video }) => {
</div>
</div>
<VideoOptions
setShowReport={setShowReport}
video={video}
setShowReport={setShowReport}
setShowShare={setShowShare}
/>
</div>
Expand Down
15 changes: 9 additions & 6 deletions apps/web/src/components/Watch/VideoComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ const VideoComments: FC<Props> = ({ video, hideTitle = false }) => {
/>
)
)}
{comments?.map((comment: Publication) => (
<Comment
key={`${comment?.id}_${comment.createdAt}`}
comment={comment}
/>
))}
{comments?.map(
(comment: Publication) =>
!comment.hidden && (
<Comment
key={`${comment?.id}_${comment.createdAt}`}
comment={comment}
/>
)
)}
</div>
{pageInfo?.next && (
<span ref={observe} className="flex justify-center p-10">
Expand Down