From c15d5e9e91b93c5bfabcf93470cc729fa4fc26fa Mon Sep 17 00:00:00 2001 From: ingawei Date: Thu, 22 Sep 2022 14:54:31 -0700 Subject: [PATCH] making portfolio --- web/components/following-button.tsx | 16 +- web/components/groups/groups-button.tsx | 6 +- web/components/layout/tabs.tsx | 7 +- .../portfolio/portfolio-value-section.tsx | 49 ++- web/components/profile/user-likes-button.tsx | 6 +- web/components/referrals-button.tsx | 10 +- web/components/user-page.tsx | 289 ++++++++++-------- 7 files changed, 240 insertions(+), 143 deletions(-) diff --git a/web/components/following-button.tsx b/web/components/following-button.tsx index fdf739a1..0f570b5f 100644 --- a/web/components/following-button.tsx +++ b/web/components/following-button.tsx @@ -13,16 +13,18 @@ import { useDiscoverUsers } from 'web/hooks/use-users' import { TextButton } from './text-button' import { track } from 'web/lib/service/analytics' -export function FollowingButton(props: { user: User }) { - const { user } = props +export function FollowingButton(props: { user: User; className?: string }) { + const { user, className } = props const [isOpen, setIsOpen] = useState(false) const followingIds = useFollows(user.id) const followerIds = useFollowers(user.id) return ( <> - setIsOpen(true)}> - {followingIds?.length ?? ''}{' '} + setIsOpen(true)} className={className}> + + {followingIds?.length ?? ''} + {' '} Following @@ -69,15 +71,15 @@ export function EditFollowingButton(props: { user: User; className?: string }) { ) } -export function FollowersButton(props: { user: User }) { - const { user } = props +export function FollowersButton(props: { user: User; className?: string }) { + const { user, className } = props const [isOpen, setIsOpen] = useState(false) const followingIds = useFollows(user.id) const followerIds = useFollowers(user.id) return ( <> - setIsOpen(true)}> + setIsOpen(true)} className={className}> {followerIds?.length ?? ''}{' '} Followers diff --git a/web/components/groups/groups-button.tsx b/web/components/groups/groups-button.tsx index e6271466..5c9d2edd 100644 --- a/web/components/groups/groups-button.tsx +++ b/web/components/groups/groups-button.tsx @@ -14,14 +14,14 @@ import { firebaseLogin } from 'web/lib/firebase/users' import { GroupLinkItem } from 'web/pages/groups' import toast from 'react-hot-toast' -export function GroupsButton(props: { user: User }) { - const { user } = props +export function GroupsButton(props: { user: User; className?: string }) { + const { user, className } = props const [isOpen, setIsOpen] = useState(false) const groups = useMemberGroups(user.id) return ( <> - setIsOpen(true)}> + setIsOpen(true)} className={className}> {groups?.length ?? ''} Groups diff --git a/web/components/layout/tabs.tsx b/web/components/layout/tabs.tsx index 3d72b13c..264001b3 100644 --- a/web/components/layout/tabs.tsx +++ b/web/components/layout/tabs.tsx @@ -2,6 +2,7 @@ import clsx from 'clsx' import { useRouter, NextRouter } from 'next/router' import { ReactNode, useState } from 'react' import { track } from '@amplitude/analytics-browser' +import { Col } from './col' type Tab = { title: string @@ -55,11 +56,13 @@ export function ControlledTabs(props: TabProps & { activeIndex: number }) { )} aria-current={activeIndex === i ? 'page' : undefined} > - {tab.tabIcon && {tab.tabIcon}} {tab.badge ? ( {tab.badge} ) : null} - {tab.title} + + {tab.tabIcon &&
{tab.tabIcon}
} + {tab.title} + ))} diff --git a/web/components/portfolio/portfolio-value-section.tsx b/web/components/portfolio/portfolio-value-section.tsx index a0006c60..f46eed8d 100644 --- a/web/components/portfolio/portfolio-value-section.tsx +++ b/web/components/portfolio/portfolio-value-section.tsx @@ -1,3 +1,4 @@ +import clsx from 'clsx' import { formatMoney } from 'common/util/format' import { last } from 'lodash' import { memo, useRef, useState } from 'react' @@ -36,7 +37,7 @@ export const PortfolioValueSection = memo(
Profit
{formatMoney(totalProfit)}
- + */} + ) } ) + +export function PortfolioPeriodSelection(props: { + setPortfolioPeriod: (string: any) => void + portfolioPeriod: string + className?: string + selectClassName?: string +}) { + const { setPortfolioPeriod, portfolioPeriod, className, selectClassName } = + props + return ( + + + + + + + ) +} diff --git a/web/components/profile/user-likes-button.tsx b/web/components/profile/user-likes-button.tsx index 3d4fa9ac..666036a8 100644 --- a/web/components/profile/user-likes-button.tsx +++ b/web/components/profile/user-likes-button.tsx @@ -10,15 +10,15 @@ import { XIcon } from '@heroicons/react/outline' import { unLikeContract } from 'web/lib/firebase/likes' import { contractPath } from 'web/lib/firebase/contracts' -export function UserLikesButton(props: { user: User }) { - const { user } = props +export function UserLikesButton(props: { user: User; className?: string }) { + const { user, className } = props const [isOpen, setIsOpen] = useState(false) const likedContracts = useUserLikedContracts(user.id) return ( <> - setIsOpen(true)}> + setIsOpen(true)} className={className}> {likedContracts?.length ?? ''}{' '} Likes diff --git a/web/components/referrals-button.tsx b/web/components/referrals-button.tsx index 4b4f7095..0f8cef7f 100644 --- a/web/components/referrals-button.tsx +++ b/web/components/referrals-button.tsx @@ -13,14 +13,18 @@ import { getUser, updateUser } from 'web/lib/firebase/users' import { TextButton } from 'web/components/text-button' import { UserLink } from 'web/components/user-link' -export function ReferralsButton(props: { user: User; currentUser?: User }) { - const { user, currentUser } = props +export function ReferralsButton(props: { + user: User + currentUser?: User + className?: string +}) { + const { user, currentUser, className } = props const [isOpen, setIsOpen] = useState(false) const referralIds = useReferrals(user.id) return ( <> - setIsOpen(true)}> + setIsOpen(true)} className={className}> {referralIds?.length ?? ''}{' '} Referrals diff --git a/web/components/user-page.tsx b/web/components/user-page.tsx index c01ec612..fa315772 100644 --- a/web/components/user-page.tsx +++ b/web/components/user-page.tsx @@ -1,8 +1,13 @@ import clsx from 'clsx' import { useEffect, useState } from 'react' -import { useRouter } from 'next/router' +import { NextRouter, useRouter } from 'next/router' import { LinkIcon } from '@heroicons/react/solid' -import { PencilIcon } from '@heroicons/react/outline' +import { + ChatIcon, + FolderIcon, + PencilIcon, + ScaleIcon, +} from '@heroicons/react/outline' import { User } from 'web/lib/firebase/users' import { useUser } from 'web/hooks/use-user' @@ -37,6 +42,7 @@ import { LoansModal } from './profile/loans-modal' import { UserLikesButton } from 'web/components/profile/user-likes-button' import { PAST_BETS } from 'common/user' import { capitalize } from 'lodash' +import { useIsMobile } from 'web/hooks/use-is-mobile' export function UserPage(props: { user: User }) { const { user } = props @@ -45,17 +51,18 @@ export function UserPage(props: { user: User }) { const isCurrentUser = user.id === currentUser?.id const bannerUrl = user.bannerUrl ?? defaultBannerUrl(user.id) const [showConfetti, setShowConfetti] = useState(false) - const [showBettingStreakModal, setShowBettingStreakModal] = useState(false) - const [showLoansModal, setShowLoansModal] = useState(false) + // const [showBettingStreakModal, setShowBettingStreakModal] = useState(false) + // const [showLoansModal, setShowLoansModal] = useState(false) + const isMobile = useIsMobile() useEffect(() => { const claimedMana = router.query['claimed-mana'] === 'yes' - const showBettingStreak = router.query['show'] === 'betting-streak' - setShowBettingStreakModal(showBettingStreak) - setShowConfetti(claimedMana || showBettingStreak) + // const showBettingStreak = router.query['show'] === 'betting-streak' + // setShowBettingStreakModal(showBettingStreak) + // setShowConfetti(claimedMana || showBettingStreak) - const showLoansModel = router.query['show'] === 'loans' - setShowLoansModal(showLoansModel) + // const showLoansModel = router.query['show'] === 'loans' + // setShowLoansModal(showLoansModel) const query = { ...router.query } if (query.claimedMana || query.show) { @@ -85,102 +92,57 @@ export function UserPage(props: { user: User }) { {showConfetti && ( )} - - {showLoansModal && ( - - )} - {/* Banner image up top, with an circle avatar overlaid */} - {/*
*/} - - + + - - - {user.name} - - @{user.username} + {isCurrentUser && ( +
+ + {' '} + +
+ )} + + +
+ + + {user.name} + + + @{user.username} + + + {isCurrentUser && ( + + )} + {!isCurrentUser && } +
+ {!isMobile && ( + + )}
- {/* Top right buttons (e.g. edit, follow) */} -
- {!isCurrentUser && } - {isCurrentUser && ( - - {' '} -
Edit
-
- )} -
- - {/* Profile details: name, username, bio, and link to twitter/discord */} - - - {/* - - {user.name} - - @{user.username} - */} - - - - = 0 ? 'text-green-600' : 'text-red-400' - )} - > - {formatMoney(profit)} - - profit - - setShowBettingStreakModal(true)} - > - 🔥 {user.currentBettingStreak ?? 0} - streak - - setShowLoansModal(true)} - > - - 🏦 {formatMoney(user.nextLoanCached ?? 0)} - - next loan - - - - - + + + {isMobile && } + {user.bio && ( <> -
+
- + )} {(user.website || user.twitterHandle || user.discordHandle) && ( @@ -194,7 +156,7 @@ export function UserPage(props: { user: User }) { > - + {user.website} @@ -215,7 +177,7 @@ export function UserPage(props: { user: User }) { className="h-4 w-4" alt="Twitter" /> - + {user.twitterHandle} @@ -230,7 +192,7 @@ export function UserPage(props: { user: User }) { className="h-4 w-4" alt="Discord" /> - + {user.discordHandle} @@ -238,7 +200,7 @@ export function UserPage(props: { user: User }) { )} )} - {currentUser?.id === user.id && REFERRAL_AMOUNT > 0 && ( + {/* {currentUser?.id === user.id && REFERRAL_AMOUNT > 0 && ( - )} + )} */} , + content: ( + <> + + + + ), + }, { title: 'Markets', + tabIcon: , content: ( ), }, { title: 'Comments', + tabIcon: , content: ( ), }, - { - title: capitalize(PAST_BETS), - content: ( - <> - - - ), - }, - { - title: 'Stats', - content: ( - - - - - - - - - - - ), - }, + // { + // title: 'Stats', + // content: ( + // + // + // + // ), + // }, ]} /> @@ -320,3 +279,87 @@ export function defaultBannerUrl(userId: string) { ] return defaultBanner[genHash(userId)() % defaultBanner.length] } + +export function ProfilePrivateStats(props: { + currentUser: User | null | undefined + profit: number + user: User + router: NextRouter +}) { + const { currentUser, profit, user, router } = props + const [showBettingStreakModal, setShowBettingStreakModal] = useState(false) + const [showLoansModal, setShowLoansModal] = useState(false) + + useEffect(() => { + const showBettingStreak = router.query['show'] === 'betting-streak' + setShowBettingStreakModal(showBettingStreak) + + const showLoansModel = router.query['show'] === 'loans' + setShowLoansModal(showLoansModel) + }, []) + return ( + <> + + + = 0 ? 'text-green-600' : 'text-red-400')} + > + {formatMoney(profit)} + + profit + + setShowBettingStreakModal(true)} + > + + 🔥 {user.currentBettingStreak ?? 0} + + + streak + + + setShowLoansModal(true)} + > + + 🏦 {formatMoney(user.nextLoanCached ?? 0)} + + next loan + + + {BettingStreakModal && ( + + )} + {showLoansModal && ( + + )} + + ) +} + +export function ProfilePublicStats(props: { user: User; className?: string }) { + const { user, className } = props + return ( + + + + {/* */} + + {/* */} + + ) +}