manifold/web/components/arrange-home.tsx

142 lines
4.0 KiB
TypeScript
Raw Normal View History

import clsx from 'clsx'
import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd'
import { MenuIcon } from '@heroicons/react/solid'
2022-09-17 23:30:27 +00:00
import { toast } from 'react-hot-toast'
Verify balance of limit order "makers" (#1007) * Fetch balance of users with open limit orders & cancel orders with insufficient balance * Fix imports * Fix bugs * Fix a bug * Remove redundant cast * buttons overlaying content fix (#1005) * buttons overlaying content fix * stats: round DAU number * made set width for portfolio/profit fields (#1006) * tournaments: included resolved markets * made delete red, moved button for regular posts (#1008) * Fix localstorage saved user being overwritten on every page load * Market page: Show no right panel while user loading * Don't flash sign in button if user is loading * election map coloring * market group modal scroll fix (#1009) * midterms: posititoning, make mobile friendly * Un-daisy share buttons (#1010) * Make embed and challenge buttons non-daisyui * Allow link Buttons. Change tweet, dupe buttons. * lint * don't insert extra lines when upload photos * Map fixes (#1011) * usa map: fix sizing * useSetIframeBackbroundColor * preload contracts * seo * remove hook * turn off sprig on dev * Render timestamp only on client to prevent error of server not matching client * Make sized container have default height so graph doesn't jump * midterms: use null in static props * Create common card component (#1012) * Create common card component * lint * add key prop to pills * redirect to /home after login * create market: use transaction * card: reduce border size * Update groupContracts in db trigger * Default sort to best * Save comment sort per user rather than per contract * Refactor Pinned Items into a reusable component * Revert "create market: use transaction" This reverts commit e1f24f24a96fa8d811ebcaa3b10b19d9b67cb282. * Mark @v with a (Bot) label * fix padding on daily movers * fix type errors * Wrap sprig init in check for window * unindex date-docs from search engines * Auto-prettification * compute elasticity * change dpm elasticity * Fix google lighthouse issues (#1013) * don't hide free response panel on open resolve * liquidity sort * Limit order trade log: '/' to 'of'. Remove 'of' in 'of YES'. * Date doc: Toggle to disable creating a prediction market * Listen for date doc changes * Fix merge error * Don't cancel all a users limit orders if they go negative Co-authored-by: ingawei <46611122+ingawei@users.noreply.github.com> Co-authored-by: mantikoros <sgrugett@gmail.com> Co-authored-by: Sinclair Chen <abc.sinclair@gmail.com> Co-authored-by: mantikoros <95266179+mantikoros@users.noreply.github.com> Co-authored-by: Ian Philips <iansphilips@gmail.com> Co-authored-by: Pico2x <pico2x@gmail.com> Co-authored-by: Austin Chen <akrolsmir@gmail.com> Co-authored-by: sipec <sipec@users.noreply.github.com>
2022-10-07 03:16:49 +00:00
import { XCircleIcon } from '@heroicons/react/outline'
import { Col } from 'web/components/layout/col'
import { Row } from 'web/components/layout/row'
import { Subtitle } from 'web/components/subtitle'
import { keyBy } from 'lodash'
2022-09-17 23:30:27 +00:00
import { Button } from './button'
import { updateUser } from 'web/lib/firebase/users'
import { leaveGroup } from 'web/lib/firebase/groups'
import { User } from 'common/user'
import { useUser } from 'web/hooks/use-user'
import { Group } from 'common/group'
export function ArrangeHome(props: {
2022-09-17 23:30:27 +00:00
sections: { label: string; id: string; group?: Group }[]
setSectionIds: (sections: string[]) => void
}) {
const { sections, setSectionIds } = props
const sectionsById = keyBy(sections, 'id')
return (
<DragDropContext
onDragEnd={(e) => {
const { destination, source, draggableId } = e
if (!destination) return
const section = sectionsById[draggableId]
const newSectionIds = sections.map((section) => section.id)
newSectionIds.splice(source.index, 1)
newSectionIds.splice(destination.index, 0, section.id)
setSectionIds(newSectionIds)
}}
>
<Row className="relative max-w-md gap-4">
<DraggableList items={sections} title="Sections" />
</Row>
</DragDropContext>
)
}
function DraggableList(props: {
title: string
2022-09-17 23:30:27 +00:00
items: { id: string; label: string; group?: Group }[]
}) {
2022-09-17 23:30:27 +00:00
const user = useUser()
const { title, items } = props
return (
<Droppable droppableId={title.toLowerCase()}>
{(provided) => (
<Col
{...provided.droppableProps}
ref={provided.innerRef}
className={clsx('flex-1 items-stretch gap-1 rounded bg-gray-100 p-4')}
>
<Subtitle text={title} className="mx-2 !mt-0 !mb-4" />
{items.map((item, index) => (
<Draggable key={item.id} draggableId={item.id} index={index}>
{(provided, snapshot) => (
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
style={provided.draggableProps.style}
>
<SectionItem
className={clsx(
snapshot.isDragging && 'z-[9000] bg-gray-200'
)}
item={item}
2022-09-17 23:30:27 +00:00
user={user}
/>
</div>
)}
</Draggable>
))}
{provided.placeholder}
</Col>
)}
</Droppable>
)
}
const SectionItem = (props: {
2022-09-17 23:30:27 +00:00
item: { id: string; label: string; group?: Group }
user: User | null | undefined
className?: string
}) => {
2022-09-17 23:30:27 +00:00
const { item, user, className } = props
const { group } = item
return (
2022-09-17 23:30:27 +00:00
<Row
className={clsx(
className,
2022-09-17 23:30:27 +00:00
'items-center justify-between gap-4 rounded bg-gray-50 p-2'
)}
>
2022-09-17 23:30:27 +00:00
<Row className="items-center gap-4">
<MenuIcon
className="h-5 w-5 flex-shrink-0 text-gray-500"
aria-hidden="true"
/>{' '}
{item.label}
</Row>
{group && (
<Button
2022-09-17 23:52:13 +00:00
className="pt-1 pb-1"
2022-09-17 23:30:27 +00:00
color="gray-white"
onClick={() => {
if (user) {
const homeSections = (user.homeSections ?? []).filter(
(id) => id !== group.id
)
updateUser(user.id, { homeSections })
toast.promise(leaveGroup(group, user.id), {
loading: 'Unfollowing group...',
success: `Unfollowed ${group.name}`,
error: "Couldn't unfollow group, try again?",
})
}
}}
>
<XCircleIcon
className={clsx('h-5 w-5 flex-shrink-0')}
aria-hidden="true"
/>
</Button>
)}
</Row>
)
}