Tweaks for loading daily movers
This commit is contained in:
parent
c7cddb3dcd
commit
0dd8a1df8f
|
@ -2,34 +2,35 @@ import clsx from 'clsx'
|
||||||
import { contractPath } from 'web/lib/firebase/contracts'
|
import { contractPath } from 'web/lib/firebase/contracts'
|
||||||
import { CPMMContract } from 'common/contract'
|
import { CPMMContract } from 'common/contract'
|
||||||
import { formatPercent } from 'common/util/format'
|
import { formatPercent } from 'common/util/format'
|
||||||
import { useProbChanges } from 'web/hooks/use-prob-changes'
|
|
||||||
import { SiteLink } from '../site-link'
|
import { SiteLink } from '../site-link'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
import { Row } from '../layout/row'
|
import { Row } from '../layout/row'
|
||||||
|
import { LoadingIndicator } from '../loading-indicator'
|
||||||
|
|
||||||
export function ProbChangeTable(props: { userId: string | null | undefined }) {
|
export function ProbChangeTable(props: {
|
||||||
const { userId } = props
|
changes:
|
||||||
|
| { positiveChanges: CPMMContract[]; negativeChanges: CPMMContract[] }
|
||||||
|
| undefined
|
||||||
|
}) {
|
||||||
|
const { changes } = props
|
||||||
|
|
||||||
const changes = useProbChanges(userId ?? '')
|
if (!changes) return <LoadingIndicator />
|
||||||
|
|
||||||
if (!changes) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const count = 6
|
|
||||||
|
|
||||||
const { positiveChanges, negativeChanges } = changes
|
const { positiveChanges, negativeChanges } = changes
|
||||||
const filteredPositiveChanges = positiveChanges.slice(0, count / 2)
|
if (positiveChanges.length === 0 && negativeChanges.length === 0) return null
|
||||||
const filteredNegativeChanges = negativeChanges.slice(0, count / 2)
|
|
||||||
const filteredChanges = [
|
const rows = Math.min(
|
||||||
...filteredPositiveChanges,
|
Math.min(positiveChanges.length, negativeChanges.length),
|
||||||
...filteredNegativeChanges,
|
3
|
||||||
]
|
)
|
||||||
|
|
||||||
|
const filteredPositiveChanges = positiveChanges.slice(0, rows)
|
||||||
|
const filteredNegativeChanges = negativeChanges.slice(0, rows)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="mb-4 w-full divide-x-2 divide-y rounded-lg bg-white shadow-md md:flex-row md:divide-y-0">
|
<Col className="mb-4 w-full divide-x-2 divide-y rounded-lg bg-white shadow-md md:flex-row md:divide-y-0">
|
||||||
<Col className="flex-1 divide-y">
|
<Col className="flex-1 divide-y">
|
||||||
{filteredChanges.slice(0, count / 2).map((contract) => (
|
{filteredPositiveChanges.map((contract) => (
|
||||||
<Row className="items-center hover:bg-gray-100">
|
<Row className="items-center hover:bg-gray-100">
|
||||||
<ProbChange
|
<ProbChange
|
||||||
className="p-4 text-right text-xl"
|
className="p-4 text-right text-xl"
|
||||||
|
@ -45,7 +46,7 @@ export function ProbChangeTable(props: { userId: string | null | undefined }) {
|
||||||
))}
|
))}
|
||||||
</Col>
|
</Col>
|
||||||
<Col className="flex-1 divide-y">
|
<Col className="flex-1 divide-y">
|
||||||
{filteredChanges.slice(count / 2).map((contract) => (
|
{filteredNegativeChanges.map((contract) => (
|
||||||
<Row className="items-center hover:bg-gray-100">
|
<Row className="items-center hover:bg-gray-100">
|
||||||
<ProbChange
|
<ProbChange
|
||||||
className="p-4 text-right text-xl"
|
className="p-4 text-right text-xl"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState } from 'react'
|
import React from 'react'
|
||||||
import Router from 'next/router'
|
import Router from 'next/router'
|
||||||
import {
|
import {
|
||||||
PencilIcon,
|
PencilIcon,
|
||||||
|
@ -28,6 +28,7 @@ import { groupPath } from 'web/lib/firebase/groups'
|
||||||
import { usePortfolioHistory } from 'web/hooks/use-portfolio-history'
|
import { usePortfolioHistory } from 'web/hooks/use-portfolio-history'
|
||||||
import { calculatePortfolioProfit } from 'common/calculate-metrics'
|
import { calculatePortfolioProfit } from 'common/calculate-metrics'
|
||||||
import { formatMoney } from 'common/util/format'
|
import { formatMoney } from 'common/util/format'
|
||||||
|
import { useProbChanges } from 'web/hooks/use-prob-changes'
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
@ -38,8 +39,7 @@ const Home = () => {
|
||||||
|
|
||||||
const groups = useMemberGroups(user?.id) ?? []
|
const groups = useMemberGroups(user?.id) ?? []
|
||||||
|
|
||||||
const [homeSections] = useState(user?.homeSections ?? [])
|
const { sections } = getHomeItems(groups, user?.homeSections ?? [])
|
||||||
const { sections } = getHomeItems(groups, homeSections)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
|
@ -152,6 +152,8 @@ function GroupSection(props: { group: Group; user: User | null | undefined }) {
|
||||||
|
|
||||||
function DailyMoversSection(props: { userId: string | null | undefined }) {
|
function DailyMoversSection(props: { userId: string | null | undefined }) {
|
||||||
const { userId } = props
|
const { userId } = props
|
||||||
|
const changes = useProbChanges(userId ?? '')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="gap-2">
|
<Col className="gap-2">
|
||||||
<SiteLink className="text-xl" href={'/daily-movers'}>
|
<SiteLink className="text-xl" href={'/daily-movers'}>
|
||||||
|
@ -161,7 +163,7 @@ function DailyMoversSection(props: { userId: string | null | undefined }) {
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
</SiteLink>
|
</SiteLink>
|
||||||
<ProbChangeTable userId={userId} />
|
<ProbChangeTable changes={changes} />
|
||||||
</Col>
|
</Col>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user