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

Sports/Explore/Activity page #3217

Merged
merged 10 commits into from
Dec 16, 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
43 changes: 43 additions & 0 deletions backend/api/src/is-sports-bettor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { buildUserInterestsCache } from 'shared/topic-interests'
import { userIdsToAverageTopicConversionScores } from 'shared/topic-interests'
import { type APIHandler } from './helpers/endpoint'
import { createSupabaseDirectClient } from 'shared/supabase/init'
import { NEW_USER_FOLLOWED_TOPIC_SCORE_BOOST } from 'common/feed'
import { log } from 'shared/utils'

const sportsGroupId = '2hGlgVhIyvVaFyQAREPi'
const sportsGroupIds = [sportsGroupId]

export const isSportsInterested: APIHandler<'is-sports-interested'> = async (
_,
auth
) => {
const pg = createSupabaseDirectClient()
if (sportsGroupIds.length === 1) {
const ids = await pg.map(
`select bottom_id from group_groups where top_id = $1`,
[sportsGroupId],
(r) => r.bottom_id as string
)
sportsGroupIds.push(...ids)
}
const userId = auth.uid
if (
!Object.keys(userIdsToAverageTopicConversionScores[userId] ?? {}).length
) {
await buildUserInterestsCache([userId])
}
// Still no topic interests, return default search
if (
!Object.keys(userIdsToAverageTopicConversionScores[userId] ?? {}).length
) {
log('No topic interests, returning true')
return { isSportsInterested: true }
}
const isInterestedInSports = sportsGroupIds.some(
(id) =>
userIdsToAverageTopicConversionScores[userId]?.[id] >=
NEW_USER_FOLLOWED_TOPIC_SCORE_BOOST
)
return { isSportsInterested: isInterestedInSports ?? false }
}
3 changes: 2 additions & 1 deletion backend/api/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ import { updateCategory } from './update-category'
import { getTasks } from './get-tasks'

import { getSiteActivity } from './get-site-activity'

import { isSportsInterested } from './is-sports-bettor'

// we define the handlers in this object in order to typecheck that every API has a handler
export const handlers: { [k in APIPath]: APIHandler<k> } = {
Expand Down Expand Up @@ -314,4 +314,5 @@ export const handlers: { [k in APIPath]: APIHandler<k> } = {
'update-category': updateCategory,
'get-tasks': getTasks,
'get-site-activity': getSiteActivity,
'is-sports-interested': isSportsInterested,
}
1 change: 1 addition & 0 deletions backend/shared/src/supabase/search-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ function getSearchContractWhereSQL(args: {
const filterSQL: FilterSQL = {
open: 'resolution_time IS NULL AND (close_time > NOW() or close_time is null)',
closed: 'close_time < NOW() AND resolution_time IS NULL',
'closing-day': `close_time > now() AND close_time < (now() + interval '1 day' + interval '7 hours') AND resolution_time IS NULL`,
'closing-week': `close_time > now() AND close_time < (now() + interval '7 days' + interval '7 hours') AND resolution_time IS NULL`,
'closing-month': `close_time > now() AND close_time < (now() + interval '30 days' + interval '7 hours') AND resolution_time IS NULL`,
'closing-90-days': `close_time > now() AND close_time < (now() + interval '90 days' + interval '7 hours') AND resolution_time IS NULL`,
Expand Down
9 changes: 8 additions & 1 deletion backend/shared/src/topic-interests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
import { GROUP_SLUGS_TO_NOT_INTRODUCE_IN_FEED } from 'common/envs/constants'
import { HOUR_MS } from 'common/util/time'
import { buildArray } from 'common/util/array'
import {
NEW_USER_FOLLOWED_TOPIC_SCORE_BOOST,
OLD_USER_FOLLOWED_TOPIC_SCORE_BOOST,
} from 'common/feed'

export type TopicToInterestWeights = { [groupId: string]: number }
export const userIdsToAverageTopicConversionScores: {
Expand Down Expand Up @@ -88,7 +92,10 @@ export const buildUserInterestsCache = async (userIds: string[]) => {
} else {
userIdsToAverageTopicConversionScores[userId][groupId] = Math.min(
groupScore +
FOLLOWED_TOPIC_CONVERSION_PRIOR * (hasFewInterests ? 0.5 : 0.3),
FOLLOWED_TOPIC_CONVERSION_PRIOR *
(hasFewInterests
? NEW_USER_FOLLOWED_TOPIC_SCORE_BOOST
: OLD_USER_FOLLOWED_TOPIC_SCORE_BOOST),
1
)
}
Expand Down
1 change: 1 addition & 0 deletions common/src/api/market-search-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const searchProps = z
z.literal('closing-90-days'),
z.literal('closing-week'),
z.literal('closing-month'),
z.literal('closing-day'),
z.literal('closed'),
z.literal('resolved'),
z.literal('all'),
Expand Down
7 changes: 7 additions & 0 deletions common/src/api/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,13 @@ export const API = (_apiTypeCheck = {
returns: {} as { tasks: Task[] },
props: z.object({}).strict(),
},
'is-sports-interested': {
method: 'GET',
visibility: 'public',
authed: true,
returns: {} as { isSportsInterested: boolean },
props: z.object({}).strict(),
},
'get-site-activity': {
method: 'GET',
visibility: 'public',
Expand Down
2 changes: 2 additions & 0 deletions common/src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export const FEED_CARD_MISSES = 5
export const FEED_BETA_LOSS = 5 // 5x worse to show a miss above a hit
export const GROUP_SCORE_PRIOR = 0.34698192227708463 // betaIncompleteInverse(1/6, 5, 5)
export const FOLLOWED_TOPIC_CONVERSION_PRIOR = 3 / 4
export const NEW_USER_FOLLOWED_TOPIC_SCORE_BOOST = 0.6
export const OLD_USER_FOLLOWED_TOPIC_SCORE_BOOST = 0.3
44 changes: 21 additions & 23 deletions web/components/contract/feed-contract-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { User } from 'common/user'
import { formatWithToken, shortFormatNumber } from 'common/util/format'
import { removeUndefinedProps } from 'common/util/object'
import { removeEmojis } from 'common/util/string'
import { capitalize } from 'lodash'
import { TbDropletHeart, TbMoneybag } from 'react-icons/tb'
import { ClaimButton } from 'web/components/ad/claim-ad-button'
import { BinaryMultiAnswersPanel } from 'web/components/answers/binary-multi-answers-panel'
Expand All @@ -37,7 +36,6 @@ import { track } from 'web/lib/service/analytics'
import { getAdCanPayFunds } from 'web/lib/supabase/ads'
import { getMarketMovementInfo } from 'web/lib/supabase/feed-timeline/feed-market-movement-display'
import { SpiceCoin } from 'web/public/custom-components/spiceCoin'
import { SweepiesCoin } from 'web/public/custom-components/sweepiesCoin'
import { SimpleAnswerBars } from '../answers/answers-panel'
import { BetButton } from '../bet/feed-bet-button'
import { CommentsButton } from '../comments/comments-button'
Expand All @@ -53,6 +51,8 @@ import { UserHovercard } from '../user/user-hovercard'
import { ClickFrame } from '../widgets/click-frame'
import { ReactButton } from './react-button'
import { TradesButton } from './trades-button'
import { SweepiesCoin } from 'web/public/custom-components/sweepiesCoin'
import { capitalize } from 'lodash'

const DEBUG_FEED_CARDS =
typeof window != 'undefined' &&
Expand Down Expand Up @@ -167,9 +167,7 @@ export function FeedContractCard(props: {
return (
<ClickFrame
className={clsx(
isPrizeMarket || isCashContract
? 'mt-2 ring-1 ring-amber-200 hover:ring-amber-400 dark:ring-amber-400 hover:dark:ring-amber-200'
: 'ring-primary-200 hover:ring-1',
'ring-primary-200 hover:ring-1',

'relative cursor-pointer rounded-xl transition-all ',
'flex w-full flex-col gap-0.5 px-4',
Expand Down Expand Up @@ -198,18 +196,6 @@ export function FeedContractCard(props: {
<SpiceCoin className="-mt-0.5" /> Prize Market
</span>
</div>
) : isCashContract ? (
<div
className={clsx(
'absolute right-4 top-0 z-40 -translate-y-1/2 transform bg-amber-200 text-amber-700',
'rounded-full px-2 py-0.5 text-xs font-semibold'
)}
>
<span>
<SweepiesCoin className="-mt-0.5" /> {capitalize(SWEEPIES_NAME)}{' '}
Market
</span>
</div>
) : (
<></>
)}
Expand All @@ -236,10 +222,22 @@ export function FeedContractCard(props: {
</Row>
</UserHovercard>
<Row className="gap-2">
{promotedData && canAdPay && (
<div className="text-ink-400 w-12 text-sm">
Ad {adSecondsLeft ? adSecondsLeft + 's' : ''}
</div>
{isCashContract ? (
<span
className={clsx(
' bg-amber-200 text-amber-700',
'rounded-full px-2 pt-1 text-xs font-semibold'
)}
>
<SweepiesCoin className="-mt-0.5" /> {capitalize(SWEEPIES_NAME)}{' '}
</span>
) : (
promotedData &&
canAdPay && (
<div className="text-ink-400 w-12 text-sm">
Ad {adSecondsLeft ? adSecondsLeft + 's' : ''}
</div>
)
)}
{marketTier ? (
<TierTooltip tier={marketTier} contract={contract} />
Expand Down Expand Up @@ -532,9 +530,9 @@ export const LoadingCards = (props: { rows?: number }) => {
const { rows = 3 } = props
return (
<Col className="w-full">
{[...Array(rows)].map((r) => (
{[...Array(rows)].map((r, i) => (
<Col
key={'loading-' + r}
key={'loading-' + i}
className="bg-canvas-0 border-canvas-0 mb-4 gap-2 rounded-xl border p-4 drop-shadow-md"
>
<Row className="mb-2 items-center gap-2">
Expand Down
15 changes: 10 additions & 5 deletions web/components/layout/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { usePersistentLocalState } from 'web/hooks/use-persistent-local-state'

export type Tab = {
title: string
titleElement?: ReactNode
content: ReactNode
stackedTabIcon?: ReactNode
inlineTabIcon?: ReactNode
Expand Down Expand Up @@ -80,7 +81,9 @@ export function MinimalistTabs(props: TabProps & { activeIndex: number }) {
)}
>
<Tooltip text={tab.tooltip}>
<Row className={'items-center'}>{tab.title}</Row>
<Row className={'items-center'}>
{tab.titleElement ?? tab.title}
</Row>
</Tooltip>
</a>
))}
Expand Down Expand Up @@ -166,7 +169,7 @@ export function ControlledTabs(props: TabProps & { activeIndex: number }) {
<Row className="justify-center">{tab.stackedTabIcon}</Row>
)}
<Row className={'items-center'}>
{tab.title}
{tab.titleElement ?? tab.title}
{tab.inlineTabIcon}
</Row>
</Tooltip>
Expand Down Expand Up @@ -237,6 +240,7 @@ export function QueryUncontrolledTabs(
scrollToTop?: boolean
minimalist?: boolean
saveTabInLocalStorageKey?: string
tabInUrlKey?: string
}
) {
const {
Expand All @@ -245,13 +249,14 @@ export function QueryUncontrolledTabs(
onClick,
scrollToTop,
saveTabInLocalStorageKey,
tabInUrlKey = 'tab',
...rest
} = props
const router = useRouter()
const pathName = usePathname()
const { searchParams, createQueryString } = useDefinedSearchParams()
const selectedIdx = tabs.findIndex((t) =>
isTabSelected(searchParams, 'tab', t)
isTabSelected(searchParams, tabInUrlKey, t)
)
const [savedTabIndex, setSavedTabIndex] = usePersistentLocalState<
number | undefined
Expand Down Expand Up @@ -280,7 +285,7 @@ export function QueryUncontrolledTabs(
onClick={(title) => {
if (scrollToTop) window.scrollTo({ top: 0 })
router.replace(
pathName + '?' + createQueryString('tab', title),
pathName + '?' + createQueryString(tabInUrlKey, title),
undefined,
{ shallow: true }
)
Expand All @@ -296,7 +301,7 @@ export function QueryUncontrolledTabs(
onClick={(title) => {
if (scrollToTop) window.scrollTo({ top: 0 })
router.replace(
pathName + '?' + createQueryString('tab', title),
pathName + '?' + createQueryString(tabInUrlKey, title),
undefined,
{ shallow: true }
)
Expand Down
14 changes: 7 additions & 7 deletions web/components/nav/bottom-nav-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { User } from 'common/user'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { Fragment, useState } from 'react'
import { GiCapitol } from 'react-icons/gi'
import { UnseenMessagesBubble } from 'web/components/messaging/messages-icon'
import { NotificationsIcon } from 'web/components/notifications-icon'
import { useIsIframe } from 'web/hooks/use-is-iframe'
Expand All @@ -32,6 +31,7 @@ import { Avatar } from '../widgets/avatar'
import { CoinNumber } from '../widgets/coin-number'
import Sidebar from './sidebar'
import { NavItem } from './sidebar-item'
import { PiSquaresFour } from 'react-icons/pi'

export const BOTTOM_NAV_BAR_HEIGHT = 58

Expand All @@ -48,9 +48,9 @@ function getNavigation(user: User) {
icon: SearchIcon,
},
{
name: 'Activity',
href: '/activity',
icon: LightningBoltIcon,
name: 'Markets',
href: '/markets',
icon: PiSquaresFour,
},
{
name: 'Profile',
Expand All @@ -67,9 +67,9 @@ function getNavigation(user: User) {
const signedOutNavigation = () => [
{ name: 'Browse', href: '/browse', icon: SearchIcon, alwaysShowName: true },
{
name: 'Election',
href: '/election',
icon: GiCapitol,
name: 'Markets',
href: '/markets',
icon: PiSquaresFour,
alwaysShowName: true,
// prefetch: false, // should we not prefetch this?
},
Expand Down
22 changes: 10 additions & 12 deletions web/components/nav/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
QuestionMarkCircleIcon,
NewspaperIcon,
LoginIcon,
GlobeAltIcon,
SearchIcon,
} from '@heroicons/react/outline'
import TrophyIcon from 'web/lib/icons/trophy-icon.svg'
Expand Down Expand Up @@ -36,7 +35,7 @@ import { ReportsIcon } from '../reports-icon'
import { AddFundsButton } from '../profile/add-funds-button'
import { Col } from '../layout/col'
import { TbPigMoney } from 'react-icons/tb'
import { LightningBoltIcon } from '@heroicons/react/outline'
import { PiSquaresFourLight } from 'react-icons/pi'
// import { PiRobotBold } from 'react-icons/pi'

export default function Sidebar(props: {
Expand Down Expand Up @@ -140,14 +139,9 @@ const getDesktopNav = (
return buildArray(
{ name: 'Browse', href: '/home', icon: SearchIcon },
{
name: 'Activity',
href: '/activity',
icon: LightningBoltIcon,
},
{
name: 'Explore',
href: '/explore',
icon: GlobeAltIcon,
name: 'Markets',
href: '/markets',
icon: PiSquaresFourLight,
},
{
name: 'Notifications',
Expand Down Expand Up @@ -209,9 +203,13 @@ const getMobileNav = (
const { isAdminOrMod } = options

return buildArray<NavItem>(
{ name: 'Markets', href: '/markets', icon: PiSquaresFourLight },
{ name: 'Leagues', href: '/leagues', icon: TrophyIcon },
{ name: 'Explore', href: '/explore', icon: GlobeAltIcon },
// {
{
name: 'Markets',
href: '/markets',
icon: PiSquaresFourLight,
}, // {
// name: 'AI',
// href: '/ai',
// icon: PiRobotBold,
Expand Down
7 changes: 1 addition & 6 deletions web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ module.exports = {
},
{
source: '/this-month',
destination: '/markets?f=closing-this-month&s=most-popular',
permanent: true,
},
{
source: '/markets',
destination: '/browse',
destination: '/browse?f=closing-this-month&s=most-popular',
permanent: true,
},
{
Expand Down
Loading
Loading