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

Deploy/epic #691

Merged
merged 16 commits into from
Jul 18, 2024
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
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
import AddressAvatar from '@/components/AddressAvatar'
import Button from '@/components/Button'
import Name from '@/components/Name'
import { env } from '@/env.mjs'
import useAuthorizedForModeration from '@/hooks/useAuthorizedForModeration'
import { TabButton } from '@/modules/chat/HomePage/ChatTabs'
import { getModerationReasonsQuery } from '@/services/datahub/moderation/query'
import { getPaginatedPostIdsByPostIdAndAccount } from '@/services/datahub/posts/queryByAccount'
import { useSendEvent } from '@/stores/analytics'
import { useProfilePostsModal } from '@/stores/profile-posts-modal'
import { cx } from '@/utils/class-names'
import { Transition } from '@headlessui/react'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { createPortal } from 'react-dom'
import { HiOutlineChevronLeft } from 'react-icons/hi2'
import SkeletonFallback from '../../../SkeletonFallback'
import { useModerateWithSuccessToast } from '../ChatItemMenus'
import ProfilePostsList from './ProfilePostsList'

const ProfilePostsListModal = () => {
type Tab = 'all' | 'contest'

type ProfilePostsListModalProps = {
tabsConfig?: {
defaultTab: Tab
}
}

const defaultHubId = env.NEXT_PUBLIC_MAIN_SPACE_ID
const chatIdByTab = {
all: env.NEXT_PUBLIC_MAIN_CHAT_ID,
contest: env.NEXT_PUBLIC_CONTEST_CHAT_ID,
}

const ProfilePostsListModal = ({ tabsConfig }: ProfilePostsListModalProps) => {
const [selectedTab, setSelectedTab] = useState<Tab>(
tabsConfig?.defaultTab || 'all'
)

const router = useRouter()

const {
isOpen,
closeModal,
messageId = '',
chatId = '',
hubId = '',
chatId = tabsConfig ? chatIdByTab[tabsConfig.defaultTab] : '',
hubId = tabsConfig ? defaultHubId : '',
address = '',
openModal,
} = useProfilePostsModal()

const { mutate: moderate } = useModerateWithSuccessToast(messageId, chatId)
Expand Down Expand Up @@ -52,6 +77,10 @@ const ProfilePostsListModal = () => {
closeModal()
}

useEffect(() => {
closeModal()
}, [closeModal, router.asPath])

return createPortal(
<>
<Transition
Expand Down Expand Up @@ -119,6 +148,41 @@ const ProfilePostsListModal = () => {
)}
</div>
<div className='relative mx-auto flex h-full max-h-full min-h-[400px] w-full flex-col items-center px-4'>
{tabsConfig && (
<div className='sticky top-14 mb-2 grid h-12 w-full grid-flow-col items-center gap-4 bg-background px-4'>
<TabButton
tab='all'
selectedTab={selectedTab}
setSelectedTab={(tab) => {
setSelectedTab(tab as any)
openModal({
address,
chatId: chatIdByTab[tab as Tab],
hubId: defaultHubId,
})
}}
size={'md'}
>
All memes
</TabButton>
<TabButton
className='flex flex-col items-center justify-center text-center'
tab='contest'
selectedTab={selectedTab}
setSelectedTab={(tab) => {
setSelectedTab(tab as any)
openModal({
address,
chatId: chatIdByTab[tab as Tab],
hubId: defaultHubId,
})
}}
size={'md'}
>
Contest
</TabButton>
</div>
)}
<ProfilePostsList address={address} chatId={chatId} hubId={hubId} />
</div>
</div>
Expand Down
8 changes: 1 addition & 7 deletions src/components/chats/ChatList/ChatItemContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ function ChatItemContainer(
message,
chatId
)
const isMessageBlockedInOriginalHub = useIsMessageBlocked(
message.struct.spaceId ?? '',
message,
chatId
)
const isMessageBlocked =
isMessageBlockedInCurrentHub || isMessageBlockedInOriginalHub
const isMessageBlocked = isMessageBlockedInCurrentHub

const { content } = message
const { body, extensions } = content || {}
Expand Down
15 changes: 10 additions & 5 deletions src/components/chats/hooks/usePaginatedMessageIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ export default function usePaginatedMessageIds({
const myAddress = useMyMainAddress() ?? ''
// because from server it doesn't have access to myAddress, so we need to use the data without users' unapproved posts as placeholder
const { data: placeholderData } =
getPaginatedPostIdsByPostId.useInfiniteQuery({
postId: chatId,
onlyDisplayUnapprovedMessages: !!onlyDisplayUnapprovedMessages,
myAddress: '',
})
getPaginatedPostIdsByPostId.useInfiniteQuery(
{
postId: chatId,
onlyDisplayUnapprovedMessages: !!onlyDisplayUnapprovedMessages,
myAddress: '',
},
{
enabled: false,
}
)
const { data, fetchNextPage, isLoading } =
getPaginatedPostIdsByPostId.useInfiniteQuery(
{
Expand Down
12 changes: 11 additions & 1 deletion src/components/content-staking/SuperLike.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Thumbsup from '@/assets/emojis/thumbsup.png'
import { env } from '@/env.mjs'
import { useIsAddressBlockedInApp } from '@/hooks/useIsAddressBlockedInApp'
import { getPostQuery, getServerTimeQuery } from '@/services/api/query'
import { useCreateSuperLike } from '@/services/datahub/content-staking/mutation'
Expand Down Expand Up @@ -63,6 +64,13 @@ export function SuperLikeWrapper({
const { mutate: createSuperLike } = useCreateSuperLike()
const { data: superLikeCount } = getSuperLikeCountQuery.useQuery(postId)

const isInContest =
post?.struct.rootPostId === env.NEXT_PUBLIC_CONTEST_CHAT_ID
const isContestEnded = dayjs().isAfter(
dayjs(env.NEXT_PUBLIC_CONTEST_END_TIME)
)
const isInEndedContest = isInContest && isContestEnded

const { canBeLiked: canBeSuperliked, isLoading: loadingCanBeLiked } =
useClientValidationOfPostSuperLike(post?.struct.createdAtTime ?? 0)

Expand Down Expand Up @@ -94,7 +102,8 @@ export function SuperLikeWrapper({
loadingTodayCount ||
loadingCanBeLiked ||
hasLikedMoreThanLimit ||
!message) &&
!message ||
isInEndedContest) &&
!hasILiked

let disabledCause = ''
Expand All @@ -106,6 +115,7 @@ export function SuperLikeWrapper({
disabledCause = `You've liked 10 ${entity} today. Come back tomorrow for more fun!`
else if (!canBeSuperliked)
disabledCause = `You cannot like ${entity}s that are older than 7 days`
else if (isInEndedContest) disabledCause = `Contest has ended`

const handleClick = async (e?: React.MouseEvent<HTMLButtonElement>) => {
// prevent chat menu from opening when clicking this button
Expand Down
8 changes: 8 additions & 0 deletions src/components/extensions/common/CommonChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getRepliedMessageId } from '@/components/chats/utils'
import SuperLike, {
SuperLikeButton,
} from '@/components/content-staking/SuperLike'
import { env } from '@/env.mjs'
import useAuthorizedForModeration from '@/hooks/useAuthorizedForModeration'
import useIsMessageBlocked from '@/hooks/useIsMessageBlocked'
import useIsModerationAdmin from '@/hooks/useIsModerationAdmin'
Expand All @@ -24,6 +25,7 @@ import { isMessageSent } from '@/services/subsocial/commentIds/optimistic'
import { useMyMainAddress } from '@/stores/my-account'
import { cx } from '@/utils/class-names'
import { getTimeRelativeToNow } from '@/utils/date'
import dayjs from 'dayjs'
import Linkify from 'linkify-react'
import { useInView } from 'react-intersection-observer'
import { ExtensionChatItemProps } from '../types'
Expand Down Expand Up @@ -428,18 +430,24 @@ function ApproveUserButton({

function ApproveMemeButton({
messageId,
chatId,
}: {
chatId: string
messageId: string
}) {
const { mutate, isLoading } = useApproveMessage()
const isInContest = chatId === env.NEXT_PUBLIC_CONTEST_CHAT_ID
const isContestEnded = dayjs().isAfter(env.NEXT_PUBLIC_CONTEST_END_TIME)
const isInEndedContest = isInContest && isContestEnded

return (
<Button
variant='greenOutline'
size='sm'
className='whitespace-nowrap px-0 text-xs disabled:!border-text-muted disabled:!text-text-muted disabled:!ring-text-muted'
loadingText='Approving...'
isLoading={isLoading}
disabled={isInEndedContest}
onClick={(e) => {
e.stopPropagation()
mutate({
Expand Down
9 changes: 7 additions & 2 deletions src/components/layouts/MobileNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ function NewMemeNotice() {
return null
}

const RedDot = () => (
<div className='absolute right-0 top-0 h-2 w-2 translate-x-[150%] rounded-full bg-red-500' />
export const RedDot = ({ className }: { className?: string }) => (
<div
className={cx(
'absolute right-0 top-0 h-2 w-2 translate-x-[150%] rounded-full bg-red-500',
className
)}
/>
)

export default MobileNavigation
6 changes: 5 additions & 1 deletion src/components/modals/DailyRewardModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@ export default function DailyRewardModal({
enterTo='opacity-100'
leaveFrom='h-auto'
leaveTo='opacity-0 !duration-150'
onClick={close}
onClick={(e) => {
e.stopPropagation()
close()
}}
/>
{isOpenAnimation && isOpen && selectedClaim && (
<RewardAnimation claim={selectedClaim} close={closeModal} />
)}
<Transition
show={isOpen && !isOpenAnimation}
appear
onClick={(e) => e.stopPropagation()}
className='fixed bottom-0 left-1/2 z-40 mx-auto flex h-auto w-full max-w-screen-md -translate-x-1/2 rounded-t-[10px] bg-background-light outline-none transition duration-300'
enterFrom={cx('opacity-0 translate-y-48')}
enterTo='opacity-100 translate-y-0'
Expand Down
16 changes: 15 additions & 1 deletion src/components/referral/CustomLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Link, { LinkProps } from 'next/link'
import { useRouter } from 'next/router'
import urlJoin from 'url-join'
import { useReferralId } from './ReferralUrlChanger'

Expand All @@ -14,6 +15,7 @@ export default function ProfileLinkCustomLink({
}) {
const refId = useReferralId()
const { href, as } = props
const { pathname } = useRouter()

if (!href) {
return <span {...props} />
Expand All @@ -31,7 +33,19 @@ export default function ProfileLinkCustomLink({
return <a {...props} href={props.href} />
}

return <Link {...props} href={href} />
return (
<Link
{...props}
onClick={(e) => {
if (pathname === href) {
e.stopPropagation()
e.preventDefault()
}
props.onClick?.(e)
}}
href={href}
/>
)
}

function augmentLink(link: LinkProps['href'], refId: string) {
Expand Down
Loading
Loading