stacker.news/components/dont-link-this.js

111 lines
2.9 KiB
JavaScript
Raw Normal View History

2023-07-24 18:35:05 +00:00
import Dropdown from 'react-bootstrap/Dropdown'
import { useShowModal } from './modal'
import { useToast } from './toast'
2023-09-14 02:08:03 +00:00
import ItemAct from './item-act'
2023-12-20 00:15:08 +00:00
import AccordianItem from './accordian-item'
import Flag from '../svgs/flag-fill.svg'
import { useMemo } from 'react'
import getColor from '../lib/rainbow'
import { gql, useMutation } from '@apollo/client'
import { useMe } from './me'
2022-09-21 19:57:36 +00:00
export function DownZap ({ id, meDontLikeSats, ...props }) {
const style = useMemo(() => (meDontLikeSats
? {
fill: getColor(meDontLikeSats),
filter: `drop-shadow(0 0 6px ${getColor(meDontLikeSats)}90)`
}
: undefined), [meDontLikeSats])
return (
<DownZapper id={id} As={({ ...oprops }) => <Flag {...props} {...oprops} style={style} />} />
)
}
function DownZapper ({ id, As, children }) {
const toaster = useToast()
const showModal = useShowModal()
const me = useMe()
2022-09-21 19:57:36 +00:00
return (
<As
onClick={async () => {
try {
2023-09-14 02:08:03 +00:00
showModal(onClose =>
<ItemAct
onClose={() => {
onClose()
// undo prompt was toasted before closing modal if zap undos are enabled
// so an additional success toast would be confusing
const zapUndosEnabled = me && me?.privates?.zapUndos
if (!zapUndosEnabled) toaster.success('item downzapped')
2023-12-27 02:27:52 +00:00
}} itemId={id} down
2023-12-20 00:15:08 +00:00
>
<AccordianItem
header='what is a downzap?' body={
<ul>
<li>downzaps are just like zaps but cause items to lose ranking position</li>
<li>downzaps also reduce trust between you and whoever zaps it so you'll see less of what they zap in the future</li>
<li>all sats from downzaps go to rewards</li>
</ul>
}
/>
</ItemAct>)
} catch (error) {
2023-12-20 00:15:08 +00:00
toaster.danger('failed to downzap item')
}
}}
>
{children}
</As>
)
}
export default function DontLikeThisDropdownItem ({ id }) {
return (
<DownZapper
As={Dropdown.Item}
id={id}
>
2023-12-20 00:15:08 +00:00
<span className='text-danger'>downzap</span>
</DownZapper>
2022-09-21 19:57:36 +00:00
)
}
export function OutlawDropdownItem ({ item }) {
const toaster = useToast()
const [toggleOutlaw] = useMutation(
gql`
mutation toggleOutlaw($id: ID!) {
toggleOutlaw(id: $id) {
outlawed
}
}`, {
update (cache, { data: { toggleOutlaw } }) {
cache.modify({
id: `Item:${item.id}`,
fields: {
outlawed: () => true
}
})
}
}
)
return (
<Dropdown.Item onClick={async () => {
try {
await toggleOutlaw({ variables: { id: item.id } })
} catch {
toaster.danger('failed to outlaw')
return
}
toaster.success('item outlawed')
}}
>
outlaw
</Dropdown.Item>
)
}