Skip to content

Commit

Permalink
Add full screen post image
Browse files Browse the repository at this point in the history
  • Loading branch information
samchuk-vlad committed Aug 8, 2024
1 parent 03cb7bf commit 51c10ad
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 30 deletions.
12 changes: 7 additions & 5 deletions src/components/ClickableMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Modal from './modals/Modal'

export type ClickableMediaProps = Omit<ImageProps, 'onClick'> & {
trigger?: (onClick: () => void) => JSX.Element
enableMaxHeight?: boolean
withBluredImage?: boolean
}

export default function ClickableMedia({
Expand All @@ -29,8 +31,9 @@ export default function ClickableMedia({
<Modal
isOpen={isOpenModal}
closeModal={() => setIsOpenModal(false)}
panelClassName='bg-transparent shadow-none'
contentClassName='!p-0'
panelClassName='bg-transparent shadow-none h-full w-fit'
contentClassName='!p-0 h-full'
containerClassName='h-full'
size='screen-md'
>
<MediaLoader
Expand All @@ -39,10 +42,9 @@ export default function ClickableMedia({
onClick={(e) => e.stopPropagation()}
onContextMenu={(e) => e.stopPropagation()}
src={props.src ?? ''}
className='w-full max-w-screen-md'
containerClassName='h-full'
className='h-full w-full max-w-screen-md'
alt={props.alt ?? ''}
width={1024}
height={1024}
/>
</Modal>
</>
Expand Down
41 changes: 25 additions & 16 deletions src/components/MediaLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type MediaLoaderProps = Omit<ImageProps, 'src' | 'alt'> & {
loadingClassName?: string
placeholderClassName?: string
withSpinner?: boolean
enableMaxHeight?: boolean
withBluredImage?: boolean
}

export default function MediaLoader({
Expand All @@ -21,6 +23,8 @@ export default function MediaLoader({
loadingClassName,
placeholderClassName,
withSpinner,
enableMaxHeight = true,
withBluredImage = true,
...props
}: MediaLoaderProps) {
const [isLoaded, setIsLoaded] = useState(false)
Expand Down Expand Up @@ -86,25 +90,29 @@ export default function MediaLoader({
isLoaded && 'hidden'
)}
/>
<Image
{...commonProps}
style={{ backfaceVisibility: 'hidden', ...commonProps.style }}
loading='eager'
onError={undefined}
onLoad={undefined}
width={10}
height={10}
alt={props.alt || ''}
className={cx(
commonProps.className,
'absolute inset-0 m-0 h-full max-h-96 w-full scale-110 object-cover p-0 blur-lg'
)}
/>
{withBluredImage && (
<Image
{...commonProps}
style={{ backfaceVisibility: 'hidden', ...commonProps.style }}
loading='eager'
onError={undefined}
onLoad={undefined}
width={10}
height={10}
alt={props.alt || ''}
className={cx(
commonProps.className,
'absolute inset-0 m-0 h-full w-full scale-110 object-cover p-0 blur-lg',
{ ['max-h-96']: enableMaxHeight }
)}
/>
)}
<Image
{...commonProps}
loading='eager'
className={cx(
'mx-auto max-h-96 object-contain',
'mx-auto object-contain',
{ ['max-h-96']: enableMaxHeight },
commonProps.className
)}
style={{ backfaceVisibility: 'hidden', ...commonProps.style }}
Expand All @@ -126,7 +134,8 @@ export default function MediaLoader({
) : (
<div
className={cx(
'aspect-square max-h-96 w-full animate-pulse bg-background-lighter',
'aspect-square w-full animate-pulse bg-background-lighter',
{ ['max-h-96']: enableMaxHeight },
placeholderClassName
)}
/>
Expand Down
5 changes: 4 additions & 1 deletion src/components/modals/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ export default function Modal({
id={id}
initialFocus={initialFocus}
className={cx('relative z-40 text-text', className)}
onClick={(e) => e.stopPropagation()}
onClick={(e) => {
e.stopPropagation()
e.preventDefault()
}}
onClose={closeModal}
>
{!withoutOverlay && (
Expand Down
11 changes: 10 additions & 1 deletion src/modules/moderator/BlockAndApproveButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Button from '@/components/Button'
import { useModerationActions } from '@/services/datahub/moderation/mutation'
import { getModerationReasonsQuery } from '@/services/datahub/moderation/query'
import { useApproveMessage } from '@/services/datahub/posts/mutation'
import { useMyMainAddress } from '@/stores/my-account'

type BlockAndApproveButtonsProps = {
chatId: string
Expand Down Expand Up @@ -35,6 +36,7 @@ const BlockMessageButton = ({
onSuccess,
}: BlockAndApproveButtonsProps) => {
const { mutateAsync: moderateMessage, isLoading } = useModerationActions()
const myAddress = useMyMainAddress()
const { data: reasons } = getModerationReasonsQuery.useQuery(null)
const firstReasonId = reasons?.[0].id

Expand All @@ -57,7 +59,12 @@ const BlockMessageButton = ({
setTimeout(() => onSuccess(), 1000)
}
return (
<Button variant='redOutline' onClick={blockMessage} isLoading={isLoading}>
<Button
variant='redOutline'
disabled={!myAddress}
onClick={blockMessage}
isLoading={isLoading}
>
Block
</Button>
)
Expand All @@ -68,6 +75,7 @@ const ApproveMessagesButton = ({
onSuccess,
}: Omit<BlockAndApproveButtonsProps, 'chatId'>) => {
const { mutateAsync, isLoading, isSuccess } = useApproveMessage()
const myAddress = useMyMainAddress()

const approveMessages = async () => {
const approvePromise = selectedMessageIds.map(async (messageId) => {
Expand All @@ -85,6 +93,7 @@ const ApproveMessagesButton = ({
<Button
variant='greenOutline'
onClick={approveMessages}
disabled={!myAddress}
isLoading={isLoading}
>
Approve
Expand Down
28 changes: 26 additions & 2 deletions src/modules/moderator/ModerationMemeItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import AddressAvatar from '@/components/AddressAvatar'
import Button from '@/components/Button'
import ClickableMedia from '@/components/ClickableMedia'
import MediaLoader from '@/components/MediaLoader'
import { ProfilePreviewModalName } from '@/components/ProfilePreviewModalWrapper'
import ChatRelativeTime from '@/components/chats/ChatItem/ChatRelativeTime'
Expand All @@ -7,6 +9,7 @@ import { getPostExtensionProperties } from '@/components/extensions/utils'
import { cx } from '@/utils/class-names'
import { PostData } from '@subsocial/api/types'
import { ComponentProps } from 'react'
import { FaSearchPlus } from 'react-icons/fa'
import ModerationCheckbox from './Checkbox'
import { useModerationContext } from './ModerationContext'

Expand Down Expand Up @@ -45,7 +48,7 @@ export default function ModerationMemeItem({
{...props}
className={cx(
'relative flex h-full w-full flex-col gap-2',
'overflow-hidden rounded-2xl bg-slate-800 pt-2',
'max-h-[350px] overflow-hidden rounded-2xl bg-slate-800 pt-2',
{ ['ring-4 ring-text-primary']: isSelected },
props.className
)}
Expand Down Expand Up @@ -77,6 +80,26 @@ export default function ModerationMemeItem({
</div>
</div>
<div className='flex min-w-fit items-center gap-2'>
<ClickableMedia
enableMaxHeight={false}
withBluredImage={false}
src={imageExt?.image || ''}
alt=''
trigger={(onClick) => (
<Button
onClick={(e) => {
e.preventDefault()
e.stopPropagation()

onClick()
}}
size={'circle'}
variant={'transparent'}
>
<FaSearchPlus />
</Button>
)}
/>
<ModerationCheckbox
checked={selectedPostIds.includes(message.struct.id)}
onChange={() => {
Expand All @@ -89,10 +112,11 @@ export default function ModerationMemeItem({
/>
</div>
</div>

<MediaLoader
containerClassName='overflow-hidden w-full h-full justify-center flex items-center cursor-pointer'
placeholderClassName={cx('w-full aspect-square')}
className='w-full object-contain'
className='h-full w-full object-contain'
src={imageExt?.image}
/>
{body && (
Expand Down
10 changes: 5 additions & 5 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export type AppCommonProps = {
}

export default function App(props: AppProps<AppCommonProps>) {
useEffect(() => {
import('eruda').then(({ default: eruda }) => {
eruda.init()
})
}, [])
// useEffect(() => {
// import('eruda').then(({ default: eruda }) => {
// eruda.init()
// })
// }, [])

return (
<SessionProvider
Expand Down

0 comments on commit 51c10ad

Please sign in to comment.