This commit is contained in:
commit
651e61275f
|
@ -231,6 +231,7 @@ export function PinnedItems(props: {
|
||||||
return pinned.length > 0 || isEditable ? (
|
return pinned.length > 0 || isEditable ? (
|
||||||
<div>
|
<div>
|
||||||
<Row className="mb-3 items-center justify-between">
|
<Row className="mb-3 items-center justify-between">
|
||||||
|
<SectionHeader label={'Featured'} href={`#`} />
|
||||||
{isEditable && (
|
{isEditable && (
|
||||||
<Button
|
<Button
|
||||||
color="gray"
|
color="gray"
|
||||||
|
|
|
@ -62,10 +62,12 @@ import { Post } from 'common/post'
|
||||||
import { useAllPosts } from 'web/hooks/use-post'
|
import { useAllPosts } from 'web/hooks/use-post'
|
||||||
import { useGlobalConfig } from 'web/hooks/use-global-config'
|
import { useGlobalConfig } from 'web/hooks/use-global-config'
|
||||||
import { useAdmin } from 'web/hooks/use-admin'
|
import { useAdmin } from 'web/hooks/use-admin'
|
||||||
|
import { GlobalConfig } from 'common/globalConfig'
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const isAdmin = useAdmin()
|
const isAdmin = useAdmin()
|
||||||
|
const globalConfig = useGlobalConfig()
|
||||||
|
|
||||||
useTracking('view home')
|
useTracking('view home')
|
||||||
|
|
||||||
|
@ -103,12 +105,50 @@ export default function Home() {
|
||||||
groups?.map((g) => g.slug)
|
groups?.map((g) => g.slug)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const [pinned, setPinned] = useState<JSX.Element[] | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const pinnedItems = globalConfig?.pinnedItems
|
||||||
|
|
||||||
|
async function getPinned() {
|
||||||
|
if (pinnedItems == null) {
|
||||||
|
if (globalConfig != null) {
|
||||||
|
updateGlobalConfig(globalConfig, { pinnedItems: [] })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const itemComponents = await Promise.all(
|
||||||
|
pinnedItems.map(async (element) => {
|
||||||
|
if (element.type === 'post') {
|
||||||
|
const post = await getPost(element.itemId)
|
||||||
|
if (post) {
|
||||||
|
return <PostCard post={post as Post} />
|
||||||
|
}
|
||||||
|
} else if (element.type === 'contract') {
|
||||||
|
const contract = await getContractFromId(element.itemId)
|
||||||
|
if (contract) {
|
||||||
|
return <ContractCard contract={contract as Contract} />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
setPinned(
|
||||||
|
itemComponents.filter(
|
||||||
|
(element) => element != undefined
|
||||||
|
) as JSX.Element[]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getPinned()
|
||||||
|
}, [globalConfig])
|
||||||
|
|
||||||
const isLoading =
|
const isLoading =
|
||||||
!user ||
|
!user ||
|
||||||
!contractMetricsByProfit ||
|
!contractMetricsByProfit ||
|
||||||
!trendingContracts ||
|
!trendingContracts ||
|
||||||
!newContracts ||
|
!newContracts ||
|
||||||
!dailyTrendingContracts
|
!dailyTrendingContracts ||
|
||||||
|
!globalConfig ||
|
||||||
|
!pinned
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
|
@ -140,7 +180,9 @@ export default function Home() {
|
||||||
'daily-trending': dailyTrendingContracts,
|
'daily-trending': dailyTrendingContracts,
|
||||||
'daily-movers': contractMetricsByProfit,
|
'daily-movers': contractMetricsByProfit,
|
||||||
},
|
},
|
||||||
isAdmin
|
isAdmin,
|
||||||
|
globalConfig,
|
||||||
|
pinned
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{groups && groupContracts && trendingGroups.length > 0 ? (
|
{groups && groupContracts && trendingGroups.length > 0 ? (
|
||||||
|
@ -215,7 +257,9 @@ function renderSections(
|
||||||
newest: CPMMBinaryContract[]
|
newest: CPMMBinaryContract[]
|
||||||
score: CPMMBinaryContract[]
|
score: CPMMBinaryContract[]
|
||||||
},
|
},
|
||||||
isAdmin: boolean
|
isAdmin: boolean,
|
||||||
|
globalConfig: GlobalConfig,
|
||||||
|
pinned: JSX.Element[]
|
||||||
) {
|
) {
|
||||||
type sectionTypes = typeof HOME_SECTIONS[number]['id']
|
type sectionTypes = typeof HOME_SECTIONS[number]['id']
|
||||||
|
|
||||||
|
@ -233,7 +277,7 @@ function renderSections(
|
||||||
if (id === 'featured') {
|
if (id === 'featured') {
|
||||||
// For now, only admins can see the featured section, until we all agree its ship-ready
|
// For now, only admins can see the featured section, until we all agree its ship-ready
|
||||||
if (!isAdmin) return <></>
|
if (!isAdmin) return <></>
|
||||||
return <FeaturedSection />
|
return <FeaturedSection globalConfig={globalConfig} pinned={pinned} />
|
||||||
}
|
}
|
||||||
|
|
||||||
const contracts = sectionContracts[id]
|
const contracts = sectionContracts[id]
|
||||||
|
@ -349,44 +393,12 @@ function SearchSection(props: {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function FeaturedSection() {
|
function FeaturedSection(props: {
|
||||||
const [pinned, setPinned] = useState<JSX.Element[]>([])
|
globalConfig: GlobalConfig
|
||||||
|
pinned: JSX.Element[]
|
||||||
|
}) {
|
||||||
|
const { globalConfig, pinned } = props
|
||||||
const posts = useAllPosts()
|
const posts = useAllPosts()
|
||||||
const globalConfig = useGlobalConfig()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const pinnedItems = globalConfig?.pinnedItems
|
|
||||||
|
|
||||||
async function getPinned() {
|
|
||||||
if (pinnedItems == null) {
|
|
||||||
if (globalConfig != null) {
|
|
||||||
updateGlobalConfig(globalConfig, { pinnedItems: [] })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const itemComponents = await Promise.all(
|
|
||||||
pinnedItems.map(async (element) => {
|
|
||||||
if (element.type === 'post') {
|
|
||||||
const post = await getPost(element.itemId)
|
|
||||||
if (post) {
|
|
||||||
return <PostCard post={post as Post} />
|
|
||||||
}
|
|
||||||
} else if (element.type === 'contract') {
|
|
||||||
const contract = await getContractFromId(element.itemId)
|
|
||||||
if (contract) {
|
|
||||||
return <ContractCard contract={contract as Contract} />
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
setPinned(
|
|
||||||
itemComponents.filter(
|
|
||||||
(element) => element != undefined
|
|
||||||
) as JSX.Element[]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getPinned()
|
|
||||||
}, [globalConfig])
|
|
||||||
|
|
||||||
async function onSubmit(selectedItems: { itemId: string; type: string }[]) {
|
async function onSubmit(selectedItems: { itemId: string; type: string }[]) {
|
||||||
if (globalConfig == null) return
|
if (globalConfig == null) return
|
||||||
|
@ -408,7 +420,6 @@ function FeaturedSection() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col>
|
<Col>
|
||||||
<SectionHeader label={'Featured'} href={`#`} />
|
|
||||||
<PinnedItems
|
<PinnedItems
|
||||||
posts={posts}
|
posts={posts}
|
||||||
isEditable={true}
|
isEditable={true}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user