2022-09-12 16:34:56 +00:00
|
|
|
import { ControlledTabs } from 'web/components/layout/tabs'
|
2022-07-19 15:04:47 +00:00
|
|
|
import React, { useEffect, useMemo, useState } from 'react'
|
2022-09-12 16:34:56 +00:00
|
|
|
import Router, { useRouter } from 'next/router'
|
2022-09-15 19:39:46 +00:00
|
|
|
import {
|
|
|
|
BetFillData,
|
|
|
|
Notification,
|
|
|
|
notification_source_types,
|
|
|
|
} from 'common/notification'
|
2022-06-23 17:55:41 +00:00
|
|
|
import { Avatar, EmptyAvatar } from 'web/components/avatar'
|
2022-06-01 13:11:25 +00:00
|
|
|
import { Row } from 'web/components/layout/row'
|
|
|
|
import { Page } from 'web/components/page'
|
|
|
|
import { Title } from 'web/components/title'
|
|
|
|
import { doc, updateDoc } from 'firebase/firestore'
|
|
|
|
import { db } from 'web/lib/firebase/init'
|
2022-07-15 17:53:30 +00:00
|
|
|
import {
|
|
|
|
MANIFOLD_AVATAR_URL,
|
|
|
|
MANIFOLD_USERNAME,
|
|
|
|
PrivateUser,
|
|
|
|
} from 'common/user'
|
2022-06-06 17:36:59 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import { RelativeTimestamp } from 'web/components/relative-timestamp'
|
|
|
|
import { Linkify } from 'web/components/linkify'
|
|
|
|
import {
|
2022-06-09 16:30:26 +00:00
|
|
|
BinaryOutcomeLabel,
|
|
|
|
CancelLabel,
|
|
|
|
MultiLabel,
|
2022-07-10 19:52:31 +00:00
|
|
|
NumericValueLabel,
|
2022-06-09 16:30:26 +00:00
|
|
|
ProbPercentLabel,
|
2022-06-06 17:36:59 +00:00
|
|
|
} from 'web/components/outcome-label'
|
2022-06-06 22:15:36 +00:00
|
|
|
import {
|
|
|
|
NotificationGroup,
|
2022-08-28 20:20:21 +00:00
|
|
|
useGroupedNotifications,
|
2022-09-12 20:17:39 +00:00
|
|
|
useUnseenGroupedNotification,
|
2022-06-06 22:15:36 +00:00
|
|
|
} from 'web/hooks/use-notifications'
|
2022-07-19 20:24:36 +00:00
|
|
|
import { TrendingUpIcon } from '@heroicons/react/outline'
|
2022-06-13 04:42:41 +00:00
|
|
|
import { formatMoney } from 'common/util/format'
|
2022-06-22 16:35:50 +00:00
|
|
|
import { groupPath } from 'web/lib/firebase/groups'
|
2022-08-25 11:10:24 +00:00
|
|
|
import {
|
|
|
|
BETTING_STREAK_BONUS_AMOUNT,
|
|
|
|
UNIQUE_BETTOR_BONUS_AMOUNT,
|
|
|
|
} from 'common/economy'
|
2022-08-30 15:38:59 +00:00
|
|
|
import { groupBy, sum, uniqBy } from 'lodash'
|
2022-07-07 21:06:29 +00:00
|
|
|
import { track } from '@amplitude/analytics-browser'
|
2022-07-10 23:50:59 +00:00
|
|
|
import { Pagination } from 'web/components/pagination'
|
2022-07-14 17:48:04 +00:00
|
|
|
import { useWindowSize } from 'web/hooks/use-window-size'
|
2022-07-19 15:04:47 +00:00
|
|
|
import { safeLocalStorage } from 'web/lib/util/local'
|
2022-07-19 19:58:51 +00:00
|
|
|
import { SiteLink } from 'web/components/site-link'
|
2022-09-12 16:34:56 +00:00
|
|
|
import { NotificationSettings } from 'web/components/notification-settings'
|
2022-08-15 04:55:11 +00:00
|
|
|
import { SEO } from 'web/components/SEO'
|
2022-08-31 20:41:34 +00:00
|
|
|
import { usePrivateUser, useUser } from 'web/hooks/use-user'
|
2022-09-01 22:23:12 +00:00
|
|
|
import { UserLink } from 'web/components/user-link'
|
|
|
|
import { LoadingIndicator } from 'web/components/loading-indicator'
|
2022-08-30 15:38:59 +00:00
|
|
|
import {
|
|
|
|
MultiUserLinkInfo,
|
2022-09-01 22:23:12 +00:00
|
|
|
MultiUserTransactionLink,
|
|
|
|
} from 'web/components/multi-user-transaction-link'
|
|
|
|
import { Col } from 'web/components/layout/col'
|
2022-07-05 17:29:26 +00:00
|
|
|
|
|
|
|
export const NOTIFICATIONS_PER_PAGE = 30
|
2022-07-15 22:57:58 +00:00
|
|
|
const HIGHLIGHT_CLASS = 'bg-indigo-50'
|
2022-06-06 17:36:59 +00:00
|
|
|
|
2022-08-31 20:41:34 +00:00
|
|
|
export default function Notifications() {
|
|
|
|
const privateUser = usePrivateUser()
|
2022-09-12 16:34:56 +00:00
|
|
|
const router = useRouter()
|
|
|
|
const [navigateToSection, setNavigateToSection] = useState<string>()
|
|
|
|
const [activeIndex, setActiveIndex] = useState(0)
|
2022-07-19 15:04:47 +00:00
|
|
|
|
2022-08-31 20:41:34 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (privateUser === null) Router.push('/')
|
|
|
|
})
|
2022-07-07 20:41:50 +00:00
|
|
|
|
2022-09-12 16:34:56 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const query = { ...router.query }
|
2022-09-12 20:41:30 +00:00
|
|
|
if (query.tab === 'settings') {
|
|
|
|
setActiveIndex(1)
|
|
|
|
}
|
2022-09-12 16:34:56 +00:00
|
|
|
if (query.section) {
|
|
|
|
setNavigateToSection(query.section as string)
|
|
|
|
}
|
|
|
|
}, [router.query])
|
|
|
|
|
2022-07-07 20:41:50 +00:00
|
|
|
return (
|
|
|
|
<Page>
|
2022-07-12 00:07:37 +00:00
|
|
|
<div className={'px-2 pt-4 sm:px-4 lg:pt-0'}>
|
2022-07-07 20:41:50 +00:00
|
|
|
<Title text={'Notifications'} className={'hidden md:block'} />
|
2022-08-15 04:55:11 +00:00
|
|
|
<SEO title="Notifications" description="Manifold user notifications" />
|
|
|
|
|
2022-09-12 16:34:56 +00:00
|
|
|
{privateUser && router.isReady && (
|
2022-08-31 20:41:34 +00:00
|
|
|
<div>
|
2022-09-12 16:34:56 +00:00
|
|
|
<ControlledTabs
|
2022-08-31 20:41:34 +00:00
|
|
|
currentPageForAnalytics={'notifications'}
|
|
|
|
labelClassName={'pb-2 pt-1 '}
|
|
|
|
className={'mb-0 sm:mb-2'}
|
2022-09-12 16:34:56 +00:00
|
|
|
activeIndex={activeIndex}
|
|
|
|
onClick={(title, i) => {
|
|
|
|
router.replace(
|
|
|
|
{
|
|
|
|
query: {
|
|
|
|
...router.query,
|
|
|
|
tab: title.toLowerCase(),
|
|
|
|
section: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
{ shallow: true }
|
|
|
|
)
|
|
|
|
setActiveIndex(i)
|
|
|
|
}}
|
2022-08-31 20:41:34 +00:00
|
|
|
tabs={[
|
|
|
|
{
|
|
|
|
title: 'Notifications',
|
|
|
|
content: <NotificationsList privateUser={privateUser} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Settings',
|
|
|
|
content: (
|
2022-09-12 16:34:56 +00:00
|
|
|
<NotificationSettings
|
|
|
|
navigateToSection={navigateToSection}
|
2022-09-13 23:00:34 +00:00
|
|
|
privateUser={privateUser}
|
2022-09-12 16:34:56 +00:00
|
|
|
/>
|
2022-08-31 20:41:34 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-07-07 20:41:50 +00:00
|
|
|
</div>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-19 15:04:47 +00:00
|
|
|
function RenderNotificationGroups(props: {
|
|
|
|
notificationGroups: NotificationGroup[]
|
|
|
|
}) {
|
|
|
|
const { notificationGroups } = props
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{notificationGroups.map((notification) =>
|
|
|
|
notification.type === 'income' ? (
|
|
|
|
<IncomeNotificationGroupItem
|
|
|
|
notificationGroup={notification}
|
|
|
|
key={notification.groupedById + notification.timePeriod}
|
|
|
|
/>
|
|
|
|
) : notification.notifications.length === 1 ? (
|
|
|
|
<NotificationItem
|
|
|
|
notification={notification.notifications[0]}
|
|
|
|
key={notification.notifications[0].id}
|
2022-09-15 19:39:46 +00:00
|
|
|
justSummary={false}
|
2022-07-19 15:04:47 +00:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<NotificationGroupItem
|
|
|
|
notificationGroup={notification}
|
|
|
|
key={notification.groupedById + notification.timePeriod}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2022-07-05 17:29:26 +00:00
|
|
|
|
2022-08-28 20:20:21 +00:00
|
|
|
function NotificationsList(props: { privateUser: PrivateUser }) {
|
|
|
|
const { privateUser } = props
|
2022-07-19 15:04:47 +00:00
|
|
|
const [page, setPage] = useState(0)
|
2022-08-28 20:20:21 +00:00
|
|
|
const allGroupedNotifications = useGroupedNotifications(privateUser)
|
2022-09-12 20:17:39 +00:00
|
|
|
const unseenGroupedNotifications = useUnseenGroupedNotification(privateUser)
|
2022-07-19 15:04:47 +00:00
|
|
|
const paginatedGroupedNotifications = useMemo(() => {
|
2022-07-07 20:41:50 +00:00
|
|
|
if (!allGroupedNotifications) return
|
2022-07-10 23:50:59 +00:00
|
|
|
const start = page * NOTIFICATIONS_PER_PAGE
|
2022-07-05 17:29:26 +00:00
|
|
|
const end = start + NOTIFICATIONS_PER_PAGE
|
2022-07-07 20:41:50 +00:00
|
|
|
const maxNotificationsToShow = allGroupedNotifications.slice(start, end)
|
2022-09-12 20:17:39 +00:00
|
|
|
|
2022-07-19 15:04:47 +00:00
|
|
|
const local = safeLocalStorage()
|
|
|
|
local?.setItem(
|
|
|
|
'notification-groups',
|
2022-07-19 15:29:12 +00:00
|
|
|
JSON.stringify(allGroupedNotifications)
|
2022-07-19 15:04:47 +00:00
|
|
|
)
|
|
|
|
return maxNotificationsToShow
|
2022-07-07 20:41:50 +00:00
|
|
|
}, [allGroupedNotifications, page])
|
2022-06-06 17:36:59 +00:00
|
|
|
|
2022-09-12 20:17:39 +00:00
|
|
|
// Set all notifications that don't fit on the first page to seen
|
|
|
|
useEffect(() => {
|
|
|
|
if (
|
|
|
|
paginatedGroupedNotifications &&
|
|
|
|
paginatedGroupedNotifications?.length >= NOTIFICATIONS_PER_PAGE
|
|
|
|
) {
|
|
|
|
const allUnseenNotifications = unseenGroupedNotifications
|
|
|
|
?.map((ng) => ng.notifications)
|
|
|
|
.flat()
|
|
|
|
allUnseenNotifications && setNotificationsAsSeen(allUnseenNotifications)
|
|
|
|
}
|
|
|
|
}, [paginatedGroupedNotifications, unseenGroupedNotifications])
|
|
|
|
|
2022-08-28 20:20:21 +00:00
|
|
|
if (!paginatedGroupedNotifications || !allGroupedNotifications)
|
|
|
|
return <LoadingIndicator />
|
2022-06-01 13:11:25 +00:00
|
|
|
|
|
|
|
return (
|
2022-08-23 13:55:26 +00:00
|
|
|
<div className={'min-h-[100vh] text-sm'}>
|
2022-07-07 20:41:50 +00:00
|
|
|
{paginatedGroupedNotifications.length === 0 && (
|
|
|
|
<div className={'mt-2'}>
|
|
|
|
You don't have any notifications. Try changing your settings to see
|
|
|
|
more.
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2022-07-19 15:04:47 +00:00
|
|
|
<RenderNotificationGroups
|
|
|
|
notificationGroups={paginatedGroupedNotifications}
|
|
|
|
/>
|
2022-07-07 20:41:50 +00:00
|
|
|
{paginatedGroupedNotifications.length > 0 &&
|
|
|
|
allGroupedNotifications.length > NOTIFICATIONS_PER_PAGE && (
|
2022-07-10 23:50:59 +00:00
|
|
|
<Pagination
|
|
|
|
page={page}
|
|
|
|
itemsPerPage={NOTIFICATIONS_PER_PAGE}
|
|
|
|
totalItems={allGroupedNotifications.length}
|
|
|
|
setPage={setPage}
|
|
|
|
scrollToTop
|
2022-07-19 20:16:20 +00:00
|
|
|
nextTitle={'Older'}
|
|
|
|
prevTitle={'Newer'}
|
2022-07-10 23:50:59 +00:00
|
|
|
/>
|
2022-07-07 20:41:50 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2022-06-01 13:11:25 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-05 17:29:26 +00:00
|
|
|
function IncomeNotificationGroupItem(props: {
|
|
|
|
notificationGroup: NotificationGroup
|
|
|
|
className?: string
|
|
|
|
}) {
|
|
|
|
const { notificationGroup, className } = props
|
|
|
|
const { notifications } = notificationGroup
|
|
|
|
const numSummaryLines = 3
|
2022-08-26 05:00:44 +00:00
|
|
|
const [expanded, setExpanded] = useState(
|
|
|
|
notifications.length <= numSummaryLines
|
|
|
|
)
|
2022-07-06 19:30:51 +00:00
|
|
|
const [highlighted, setHighlighted] = useState(
|
|
|
|
notifications.some((n) => !n.isSeen)
|
|
|
|
)
|
|
|
|
|
2022-07-14 17:56:40 +00:00
|
|
|
const onClickHandler = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
|
|
if (event.ctrlKey || event.metaKey) return
|
|
|
|
setExpanded(!expanded)
|
|
|
|
}
|
|
|
|
|
2022-07-05 17:29:26 +00:00
|
|
|
useEffect(() => {
|
|
|
|
setNotificationsAsSeen(notifications)
|
|
|
|
}, [notifications])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (expanded) setHighlighted(false)
|
|
|
|
}, [expanded])
|
|
|
|
|
2022-07-06 19:30:51 +00:00
|
|
|
const totalIncome = sum(
|
|
|
|
notifications.map((notification) =>
|
|
|
|
notification.sourceText ? parseInt(notification.sourceText) : 0
|
|
|
|
)
|
2022-07-05 17:29:26 +00:00
|
|
|
)
|
2022-07-06 19:30:51 +00:00
|
|
|
// Loop through the contracts and combine the notification items into one
|
|
|
|
function combineNotificationsByAddingNumericSourceTexts(
|
2022-07-05 17:29:26 +00:00
|
|
|
notifications: Notification[]
|
|
|
|
) {
|
2022-09-01 22:23:12 +00:00
|
|
|
const newNotifications: Notification[] = []
|
2022-07-06 19:30:51 +00:00
|
|
|
const groupedNotificationsBySourceType = groupBy(
|
2022-07-05 17:29:26 +00:00
|
|
|
notifications,
|
2022-07-06 19:30:51 +00:00
|
|
|
(n) => n.sourceType
|
2022-07-05 17:29:26 +00:00
|
|
|
)
|
2022-07-06 19:30:51 +00:00
|
|
|
for (const sourceType in groupedNotificationsBySourceType) {
|
2022-08-19 17:10:32 +00:00
|
|
|
// Source title splits by contracts, groups, betting streak bonus
|
2022-07-11 14:11:52 +00:00
|
|
|
const groupedNotificationsBySourceTitle = groupBy(
|
2022-07-06 19:30:51 +00:00
|
|
|
groupedNotificationsBySourceType[sourceType],
|
|
|
|
(notification) => {
|
2022-07-14 17:48:04 +00:00
|
|
|
return notification.sourceTitle ?? notification.sourceContractTitle
|
2022-07-06 19:30:51 +00:00
|
|
|
}
|
2022-07-05 17:29:26 +00:00
|
|
|
)
|
2022-08-19 17:10:32 +00:00
|
|
|
for (const sourceTitle in groupedNotificationsBySourceTitle) {
|
|
|
|
const notificationsForSourceTitle =
|
|
|
|
groupedNotificationsBySourceTitle[sourceTitle]
|
2022-09-01 22:23:12 +00:00
|
|
|
|
2022-07-06 19:30:51 +00:00
|
|
|
let sum = 0
|
2022-08-19 17:10:32 +00:00
|
|
|
notificationsForSourceTitle.forEach(
|
2022-07-06 19:30:51 +00:00
|
|
|
(notification) =>
|
2022-08-30 15:38:59 +00:00
|
|
|
(sum = parseInt(notification.sourceText ?? '0') + sum)
|
2022-07-06 19:30:51 +00:00
|
|
|
)
|
2022-08-30 15:38:59 +00:00
|
|
|
const uniqueUsers = uniqBy(
|
2022-08-19 17:10:32 +00:00
|
|
|
notificationsForSourceTitle.map((notification) => {
|
2022-08-30 15:38:59 +00:00
|
|
|
let thisSum = 0
|
|
|
|
notificationsForSourceTitle
|
|
|
|
.filter(
|
|
|
|
(n) => n.sourceUserUsername === notification.sourceUserUsername
|
|
|
|
)
|
|
|
|
.forEach(
|
|
|
|
(n) => (thisSum = parseInt(n.sourceText ?? '0') + thisSum)
|
|
|
|
)
|
|
|
|
return {
|
|
|
|
username: notification.sourceUserUsername,
|
|
|
|
name: notification.sourceUserName,
|
|
|
|
avatarUrl: notification.sourceUserAvatarUrl,
|
2022-09-01 22:23:12 +00:00
|
|
|
amount: thisSum,
|
2022-08-30 15:38:59 +00:00
|
|
|
} as MultiUserLinkInfo
|
|
|
|
}),
|
|
|
|
(n) => n.username
|
2022-07-06 19:30:51 +00:00
|
|
|
)
|
2022-07-05 17:29:26 +00:00
|
|
|
|
2022-07-06 19:30:51 +00:00
|
|
|
const newNotification = {
|
2022-08-19 17:10:32 +00:00
|
|
|
...notificationsForSourceTitle[0],
|
2022-07-06 19:30:51 +00:00
|
|
|
sourceText: sum.toString(),
|
2022-09-01 22:23:12 +00:00
|
|
|
sourceUserUsername: notificationsForSourceTitle[0].sourceUserUsername,
|
2022-09-14 13:27:20 +00:00
|
|
|
data: { uniqueUsers },
|
2022-07-06 19:30:51 +00:00
|
|
|
}
|
|
|
|
newNotifications.push(newNotification)
|
|
|
|
}
|
2022-07-05 17:29:26 +00:00
|
|
|
}
|
|
|
|
return newNotifications
|
|
|
|
}
|
2022-08-22 12:31:30 +00:00
|
|
|
const combinedNotifs = combineNotificationsByAddingNumericSourceTexts(
|
|
|
|
notifications.filter((n) => n.sourceType !== 'betting_streak_bonus')
|
|
|
|
)
|
|
|
|
// Because the server's reset time will never align with the client's, we may
|
|
|
|
// erroneously sum 2 betting streak bonuses, therefore just show the most recent
|
|
|
|
const mostRecentBettingStreakBonus = notifications
|
|
|
|
.filter((n) => n.sourceType === 'betting_streak_bonus')
|
|
|
|
.sort((a, b) => a.createdTime - b.createdTime)
|
|
|
|
.pop()
|
|
|
|
if (mostRecentBettingStreakBonus)
|
|
|
|
combinedNotifs.unshift(mostRecentBettingStreakBonus)
|
2022-07-05 17:29:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'relative cursor-pointer bg-white px-2 pt-6 text-sm',
|
|
|
|
className,
|
|
|
|
!expanded ? 'hover:bg-gray-100' : '',
|
2022-07-15 22:57:58 +00:00
|
|
|
highlighted && !expanded ? HIGHLIGHT_CLASS : ''
|
2022-07-05 17:29:26 +00:00
|
|
|
)}
|
2022-07-14 17:56:40 +00:00
|
|
|
onClick={onClickHandler}
|
2022-07-05 17:29:26 +00:00
|
|
|
>
|
|
|
|
{expanded && (
|
|
|
|
<span
|
|
|
|
className="absolute top-14 left-6 -ml-px h-[calc(100%-5rem)] w-0.5 bg-gray-200"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Row className={'items-center text-gray-500 sm:justify-start'}>
|
2022-07-07 23:17:10 +00:00
|
|
|
<TrendingUpIcon
|
|
|
|
className={'text-primary ml-1 h-7 w-7 flex-shrink-0 sm:ml-2'}
|
|
|
|
/>
|
2022-07-07 20:41:50 +00:00
|
|
|
<div
|
2022-07-07 23:17:10 +00:00
|
|
|
className={'ml-2 flex w-full flex-row flex-wrap truncate'}
|
2022-07-14 17:56:40 +00:00
|
|
|
onClick={onClickHandler}
|
2022-07-07 20:41:50 +00:00
|
|
|
>
|
|
|
|
<div className={'flex w-full flex-row justify-between'}>
|
|
|
|
<div>
|
2022-07-05 17:29:26 +00:00
|
|
|
{'Daily Income Summary: '}
|
2022-07-06 13:45:47 +00:00
|
|
|
<span className={'text-primary'}>
|
|
|
|
{'+' + formatMoney(totalIncome)}
|
|
|
|
</span>
|
2022-07-07 20:41:50 +00:00
|
|
|
</div>
|
|
|
|
<div className={'inline-block'}>
|
|
|
|
<RelativeTimestamp time={notifications[0].createdTime} />
|
|
|
|
</div>
|
2022-07-05 17:29:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Row>
|
|
|
|
<div>
|
|
|
|
<div className={clsx('mt-1 md:text-base', expanded ? 'pl-4' : '')}>
|
|
|
|
{' '}
|
2022-07-06 19:30:51 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'mt-1 ml-1 gap-1 whitespace-pre-line',
|
|
|
|
!expanded ? 'line-clamp-4' : ''
|
|
|
|
)}
|
|
|
|
>
|
2022-07-05 17:29:26 +00:00
|
|
|
{!expanded ? (
|
|
|
|
<>
|
|
|
|
{combinedNotifs
|
|
|
|
.slice(0, numSummaryLines)
|
2022-07-06 19:30:51 +00:00
|
|
|
.map((notification) => (
|
|
|
|
<IncomeNotificationItem
|
|
|
|
notification={notification}
|
|
|
|
justSummary={true}
|
|
|
|
key={notification.id}
|
|
|
|
/>
|
|
|
|
))}
|
2022-07-05 17:29:26 +00:00
|
|
|
<div className={'text-sm text-gray-500 hover:underline '}>
|
|
|
|
{combinedNotifs.length - numSummaryLines > 0
|
|
|
|
? 'And ' +
|
|
|
|
(combinedNotifs.length - numSummaryLines) +
|
|
|
|
' more...'
|
|
|
|
: ''}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{combinedNotifs.map((notification) => (
|
2022-07-06 19:30:51 +00:00
|
|
|
<IncomeNotificationItem
|
2022-07-05 17:29:26 +00:00
|
|
|
notification={notification}
|
|
|
|
key={notification.id}
|
|
|
|
justSummary={false}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={'mt-6 border-b border-gray-300'} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-06 19:30:51 +00:00
|
|
|
function IncomeNotificationItem(props: {
|
|
|
|
notification: Notification
|
|
|
|
justSummary?: boolean
|
|
|
|
}) {
|
|
|
|
const { notification, justSummary } = props
|
2022-09-01 22:23:12 +00:00
|
|
|
const { sourceType, sourceUserUsername, sourceText, data } = notification
|
2022-07-06 19:30:51 +00:00
|
|
|
const [highlighted] = useState(!notification.isSeen)
|
2022-07-14 17:48:04 +00:00
|
|
|
const { width } = useWindowSize()
|
|
|
|
const isMobile = (width && width < 768) || false
|
2022-08-25 04:40:27 +00:00
|
|
|
const user = useUser()
|
2022-09-01 22:23:12 +00:00
|
|
|
const isTip = sourceType === 'tip' || sourceType === 'tip_and_like'
|
|
|
|
const isUniqueBettorBonus = sourceType === 'bonus'
|
|
|
|
const userLinks: MultiUserLinkInfo[] =
|
2022-09-14 13:27:20 +00:00
|
|
|
isTip || isUniqueBettorBonus ? data?.uniqueUsers ?? [] : []
|
2022-08-25 04:40:27 +00:00
|
|
|
|
2022-07-06 19:30:51 +00:00
|
|
|
useEffect(() => {
|
|
|
|
setNotificationsAsSeen([notification])
|
|
|
|
}, [notification])
|
|
|
|
|
2022-08-19 17:10:32 +00:00
|
|
|
function reasonAndLink(simple: boolean) {
|
2022-07-06 19:30:51 +00:00
|
|
|
const { sourceText } = notification
|
|
|
|
let reasonText = ''
|
2022-08-20 18:47:23 +00:00
|
|
|
|
2022-07-06 19:30:51 +00:00
|
|
|
if (sourceType === 'bonus' && sourceText) {
|
|
|
|
reasonText = !simple
|
2022-07-06 23:24:53 +00:00
|
|
|
? `Bonus for ${
|
2022-07-06 19:30:51 +00:00
|
|
|
parseInt(sourceText) / UNIQUE_BETTOR_BONUS_AMOUNT
|
2022-09-13 22:19:52 +00:00
|
|
|
} new predictors on`
|
2022-07-06 23:24:53 +00:00
|
|
|
: 'bonus on'
|
2022-07-06 19:30:51 +00:00
|
|
|
} else if (sourceType === 'tip') {
|
2022-08-19 17:10:32 +00:00
|
|
|
reasonText = !simple ? `tipped you on` : `in tips on`
|
2022-08-20 18:47:23 +00:00
|
|
|
} else if (sourceType === 'betting_streak_bonus') {
|
2022-08-26 16:38:08 +00:00
|
|
|
if (sourceText && +sourceText === 50) reasonText = '(max) for your'
|
|
|
|
else reasonText = 'for your'
|
2022-08-22 05:22:49 +00:00
|
|
|
} else if (sourceType === 'loan' && sourceText) {
|
2022-09-13 22:19:52 +00:00
|
|
|
reasonText = `of your invested predictions returned as a`
|
2022-08-30 15:38:59 +00:00
|
|
|
// TODO: support just 'like' notification without a tip
|
|
|
|
} else if (sourceType === 'tip_and_like' && sourceText) {
|
|
|
|
reasonText = !simple ? `liked` : `in likes on`
|
2022-07-06 19:30:51 +00:00
|
|
|
}
|
2022-08-20 18:47:23 +00:00
|
|
|
|
2022-09-14 13:27:20 +00:00
|
|
|
const streakInDays = notification.data?.streak
|
|
|
|
? notification.data?.streak
|
|
|
|
: Date.now() - notification.createdTime > 24 * 60 * 60 * 1000
|
|
|
|
? parseInt(sourceText ?? '0') / BETTING_STREAK_BONUS_AMOUNT
|
|
|
|
: user?.currentBettingStreak ?? 0
|
2022-08-20 18:47:23 +00:00
|
|
|
const bettingStreakText =
|
|
|
|
sourceType === 'betting_streak_bonus' &&
|
2022-09-13 22:19:52 +00:00
|
|
|
(sourceText
|
|
|
|
? `🔥 ${streakInDays} day Prediction Streak`
|
|
|
|
: 'Prediction Streak')
|
2022-08-20 18:47:23 +00:00
|
|
|
|
2022-08-19 17:10:32 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{reasonText}
|
2022-08-22 05:22:49 +00:00
|
|
|
{sourceType === 'loan' ? (
|
|
|
|
simple ? (
|
2022-08-22 15:31:23 +00:00
|
|
|
<span className={'ml-1 font-bold'}>🏦 Loan</span>
|
2022-08-22 05:22:49 +00:00
|
|
|
) : (
|
|
|
|
<SiteLink className={'ml-1 font-bold'} href={'/loans'}>
|
2022-08-22 15:31:23 +00:00
|
|
|
🏦 Loan
|
2022-08-22 05:22:49 +00:00
|
|
|
</SiteLink>
|
|
|
|
)
|
|
|
|
) : sourceType === 'betting_streak_bonus' ? (
|
2022-08-19 17:10:32 +00:00
|
|
|
simple ? (
|
2022-08-20 18:47:23 +00:00
|
|
|
<span className={'ml-1 font-bold'}>{bettingStreakText}</span>
|
2022-08-19 17:10:32 +00:00
|
|
|
) : (
|
|
|
|
<SiteLink
|
|
|
|
className={'ml-1 font-bold'}
|
|
|
|
href={'/betting-streak-bonus'}
|
|
|
|
>
|
2022-08-20 18:47:23 +00:00
|
|
|
{bettingStreakText}
|
2022-08-19 17:10:32 +00:00
|
|
|
</SiteLink>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<QuestionOrGroupLink
|
|
|
|
notification={notification}
|
|
|
|
ignoreClick={isMobile}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const incomeNotificationLabel = () => {
|
|
|
|
return sourceText ? (
|
|
|
|
<span className="text-primary">
|
|
|
|
{'+' + formatMoney(parseInt(sourceText))}
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<div />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const getIncomeSourceUrl = () => {
|
|
|
|
const {
|
|
|
|
sourceId,
|
|
|
|
sourceContractCreatorUsername,
|
|
|
|
sourceContractSlug,
|
|
|
|
sourceSlug,
|
|
|
|
} = notification
|
|
|
|
if (sourceType === 'tip' && sourceContractSlug)
|
|
|
|
return `/${sourceContractCreatorUsername}/${sourceContractSlug}#${sourceSlug}`
|
|
|
|
if (sourceType === 'tip' && sourceSlug) return `${groupPath(sourceSlug)}`
|
|
|
|
if (sourceType === 'challenge') return `${sourceSlug}`
|
|
|
|
if (sourceType === 'betting_streak_bonus')
|
|
|
|
return `/${sourceUserUsername}/?show=betting-streak`
|
2022-08-22 05:22:49 +00:00
|
|
|
if (sourceType === 'loan') return `/${sourceUserUsername}/?show=loans`
|
2022-08-19 17:10:32 +00:00
|
|
|
if (sourceContractCreatorUsername && sourceContractSlug)
|
|
|
|
return `/${sourceContractCreatorUsername}/${sourceContractSlug}#${getSourceIdForLinkComponent(
|
|
|
|
sourceId ?? '',
|
|
|
|
sourceType
|
|
|
|
)}`
|
2022-07-06 19:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (justSummary) {
|
|
|
|
return (
|
|
|
|
<Row className={'items-center text-sm text-gray-500 sm:justify-start'}>
|
|
|
|
<div className={'line-clamp-1 flex-1 overflow-hidden sm:flex'}>
|
|
|
|
<div className={'flex pl-1 sm:pl-0'}>
|
|
|
|
<div className={'inline-flex overflow-hidden text-ellipsis pl-1'}>
|
|
|
|
<div className={'mr-1 text-black'}>
|
2022-08-19 17:10:32 +00:00
|
|
|
{incomeNotificationLabel()}
|
2022-07-06 19:30:51 +00:00
|
|
|
</div>
|
2022-08-19 17:10:32 +00:00
|
|
|
<span className={'flex truncate'}>{reasonAndLink(true)}</span>
|
2022-07-06 19:30:51 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'bg-white px-2 pt-6 text-sm sm:px-4',
|
2022-07-15 22:57:58 +00:00
|
|
|
highlighted && HIGHLIGHT_CLASS
|
2022-07-06 19:30:51 +00:00
|
|
|
)}
|
|
|
|
>
|
2022-07-19 19:58:51 +00:00
|
|
|
<div className={'relative'}>
|
|
|
|
<SiteLink
|
2022-08-19 17:10:32 +00:00
|
|
|
href={getIncomeSourceUrl() ?? ''}
|
2022-07-19 19:58:51 +00:00
|
|
|
className={'absolute left-0 right-0 top-0 bottom-0 z-0'}
|
|
|
|
/>
|
2022-09-01 22:23:12 +00:00
|
|
|
<Col className={'justify-start text-gray-500'}>
|
|
|
|
{(isTip || isUniqueBettorBonus) && (
|
|
|
|
<MultiUserTransactionLink
|
|
|
|
userInfos={userLinks}
|
2022-09-13 22:19:52 +00:00
|
|
|
modalLabel={isTip ? 'Who tipped you' : 'Unique predictors'}
|
2022-09-01 22:23:12 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Row className={'line-clamp-2 flex max-w-xl'}>
|
|
|
|
<span>{incomeNotificationLabel()}</span>
|
|
|
|
<span className={'mx-1'}>
|
|
|
|
{isTip &&
|
|
|
|
(userLinks.length > 1
|
|
|
|
? 'Multiple users'
|
|
|
|
: userLinks.length > 0
|
|
|
|
? userLinks[0].name
|
|
|
|
: '')}
|
2022-07-06 19:30:51 +00:00
|
|
|
</span>
|
2022-09-01 22:23:12 +00:00
|
|
|
<span>{reasonAndLink(false)}</span>
|
|
|
|
</Row>
|
|
|
|
</Col>
|
2022-08-26 05:00:44 +00:00
|
|
|
<div className={'border-b border-gray-300 pt-4'} />
|
2022-07-19 19:58:51 +00:00
|
|
|
</div>
|
2022-07-06 19:30:51 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-06 17:36:59 +00:00
|
|
|
function NotificationGroupItem(props: {
|
|
|
|
notificationGroup: NotificationGroup
|
|
|
|
className?: string
|
|
|
|
}) {
|
|
|
|
const { notificationGroup, className } = props
|
2022-07-01 13:47:19 +00:00
|
|
|
const { notifications } = notificationGroup
|
2022-07-06 19:30:51 +00:00
|
|
|
const { sourceContractTitle } = notifications[0]
|
2022-07-14 17:48:04 +00:00
|
|
|
const { width } = useWindowSize()
|
|
|
|
const isMobile = (width && width < 768) || false
|
2022-06-06 17:36:59 +00:00
|
|
|
const numSummaryLines = 3
|
2022-06-09 17:39:23 +00:00
|
|
|
|
2022-08-26 05:00:44 +00:00
|
|
|
const [expanded, setExpanded] = useState(
|
|
|
|
notifications.length <= numSummaryLines
|
|
|
|
)
|
2022-07-06 19:30:51 +00:00
|
|
|
const [highlighted, setHighlighted] = useState(
|
|
|
|
notifications.some((n) => !n.isSeen)
|
|
|
|
)
|
2022-07-14 17:56:40 +00:00
|
|
|
|
|
|
|
const onClickHandler = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
|
|
if (event.ctrlKey || event.metaKey) return
|
|
|
|
setExpanded(!expanded)
|
|
|
|
}
|
|
|
|
|
2022-06-06 17:36:59 +00:00
|
|
|
useEffect(() => {
|
|
|
|
setNotificationsAsSeen(notifications)
|
2022-06-09 17:39:23 +00:00
|
|
|
}, [notifications])
|
2022-06-06 17:36:59 +00:00
|
|
|
|
2022-07-05 17:29:26 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (expanded) setHighlighted(false)
|
|
|
|
}, [expanded])
|
|
|
|
|
2022-06-06 17:36:59 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'relative cursor-pointer bg-white px-2 pt-6 text-sm',
|
|
|
|
className,
|
2022-07-05 17:29:26 +00:00
|
|
|
!expanded ? 'hover:bg-gray-100' : '',
|
2022-07-15 22:57:58 +00:00
|
|
|
highlighted && !expanded ? HIGHLIGHT_CLASS : ''
|
2022-06-06 17:36:59 +00:00
|
|
|
)}
|
2022-07-14 17:56:40 +00:00
|
|
|
onClick={onClickHandler}
|
2022-06-06 17:36:59 +00:00
|
|
|
>
|
|
|
|
{expanded && (
|
|
|
|
<span
|
|
|
|
className="absolute top-14 left-6 -ml-px h-[calc(100%-5rem)] w-0.5 bg-gray-200"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Row className={'items-center text-gray-500 sm:justify-start'}>
|
2022-06-23 17:55:41 +00:00
|
|
|
<EmptyAvatar multi />
|
2022-07-07 20:41:50 +00:00
|
|
|
<div
|
|
|
|
className={'line-clamp-2 flex w-full flex-row flex-wrap pl-1 sm:pl-0'}
|
|
|
|
>
|
|
|
|
{sourceContractTitle ? (
|
|
|
|
<div className={'flex w-full flex-row justify-between'}>
|
|
|
|
<div className={'ml-2'}>
|
|
|
|
Activity on
|
2022-07-14 17:48:04 +00:00
|
|
|
<QuestionOrGroupLink
|
|
|
|
notification={notifications[0]}
|
|
|
|
ignoreClick={!expanded && isMobile}
|
|
|
|
/>
|
2022-07-07 20:41:50 +00:00
|
|
|
</div>
|
|
|
|
<div className={'hidden sm:inline-block'}>
|
|
|
|
<RelativeTimestamp time={notifications[0].createdTime} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<span>
|
|
|
|
Other activity
|
|
|
|
<RelativeTimestamp time={notifications[0].createdTime} />
|
|
|
|
</span>
|
|
|
|
)}
|
2022-06-06 17:36:59 +00:00
|
|
|
</div>
|
|
|
|
</Row>
|
|
|
|
<div>
|
|
|
|
<div className={clsx('mt-1 md:text-base', expanded ? 'pl-4' : '')}>
|
|
|
|
{' '}
|
2022-07-06 19:30:51 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'mt-1 ml-1 gap-1 whitespace-pre-line',
|
|
|
|
!expanded ? 'line-clamp-4' : ''
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{' '}
|
2022-06-06 17:36:59 +00:00
|
|
|
{!expanded ? (
|
|
|
|
<>
|
2022-06-06 22:15:36 +00:00
|
|
|
{notifications.slice(0, numSummaryLines).map((notification) => {
|
|
|
|
return (
|
|
|
|
<NotificationItem
|
|
|
|
notification={notification}
|
|
|
|
justSummary={true}
|
|
|
|
key={notification.id}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
2022-06-06 17:36:59 +00:00
|
|
|
<div className={'text-sm text-gray-500 hover:underline '}>
|
|
|
|
{notifications.length - numSummaryLines > 0
|
|
|
|
? 'And ' +
|
|
|
|
(notifications.length - numSummaryLines) +
|
|
|
|
' more...'
|
|
|
|
: ''}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
2022-06-06 22:15:36 +00:00
|
|
|
{notifications.map((notification) => (
|
2022-06-06 17:36:59 +00:00
|
|
|
<NotificationItem
|
|
|
|
notification={notification}
|
|
|
|
key={notification.id}
|
|
|
|
justSummary={false}
|
2022-07-07 20:41:50 +00:00
|
|
|
isChildOfGroup={true}
|
2022-06-06 17:36:59 +00:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={'mt-6 border-b border-gray-300'} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-06 21:06:41 +00:00
|
|
|
function NotificationItem(props: {
|
|
|
|
notification: Notification
|
2022-09-15 19:39:46 +00:00
|
|
|
justSummary: boolean
|
2022-07-07 20:41:50 +00:00
|
|
|
isChildOfGroup?: boolean
|
2022-07-06 21:06:41 +00:00
|
|
|
}) {
|
2022-07-07 20:41:50 +00:00
|
|
|
const { notification, justSummary, isChildOfGroup } = props
|
2022-09-15 19:39:46 +00:00
|
|
|
const { sourceType, reason } = notification
|
2022-06-06 17:36:59 +00:00
|
|
|
|
2022-07-06 21:06:41 +00:00
|
|
|
const [highlighted] = useState(!notification.isSeen)
|
2022-06-06 17:36:59 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-07-06 21:06:41 +00:00
|
|
|
setNotificationsAsSeen([notification])
|
|
|
|
}, [notification])
|
2022-06-06 17:36:59 +00:00
|
|
|
|
2022-09-15 19:39:46 +00:00
|
|
|
// TODO Any new notification should be its own component
|
|
|
|
if (reason === 'bet_fill') {
|
|
|
|
return (
|
|
|
|
<BetFillNotification
|
|
|
|
notification={notification}
|
|
|
|
isChildOfGroup={isChildOfGroup}
|
|
|
|
highlighted={highlighted}
|
|
|
|
justSummary={justSummary}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
// TODO Add new notification components here
|
2022-07-15 17:53:30 +00:00
|
|
|
|
2022-07-06 21:06:41 +00:00
|
|
|
if (justSummary) {
|
2022-06-06 17:36:59 +00:00
|
|
|
return (
|
2022-09-15 19:39:46 +00:00
|
|
|
<NotificationSummaryFrame
|
|
|
|
notification={notification}
|
|
|
|
subtitle={
|
|
|
|
(sourceType &&
|
|
|
|
reason &&
|
|
|
|
getReasonForShowingNotification(notification, true)) ??
|
|
|
|
''
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<NotificationTextLabel
|
|
|
|
className={'line-clamp-1'}
|
|
|
|
notification={notification}
|
|
|
|
justSummary={true}
|
|
|
|
/>
|
|
|
|
</NotificationSummaryFrame>
|
2022-06-06 17:36:59 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-09-15 19:39:46 +00:00
|
|
|
return (
|
|
|
|
<NotificationFrame
|
|
|
|
notification={notification}
|
|
|
|
subtitle={getReasonForShowingNotification(
|
|
|
|
notification,
|
|
|
|
isChildOfGroup ?? false
|
|
|
|
)}
|
|
|
|
highlighted={highlighted}
|
|
|
|
>
|
|
|
|
<div className={'mt-1 ml-1 md:text-base'}>
|
|
|
|
<NotificationTextLabel notification={notification} />
|
|
|
|
</div>
|
|
|
|
</NotificationFrame>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function NotificationSummaryFrame(props: {
|
|
|
|
notification: Notification
|
|
|
|
subtitle: string
|
|
|
|
children: React.ReactNode
|
|
|
|
}) {
|
|
|
|
const { notification, subtitle, children } = props
|
|
|
|
const { sourceUserName, sourceUserUsername } = notification
|
|
|
|
return (
|
|
|
|
<Row className={'items-center text-sm text-gray-500 sm:justify-start'}>
|
|
|
|
<div className={'line-clamp-1 flex-1 overflow-hidden sm:flex'}>
|
|
|
|
<div className={'flex pl-1 sm:pl-0'}>
|
|
|
|
<UserLink
|
|
|
|
name={sourceUserName || ''}
|
|
|
|
username={sourceUserUsername || ''}
|
|
|
|
className={'mr-0 flex-shrink-0'}
|
|
|
|
short={true}
|
|
|
|
/>
|
|
|
|
<div className={'inline-flex overflow-hidden text-ellipsis pl-1'}>
|
|
|
|
<span className={'flex-shrink-0'}>{subtitle}</span>
|
|
|
|
<div className={'line-clamp-1 ml-1 text-black'}>{children}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function NotificationFrame(props: {
|
|
|
|
notification: Notification
|
|
|
|
highlighted: boolean
|
|
|
|
subtitle: string
|
|
|
|
children: React.ReactNode
|
|
|
|
isChildOfGroup?: boolean
|
|
|
|
}) {
|
|
|
|
const { notification, isChildOfGroup, highlighted, subtitle, children } =
|
|
|
|
props
|
|
|
|
const {
|
|
|
|
sourceType,
|
|
|
|
sourceUserName,
|
|
|
|
sourceUserAvatarUrl,
|
|
|
|
sourceUpdateType,
|
|
|
|
reason,
|
|
|
|
reasonText,
|
|
|
|
sourceUserUsername,
|
|
|
|
sourceText,
|
|
|
|
} = notification
|
|
|
|
const questionNeedsResolution = sourceUpdateType == 'closed'
|
|
|
|
|
2022-06-06 17:36:59 +00:00
|
|
|
return (
|
2022-07-06 21:06:41 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'bg-white px-2 pt-6 text-sm sm:px-4',
|
2022-07-15 22:57:58 +00:00
|
|
|
highlighted && HIGHLIGHT_CLASS
|
2022-07-06 21:06:41 +00:00
|
|
|
)}
|
|
|
|
>
|
2022-07-19 19:58:51 +00:00
|
|
|
<div className={'relative cursor-pointer'}>
|
|
|
|
<SiteLink
|
|
|
|
href={getSourceUrl(notification) ?? ''}
|
|
|
|
className={'absolute left-0 right-0 top-0 bottom-0 z-0'}
|
|
|
|
onClick={() =>
|
|
|
|
track('Notification Clicked', {
|
|
|
|
type: 'notification item',
|
|
|
|
sourceType,
|
|
|
|
sourceUserName,
|
|
|
|
sourceUserAvatarUrl,
|
|
|
|
sourceUpdateType,
|
|
|
|
reasonText,
|
|
|
|
reason,
|
|
|
|
sourceUserUsername,
|
|
|
|
sourceText,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
2022-07-06 21:06:41 +00:00
|
|
|
<Row className={'items-center text-gray-500 sm:justify-start'}>
|
|
|
|
<Avatar
|
2022-07-15 17:53:30 +00:00
|
|
|
avatarUrl={
|
|
|
|
questionNeedsResolution
|
|
|
|
? MANIFOLD_AVATAR_URL
|
|
|
|
: sourceUserAvatarUrl
|
|
|
|
}
|
2022-07-06 21:06:41 +00:00
|
|
|
size={'sm'}
|
2022-07-19 19:58:51 +00:00
|
|
|
className={'z-10 mr-2'}
|
2022-07-15 17:53:30 +00:00
|
|
|
username={
|
|
|
|
questionNeedsResolution ? MANIFOLD_USERNAME : sourceUserUsername
|
|
|
|
}
|
2022-06-08 17:24:07 +00:00
|
|
|
/>
|
2022-07-07 20:41:50 +00:00
|
|
|
<div className={'flex w-full flex-row pl-1 sm:pl-0'}>
|
2022-07-06 21:06:41 +00:00
|
|
|
<div
|
|
|
|
className={
|
2022-07-07 20:41:50 +00:00
|
|
|
'line-clamp-2 sm:line-clamp-none flex w-full flex-row justify-between'
|
2022-07-06 21:06:41 +00:00
|
|
|
}
|
|
|
|
>
|
2022-07-07 20:41:50 +00:00
|
|
|
<div>
|
2022-09-15 19:39:46 +00:00
|
|
|
<UserLink
|
|
|
|
name={sourceUserName || ''}
|
|
|
|
username={sourceUserUsername || ''}
|
|
|
|
className={'relative mr-1 flex-shrink-0'}
|
|
|
|
short={true}
|
|
|
|
/>
|
|
|
|
{subtitle}
|
2022-07-07 20:41:50 +00:00
|
|
|
{isChildOfGroup ? (
|
|
|
|
<RelativeTimestamp time={notification.createdTime} />
|
|
|
|
) : (
|
2022-07-07 23:23:13 +00:00
|
|
|
<QuestionOrGroupLink notification={notification} />
|
2022-07-07 20:41:50 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2022-07-06 21:06:41 +00:00
|
|
|
</div>
|
2022-07-07 20:41:50 +00:00
|
|
|
{!isChildOfGroup && (
|
|
|
|
<div className={'hidden sm:inline-block'}>
|
|
|
|
<RelativeTimestamp time={notification.createdTime} />
|
|
|
|
</div>
|
|
|
|
)}
|
2022-07-06 21:06:41 +00:00
|
|
|
</div>
|
|
|
|
</Row>
|
2022-09-15 19:39:46 +00:00
|
|
|
<div className={'mt-1 ml-1 md:text-base'}>{children}</div>
|
2022-07-06 21:06:41 +00:00
|
|
|
|
|
|
|
<div className={'mt-6 border-b border-gray-300'} />
|
2022-07-15 17:53:30 +00:00
|
|
|
</div>
|
2022-06-06 17:36:59 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-09-15 19:39:46 +00:00
|
|
|
function BetFillNotification(props: {
|
|
|
|
notification: Notification
|
|
|
|
highlighted: boolean
|
|
|
|
justSummary: boolean
|
|
|
|
isChildOfGroup?: boolean
|
|
|
|
}) {
|
|
|
|
const { notification, isChildOfGroup, highlighted, justSummary } = props
|
|
|
|
const { sourceText, data } = notification
|
|
|
|
const { creatorOutcome, probability } = (data as BetFillData) ?? {}
|
|
|
|
const subtitle = 'bet against you'
|
|
|
|
const amount = formatMoney(parseInt(sourceText ?? '0'))
|
|
|
|
const description =
|
|
|
|
creatorOutcome && probability ? (
|
|
|
|
<span>
|
|
|
|
of your{' '}
|
|
|
|
<span
|
|
|
|
className={
|
|
|
|
creatorOutcome === 'YES'
|
|
|
|
? 'text-primary'
|
|
|
|
: creatorOutcome === 'NO'
|
|
|
|
? 'text-red-500'
|
|
|
|
: 'text-blue-500'
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{creatorOutcome}{' '}
|
|
|
|
</span>
|
|
|
|
limit order at {Math.round(probability * 100)}% was filled
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span>of your limit order was filled</span>
|
|
|
|
)
|
|
|
|
|
|
|
|
if (justSummary) {
|
|
|
|
return (
|
|
|
|
<NotificationSummaryFrame notification={notification} subtitle={subtitle}>
|
|
|
|
<Row className={'line-clamp-1'}>
|
|
|
|
<span className={'text-primary mr-1'}>{amount}</span>
|
|
|
|
<span>{description}</span>
|
|
|
|
</Row>
|
|
|
|
</NotificationSummaryFrame>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<NotificationFrame
|
|
|
|
notification={notification}
|
|
|
|
isChildOfGroup={isChildOfGroup}
|
|
|
|
highlighted={highlighted}
|
|
|
|
subtitle={subtitle}
|
|
|
|
>
|
|
|
|
<Row>
|
|
|
|
<span>
|
|
|
|
<span className="text-primary mr-1">{amount}</span>
|
|
|
|
{description}
|
|
|
|
</span>
|
|
|
|
</Row>
|
|
|
|
</NotificationFrame>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-25 23:37:23 +00:00
|
|
|
export const setNotificationsAsSeen = async (notifications: Notification[]) => {
|
|
|
|
const unseenNotifications = notifications.filter((n) => !n.isSeen)
|
|
|
|
return await Promise.all(
|
|
|
|
unseenNotifications.map((n) => {
|
|
|
|
const notificationDoc = doc(db, `users/${n.userId}/notifications/`, n.id)
|
|
|
|
return updateDoc(notificationDoc, { isSeen: true, viewTime: new Date() })
|
|
|
|
})
|
|
|
|
)
|
2022-07-06 21:06:41 +00:00
|
|
|
}
|
|
|
|
|
2022-07-07 23:23:13 +00:00
|
|
|
function QuestionOrGroupLink(props: {
|
2022-07-07 20:41:50 +00:00
|
|
|
notification: Notification
|
2022-07-07 21:06:29 +00:00
|
|
|
ignoreClick?: boolean
|
2022-07-07 20:41:50 +00:00
|
|
|
}) {
|
2022-07-07 21:06:29 +00:00
|
|
|
const { notification, ignoreClick } = props
|
2022-07-06 13:45:47 +00:00
|
|
|
const {
|
|
|
|
sourceType,
|
|
|
|
sourceContractTitle,
|
|
|
|
sourceContractCreatorUsername,
|
|
|
|
sourceContractSlug,
|
|
|
|
sourceSlug,
|
|
|
|
sourceTitle,
|
|
|
|
} = notification
|
2022-07-07 21:06:29 +00:00
|
|
|
|
|
|
|
if (ignoreClick)
|
2022-07-07 20:41:50 +00:00
|
|
|
return (
|
|
|
|
<span className={'ml-1 font-bold '}>
|
|
|
|
{sourceContractTitle || sourceTitle}
|
|
|
|
</span>
|
|
|
|
)
|
2022-07-06 13:45:47 +00:00
|
|
|
return (
|
2022-07-19 19:58:51 +00:00
|
|
|
<SiteLink
|
|
|
|
className={'relative ml-1 font-bold'}
|
2022-07-06 13:45:47 +00:00
|
|
|
href={
|
|
|
|
sourceContractCreatorUsername
|
|
|
|
? `/${sourceContractCreatorUsername}/${sourceContractSlug}`
|
2022-07-18 16:40:44 +00:00
|
|
|
: // User's added to group or received a tip there
|
|
|
|
(sourceType === 'group' || sourceType === 'tip') && sourceSlug
|
2022-07-06 13:45:47 +00:00
|
|
|
? `${groupPath(sourceSlug)}`
|
2022-07-18 16:40:44 +00:00
|
|
|
: // User referral via group
|
|
|
|
sourceSlug?.includes('/group/')
|
|
|
|
? `${sourceSlug}`
|
2022-07-06 13:45:47 +00:00
|
|
|
: ''
|
|
|
|
}
|
2022-07-07 21:06:29 +00:00
|
|
|
onClick={() =>
|
|
|
|
track('Notification Clicked', {
|
|
|
|
type: 'question title',
|
|
|
|
sourceType,
|
|
|
|
sourceContractTitle,
|
|
|
|
sourceContractCreatorUsername,
|
|
|
|
sourceContractSlug,
|
|
|
|
sourceSlug,
|
|
|
|
sourceTitle,
|
|
|
|
})
|
|
|
|
}
|
2022-07-06 13:45:47 +00:00
|
|
|
>
|
|
|
|
{sourceContractTitle || sourceTitle}
|
2022-07-19 19:58:51 +00:00
|
|
|
</SiteLink>
|
2022-07-06 13:45:47 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-06 19:30:51 +00:00
|
|
|
function getSourceUrl(notification: Notification) {
|
|
|
|
const {
|
|
|
|
sourceType,
|
|
|
|
sourceId,
|
|
|
|
sourceUserUsername,
|
|
|
|
sourceContractCreatorUsername,
|
|
|
|
sourceContractSlug,
|
|
|
|
sourceSlug,
|
|
|
|
} = notification
|
|
|
|
if (sourceType === 'follow') return `/${sourceUserUsername}`
|
|
|
|
if (sourceType === 'group' && sourceSlug) return `${groupPath(sourceSlug)}`
|
2022-07-18 16:40:44 +00:00
|
|
|
// User referral via contract:
|
2022-07-06 19:30:51 +00:00
|
|
|
if (
|
|
|
|
sourceContractCreatorUsername &&
|
|
|
|
sourceContractSlug &&
|
|
|
|
sourceType === 'user'
|
|
|
|
)
|
|
|
|
return `/${sourceContractCreatorUsername}/${sourceContractSlug}`
|
2022-07-18 16:40:44 +00:00
|
|
|
// User referral:
|
|
|
|
if (sourceType === 'user' && !sourceContractSlug)
|
|
|
|
return `/${sourceUserUsername}`
|
2022-08-04 21:27:02 +00:00
|
|
|
if (sourceType === 'challenge') return `${sourceSlug}`
|
2022-07-06 19:30:51 +00:00
|
|
|
if (sourceContractCreatorUsername && sourceContractSlug)
|
|
|
|
return `/${sourceContractCreatorUsername}/${sourceContractSlug}#${getSourceIdForLinkComponent(
|
|
|
|
sourceId ?? '',
|
|
|
|
sourceType
|
|
|
|
)}`
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSourceIdForLinkComponent(
|
|
|
|
sourceId: string,
|
|
|
|
sourceType?: notification_source_types
|
|
|
|
) {
|
|
|
|
switch (sourceType) {
|
|
|
|
case 'answer':
|
|
|
|
return `answer-${sourceId}`
|
|
|
|
case 'comment':
|
|
|
|
return sourceId
|
|
|
|
case 'contract':
|
|
|
|
return ''
|
2022-07-10 18:05:44 +00:00
|
|
|
case 'bet':
|
|
|
|
return ''
|
2022-07-06 19:30:51 +00:00
|
|
|
default:
|
|
|
|
return sourceId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 17:36:59 +00:00
|
|
|
function NotificationTextLabel(props: {
|
2022-06-08 14:43:24 +00:00
|
|
|
notification: Notification
|
2022-06-06 17:36:59 +00:00
|
|
|
className?: string
|
2022-06-09 17:39:23 +00:00
|
|
|
justSummary?: boolean
|
2022-06-06 17:36:59 +00:00
|
|
|
}) {
|
2022-07-11 13:51:48 +00:00
|
|
|
const { className, notification, justSummary } = props
|
2022-07-15 17:53:30 +00:00
|
|
|
const { sourceUpdateType, sourceType, sourceText, reasonText } = notification
|
2022-07-11 13:51:48 +00:00
|
|
|
const defaultText = sourceText ?? reasonText ?? ''
|
2022-06-10 22:48:28 +00:00
|
|
|
if (sourceType === 'contract') {
|
2022-07-15 17:53:30 +00:00
|
|
|
if (justSummary || !sourceText) return <div />
|
2022-06-10 22:48:28 +00:00
|
|
|
// Resolved contracts
|
2022-07-05 17:29:26 +00:00
|
|
|
if (sourceType === 'contract' && sourceUpdateType === 'resolved') {
|
2022-06-10 22:48:28 +00:00
|
|
|
{
|
|
|
|
if (sourceText === 'YES' || sourceText == 'NO') {
|
|
|
|
return <BinaryOutcomeLabel outcome={sourceText as any} />
|
|
|
|
}
|
|
|
|
if (sourceText.includes('%'))
|
|
|
|
return (
|
|
|
|
<ProbPercentLabel prob={parseFloat(sourceText.replace('%', ''))} />
|
|
|
|
)
|
|
|
|
if (sourceText === 'CANCEL') return <CancelLabel />
|
|
|
|
if (sourceText === 'MKT' || sourceText === 'PROB') return <MultiLabel />
|
2022-07-13 13:41:58 +00:00
|
|
|
|
2022-07-11 13:51:48 +00:00
|
|
|
// Numeric market
|
2022-07-13 13:41:58 +00:00
|
|
|
if (parseFloat(sourceText))
|
|
|
|
return <NumericValueLabel value={parseFloat(sourceText)} />
|
|
|
|
|
|
|
|
// Free response market
|
|
|
|
return (
|
|
|
|
<div className={className ? className : 'line-clamp-1 text-blue-400'}>
|
|
|
|
<Linkify text={sourceText} />
|
|
|
|
</div>
|
|
|
|
)
|
2022-06-09 16:30:26 +00:00
|
|
|
}
|
2022-06-10 22:48:28 +00:00
|
|
|
}
|
|
|
|
// Close date will be a number - it looks better without it
|
|
|
|
if (sourceUpdateType === 'closed') {
|
|
|
|
return <div />
|
|
|
|
}
|
|
|
|
// Updated contracts
|
|
|
|
// Description will be in default text
|
|
|
|
if (parseInt(sourceText) > 0) {
|
2022-06-06 17:36:59 +00:00
|
|
|
return (
|
2022-06-10 22:48:28 +00:00
|
|
|
<span>
|
|
|
|
Updated close time: {new Date(parseInt(sourceText)).toLocaleString()}
|
|
|
|
</span>
|
2022-06-06 17:36:59 +00:00
|
|
|
)
|
2022-06-10 22:48:28 +00:00
|
|
|
}
|
2022-07-01 13:47:19 +00:00
|
|
|
} else if (sourceType === 'user' && sourceText) {
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
As a thank you, we sent you{' '}
|
|
|
|
<span className="text-primary">
|
|
|
|
{formatMoney(parseInt(sourceText))}
|
|
|
|
</span>
|
|
|
|
!
|
|
|
|
</span>
|
|
|
|
)
|
2022-06-10 22:48:28 +00:00
|
|
|
} else if (sourceType === 'liquidity' && sourceText) {
|
2022-06-06 17:36:59 +00:00
|
|
|
return (
|
2022-06-10 22:48:28 +00:00
|
|
|
<span className="text-blue-400">{formatMoney(parseInt(sourceText))}</span>
|
2022-06-06 17:36:59 +00:00
|
|
|
)
|
2022-08-04 21:27:02 +00:00
|
|
|
} else if (sourceType === 'challenge' && sourceText) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span> for </span>
|
|
|
|
<span className="text-primary">
|
|
|
|
{formatMoney(parseInt(sourceText))}
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)
|
2022-06-06 17:36:59 +00:00
|
|
|
}
|
2022-06-10 22:48:28 +00:00
|
|
|
return (
|
|
|
|
<div className={className ? className : 'line-clamp-4 whitespace-pre-line'}>
|
|
|
|
<Linkify text={defaultText} />
|
|
|
|
</div>
|
|
|
|
)
|
2022-06-06 17:36:59 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 22:15:36 +00:00
|
|
|
function getReasonForShowingNotification(
|
2022-07-05 17:29:26 +00:00
|
|
|
notification: Notification,
|
2022-07-15 17:53:30 +00:00
|
|
|
justSummary: boolean
|
2022-06-01 18:26:41 +00:00
|
|
|
) {
|
2022-07-06 19:30:51 +00:00
|
|
|
const { sourceType, sourceUpdateType, reason, sourceSlug } = notification
|
2022-06-06 22:15:36 +00:00
|
|
|
let reasonText: string
|
2022-09-12 16:34:56 +00:00
|
|
|
// TODO: we could leave out this switch and just use the reason field now that they have more information
|
2022-09-13 15:54:51 +00:00
|
|
|
if (reason === 'tagged_user')
|
|
|
|
reasonText = justSummary ? 'tagged you' : 'tagged you on'
|
|
|
|
else
|
|
|
|
switch (sourceType) {
|
|
|
|
case 'comment':
|
|
|
|
if (reason === 'reply_to_users_answer')
|
|
|
|
reasonText = justSummary ? 'replied' : 'replied to you on'
|
|
|
|
else if (reason === 'reply_to_users_comment')
|
|
|
|
reasonText = justSummary ? 'replied' : 'replied to you on'
|
|
|
|
else reasonText = justSummary ? `commented` : `commented on`
|
|
|
|
break
|
|
|
|
case 'contract':
|
|
|
|
if (reason === 'contract_from_followed_user')
|
|
|
|
reasonText = justSummary ? 'asked the question' : 'asked'
|
|
|
|
else if (sourceUpdateType === 'resolved')
|
|
|
|
reasonText = justSummary ? `resolved the question` : `resolved`
|
|
|
|
else if (sourceUpdateType === 'closed') reasonText = `Please resolve`
|
|
|
|
else reasonText = justSummary ? 'updated the question' : `updated`
|
|
|
|
break
|
|
|
|
case 'answer':
|
|
|
|
if (reason === 'answer_on_your_contract')
|
|
|
|
reasonText = `answered your question `
|
|
|
|
else reasonText = `answered`
|
|
|
|
break
|
|
|
|
case 'follow':
|
|
|
|
reasonText = 'followed you'
|
|
|
|
break
|
|
|
|
case 'liquidity':
|
|
|
|
reasonText = 'added a subsidy to your question'
|
|
|
|
break
|
|
|
|
case 'group':
|
|
|
|
reasonText = 'added you to the group'
|
|
|
|
break
|
|
|
|
case 'user':
|
|
|
|
if (sourceSlug && reason === 'user_joined_to_bet_on_your_market')
|
|
|
|
reasonText = 'joined to bet on your market'
|
|
|
|
else if (sourceSlug) reasonText = 'joined because you shared'
|
|
|
|
else reasonText = 'joined because of you'
|
|
|
|
break
|
|
|
|
case 'challenge':
|
|
|
|
reasonText = 'accepted your challenge'
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
reasonText = ''
|
|
|
|
}
|
2022-07-15 17:53:30 +00:00
|
|
|
return reasonText
|
2022-06-01 18:26:41 +00:00
|
|
|
}
|