diff --git a/web/components/contract-search.tsx b/web/components/contract-search.tsx index 56bc965d..34e1ff0d 100644 --- a/web/components/contract-search.tsx +++ b/web/components/contract-search.tsx @@ -91,6 +91,8 @@ export function ContractSearch(props: { useQuerySortLocalStorage?: boolean useQuerySortUrlParams?: boolean isWholePage?: boolean + maxItems?: number + noControls?: boolean }) { const { user, @@ -105,6 +107,8 @@ export function ContractSearch(props: { useQuerySortLocalStorage, useQuerySortUrlParams, isWholePage, + maxItems, + noControls, } = props const [numPages, setNumPages] = useState(1) @@ -158,6 +162,8 @@ export function ContractSearch(props: { const contracts = pages .flat() .filter((c) => !additionalFilter?.excludeContractIds?.includes(c.id)) + const renderedContracts = + pages.length === 0 ? undefined : contracts.slice(0, maxItems) if (IS_PRIVATE_MANIFOLD || process.env.NEXT_PUBLIC_FIREBASE_EMULATE) { return @@ -175,10 +181,11 @@ export function ContractSearch(props: { useQuerySortUrlParams={useQuerySortUrlParams} user={user} onSearchParametersChanged={onSearchParametersChanged} + noControls={noControls} /> + } + return ( ))} - + {loadMore && ( + + )} ) } diff --git a/web/pages/experimental/home.tsx b/web/pages/experimental/home.tsx new file mode 100644 index 00000000..380f4286 --- /dev/null +++ b/web/pages/experimental/home.tsx @@ -0,0 +1,118 @@ +import React from 'react' +import { useRouter } from 'next/router' +import { PlusSmIcon } from '@heroicons/react/solid' + +import { Page } from 'web/components/page' +import { Col } from 'web/components/layout/col' +import { ContractSearch } from 'web/components/contract-search' +import { User } from 'common/user' +import { getUserAndPrivateUser } from 'web/lib/firebase/users' +import { useTracking } from 'web/hooks/use-tracking' +import { track } from 'web/lib/service/analytics' +import { authenticateOnServer } from 'web/lib/firebase/server-auth' +import { useSaveReferral } from 'web/hooks/use-save-referral' +import { GetServerSideProps } from 'next' +import { Sort } from 'web/hooks/use-sort-and-query-params' +import { Button } from 'web/components/button' +import { Spacer } from 'web/components/layout/spacer' +import { useMemberGroups } from 'web/hooks/use-group' +import { Group } from 'common/group' +import { Title } from 'web/components/title' + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const creds = await authenticateOnServer(ctx) + const auth = creds ? await getUserAndPrivateUser(creds.user.uid) : null + return { props: { auth } } +} + +const Home = (props: { auth: { user: User } | null }) => { + const user = props.auth ? props.auth.user : null + + const router = useRouter() + useTracking('view home') + + useSaveReferral() + + const memberGroups = (useMemberGroups(user?.id) ?? []).filter( + (group) => group.contractIds.length > 0 + ) + + return ( + + + + + + {memberGroups.map((group) => ( + + ))} + + + + ) +} + +function SearchSection(props: { + label: string + user: User | null + sort: Sort +}) { + const { label, user, sort } = props + + const router = useRouter() + + return ( + + + <Spacer h={2} /> + <ContractSearch user={user} defaultSort={sort} maxItems={4} noControls /> + <Button + className="self-end" + color="blue" + size="sm" + onClick={() => router.push(`/home?s=${sort}`)} + > + See more + </Button> + </Col> + ) +} + +function GroupSection(props: { group: Group; user: User | null }) { + const { group, user } = props + + const router = useRouter() + + return ( + <Col className=""> + <Title className="mx-2 !text-gray-800 sm:mx-0" text={group.name} /> + <Spacer h={2} /> + <ContractSearch + user={user} + defaultSort={'score'} + additionalFilter={{ groupSlug: group.slug }} + maxItems={4} + noControls + /> + <Button + className="mr-2 self-end" + color="blue" + size="sm" + onClick={() => router.push(`/group/${group.slug}`)} + > + See more + </Button> + </Col> + ) +} + +export default Home