2022-06-23 08:07:52 +00:00
|
|
|
import { useState } from 'react'
|
2022-08-02 22:08:07 +00:00
|
|
|
|
|
|
|
import dayjs from 'dayjs'
|
|
|
|
import customParseFormat from 'dayjs/plugin/customParseFormat'
|
|
|
|
dayjs.extend(customParseFormat)
|
|
|
|
|
2022-06-23 08:07:52 +00:00
|
|
|
import { formatMoney } from 'common/util/format'
|
|
|
|
import { Col } from 'web/components/layout/col'
|
2022-07-13 21:57:34 +00:00
|
|
|
import { Row } from 'web/components/layout/row'
|
2022-06-23 08:07:52 +00:00
|
|
|
import { Page } from 'web/components/page'
|
|
|
|
import { SEO } from 'web/components/SEO'
|
|
|
|
import { Title } from 'web/components/title'
|
2022-07-13 21:57:34 +00:00
|
|
|
import { Subtitle } from 'web/components/subtitle'
|
2022-08-09 05:43:04 +00:00
|
|
|
import { getUser } from 'web/lib/firebase/users'
|
2022-07-13 21:57:34 +00:00
|
|
|
import { useUserManalinks } from 'web/lib/firebase/manalinks'
|
2022-07-14 00:43:20 +00:00
|
|
|
import { useUserById } from 'web/hooks/use-user'
|
2022-06-23 08:07:52 +00:00
|
|
|
import { ManalinkTxn } from 'common/txn'
|
2022-08-09 05:43:04 +00:00
|
|
|
import { User } from 'common/user'
|
2022-06-23 08:07:52 +00:00
|
|
|
import { Avatar } from 'web/components/avatar'
|
|
|
|
import { RelativeTimestamp } from 'web/components/relative-timestamp'
|
|
|
|
import { UserLink } from 'web/components/user-page'
|
2022-07-13 21:57:34 +00:00
|
|
|
import { CreateLinksButton } from 'web/components/manalinks/create-links-button'
|
2022-07-19 07:50:11 +00:00
|
|
|
import { redirectIfLoggedOut } from 'web/lib/firebase/server-auth'
|
2022-06-23 08:07:52 +00:00
|
|
|
|
2022-07-21 05:45:53 +00:00
|
|
|
import { ManalinkCardFromView } from 'web/components/manalink-card'
|
|
|
|
import { Pagination } from 'web/components/pagination'
|
2022-07-22 01:22:17 +00:00
|
|
|
import { Manalink } from 'common/manalink'
|
2022-08-02 22:08:07 +00:00
|
|
|
import { REFERRAL_AMOUNT } from 'common/user'
|
2022-08-10 02:51:01 +00:00
|
|
|
import { SiteLink } from 'web/components/site-link'
|
2022-06-23 08:07:52 +00:00
|
|
|
|
2022-07-21 05:45:53 +00:00
|
|
|
const LINKS_PER_PAGE = 24
|
2022-08-09 05:43:04 +00:00
|
|
|
|
|
|
|
export const getServerSideProps = redirectIfLoggedOut('/', async (_, creds) => {
|
|
|
|
const user = await getUser(creds.user.uid)
|
|
|
|
return { props: { user } }
|
|
|
|
})
|
2022-07-19 07:50:11 +00:00
|
|
|
|
2022-07-13 21:57:34 +00:00
|
|
|
export function getManalinkUrl(slug: string) {
|
2022-06-23 08:07:52 +00:00
|
|
|
return `${location.protocol}//${location.host}/link/${slug}`
|
|
|
|
}
|
|
|
|
|
2022-08-09 05:43:04 +00:00
|
|
|
export default function LinkPage(props: { user: User }) {
|
|
|
|
const { user } = props
|
|
|
|
const links = useUserManalinks(user.id ?? '')
|
2022-06-23 08:07:52 +00:00
|
|
|
// const manalinkTxns = useManalinkTxns(user?.id ?? '')
|
|
|
|
const [highlightedSlug, setHighlightedSlug] = useState('')
|
|
|
|
const unclaimedLinks = links.filter(
|
|
|
|
(l) =>
|
|
|
|
(l.maxUses == null || l.claimedUserIds.length < l.maxUses) &&
|
|
|
|
(l.expiresTime == null || l.expiresTime > Date.now())
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<SEO
|
|
|
|
title="Manalinks"
|
2022-07-13 21:57:34 +00:00
|
|
|
description="Send M$ to others with a link, even if they don't have a Manifold account yet!"
|
2022-06-23 08:07:52 +00:00
|
|
|
url="/send"
|
|
|
|
/>
|
|
|
|
<Col className="w-full px-8">
|
2022-07-13 21:57:34 +00:00
|
|
|
<Row className="items-center justify-between">
|
|
|
|
<Title text="Manalinks" />
|
|
|
|
{user && (
|
|
|
|
<CreateLinksButton
|
|
|
|
user={user}
|
|
|
|
highlightedSlug={highlightedSlug}
|
|
|
|
setHighlightedSlug={setHighlightedSlug}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Row>
|
|
|
|
<p>
|
2022-08-02 22:08:07 +00:00
|
|
|
You can use manalinks to send mana (M$) to other people, even if they
|
2022-08-10 02:51:01 +00:00
|
|
|
don't yet have a Manifold account.{' '}
|
|
|
|
<SiteLink href="/referrals">
|
|
|
|
Eligible for {formatMoney(REFERRAL_AMOUNT)} referral bonus if a new
|
|
|
|
user signs up!
|
|
|
|
</SiteLink>
|
2022-07-13 21:57:34 +00:00
|
|
|
</p>
|
|
|
|
<Subtitle text="Your Manalinks" />
|
2022-07-22 01:22:17 +00:00
|
|
|
<ManalinksDisplay
|
|
|
|
unclaimedLinks={unclaimedLinks}
|
|
|
|
highlightedSlug={highlightedSlug}
|
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function ManalinksDisplay(props: {
|
|
|
|
unclaimedLinks: Manalink[]
|
|
|
|
highlightedSlug: string
|
|
|
|
}) {
|
|
|
|
const { unclaimedLinks, highlightedSlug } = props
|
|
|
|
const [page, setPage] = useState(0)
|
|
|
|
const start = page * LINKS_PER_PAGE
|
|
|
|
const end = start + LINKS_PER_PAGE
|
|
|
|
const displayedLinks = unclaimedLinks.slice(start, end)
|
|
|
|
|
|
|
|
if (unclaimedLinks.length === 0) {
|
|
|
|
return (
|
|
|
|
<p className="text-gray-500">
|
|
|
|
You don't have any unclaimed manalinks. Send some more to spread the
|
|
|
|
wealth!
|
|
|
|
</p>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<>
|
2022-07-21 05:45:53 +00:00
|
|
|
<Col className="grid w-full gap-4 md:grid-cols-2">
|
2022-07-22 01:22:17 +00:00
|
|
|
{displayedLinks.map((link) => (
|
|
|
|
<ManalinkCardFromView
|
|
|
|
key={link.slug + link.createdTime}
|
|
|
|
link={link}
|
|
|
|
highlightedSlug={highlightedSlug}
|
|
|
|
/>
|
|
|
|
))}
|
2022-07-21 05:45:53 +00:00
|
|
|
</Col>
|
|
|
|
<Pagination
|
|
|
|
page={page}
|
|
|
|
itemsPerPage={LINKS_PER_PAGE}
|
|
|
|
totalItems={unclaimedLinks.length}
|
|
|
|
setPage={setPage}
|
|
|
|
className="mt-4 bg-transparent"
|
|
|
|
scrollToTop
|
|
|
|
/>
|
2022-07-22 01:22:17 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2022-06-23 08:07:52 +00:00
|
|
|
}
|
|
|
|
|
2022-07-21 05:45:53 +00:00
|
|
|
// TODO: either utilize this or get rid of it
|
2022-06-23 08:07:52 +00:00
|
|
|
export function ClaimsList(props: { txns: ManalinkTxn[] }) {
|
|
|
|
const { txns } = props
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h1 className="mb-4 text-xl font-semibold text-gray-900">
|
|
|
|
Claimed links
|
|
|
|
</h1>
|
|
|
|
{txns.map((txn) => (
|
|
|
|
<ClaimDescription txn={txn} key={txn.id} />
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ClaimDescription(props: { txn: ManalinkTxn }) {
|
|
|
|
const { txn } = props
|
|
|
|
const from = useUserById(txn.fromId)
|
|
|
|
const to = useUserById(txn.toId)
|
|
|
|
|
|
|
|
if (!from || !to) {
|
|
|
|
return <>Loading...</>
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="mb-2 flow-root pr-2 md:pr-0">
|
|
|
|
<div className="relative flex items-center space-x-3">
|
|
|
|
<Avatar username={to.name} avatarUrl={to.avatarUrl} size="sm" />
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
<p className="mt-0.5 text-sm text-gray-500">
|
|
|
|
<UserLink
|
|
|
|
className="text-gray-500"
|
|
|
|
username={to.username}
|
|
|
|
name={to.name}
|
|
|
|
/>{' '}
|
|
|
|
claimed {formatMoney(txn.amount)} from{' '}
|
|
|
|
<UserLink
|
|
|
|
className="text-gray-500"
|
|
|
|
username={from.username}
|
|
|
|
name={from.name}
|
|
|
|
/>
|
|
|
|
<RelativeTimestamp time={txn.createdTime} />
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|