mute territories in overflow
This commit is contained in:
parent
9ab1d770eb
commit
0999004646
|
@ -125,7 +125,7 @@ async function itemQueryWithMeta ({ me, models, query, orderBy = '' }, ...args)
|
||||||
COALESCE("ItemAct"."meMsats", 0) as "meMsats",
|
COALESCE("ItemAct"."meMsats", 0) as "meMsats",
|
||||||
COALESCE("ItemAct"."meDontLikeMsats", 0) as "meDontLikeMsats", b."itemId" IS NOT NULL AS "meBookmark",
|
COALESCE("ItemAct"."meDontLikeMsats", 0) as "meDontLikeMsats", b."itemId" IS NOT NULL AS "meBookmark",
|
||||||
"ThreadSubscription"."itemId" IS NOT NULL AS "meSubscription", "ItemForward"."itemId" IS NOT NULL AS "meForward",
|
"ThreadSubscription"."itemId" IS NOT NULL AS "meSubscription", "ItemForward"."itemId" IS NOT NULL AS "meForward",
|
||||||
to_jsonb("Sub".*) as sub
|
to_jsonb("Sub".*) || jsonb_build_object('meMuteSub', "MuteSub"."userId" IS NOT NULL) as sub
|
||||||
FROM (
|
FROM (
|
||||||
${query}
|
${query}
|
||||||
) "Item"
|
) "Item"
|
||||||
|
@ -135,6 +135,7 @@ async function itemQueryWithMeta ({ me, models, query, orderBy = '' }, ...args)
|
||||||
LEFT JOIN "ThreadSubscription" ON "ThreadSubscription"."itemId" = "Item".id AND "ThreadSubscription"."userId" = ${me.id}
|
LEFT JOIN "ThreadSubscription" ON "ThreadSubscription"."itemId" = "Item".id AND "ThreadSubscription"."userId" = ${me.id}
|
||||||
LEFT JOIN "ItemForward" ON "ItemForward"."itemId" = "Item".id AND "ItemForward"."userId" = ${me.id}
|
LEFT JOIN "ItemForward" ON "ItemForward"."itemId" = "Item".id AND "ItemForward"."userId" = ${me.id}
|
||||||
LEFT JOIN "Sub" ON "Sub"."name" = "Item"."subName"
|
LEFT JOIN "Sub" ON "Sub"."name" = "Item"."subName"
|
||||||
|
LEFT JOIN "MuteSub" ON "Sub"."name" = "MuteSub"."subName" AND "MuteSub"."userId" = ${me.id}
|
||||||
LEFT JOIN LATERAL (
|
LEFT JOIN LATERAL (
|
||||||
SELECT "itemId", sum("ItemAct".msats) FILTER (WHERE act = 'FEE' OR act = 'TIP') AS "meMsats",
|
SELECT "itemId", sum("ItemAct".msats) FILTER (WHERE act = 'FEE' OR act = 'TIP') AS "meMsats",
|
||||||
sum("ItemAct".msats) FILTER (WHERE act = 'DONT_LIKE_THIS') AS "meDontLikeMsats"
|
sum("ItemAct".msats) FILTER (WHERE act = 'DONT_LIKE_THIS') AS "meDontLikeMsats"
|
||||||
|
@ -1034,17 +1035,14 @@ export default {
|
||||||
mine: async (item, args, { me, models }) => {
|
mine: async (item, args, { me, models }) => {
|
||||||
return me?.id === item.userId
|
return me?.id === item.userId
|
||||||
},
|
},
|
||||||
root: async (item, args, { models }) => {
|
root: async (item, args, { models, me }) => {
|
||||||
if (!item.rootId) {
|
if (!item.rootId) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (item.root) {
|
if (item.root) {
|
||||||
return item.root
|
return item.root
|
||||||
}
|
}
|
||||||
return await models.item.findUnique({
|
return await getItem(item, { id: item.rootId }, { me, models })
|
||||||
where: { id: item.rootId },
|
|
||||||
include: { sub: true }
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
parent: async (item, args, { models }) => {
|
parent: async (item, args, { models }) => {
|
||||||
if (!item.parentId) {
|
if (!item.parentId) {
|
||||||
|
|
|
@ -86,7 +86,7 @@ export default {
|
||||||
LEFT JOIN "MuteSub" ON "Sub".name = "MuteSub"."subName" AND "MuteSub"."userId" = ${me.id}::INTEGER
|
LEFT JOIN "MuteSub" ON "Sub".name = "MuteSub"."subName" AND "MuteSub"."userId" = ${me.id}::INTEGER
|
||||||
WHERE status <> 'STOPPED'
|
WHERE status <> 'STOPPED'
|
||||||
GROUP BY "Sub".name, "MuteSub"."userId"
|
GROUP BY "Sub".name, "MuteSub"."userId"
|
||||||
ORDER BY "MuteSub"."userId" NULLS FIRST, "Sub".name ASC
|
ORDER BY "Sub".name ASC
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ export default {
|
||||||
return await models.user.findUnique({ where: { id: sub.userId } })
|
return await models.user.findUnique({ where: { id: sub.userId } })
|
||||||
},
|
},
|
||||||
meMuteSub: async (sub, args, { models }) => {
|
meMuteSub: async (sub, args, { models }) => {
|
||||||
return sub.MuteSub?.length > 0
|
return sub.meMuteSub || sub.MuteSub?.length > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import ActionDropdown from './action-dropdown'
|
||||||
import MuteDropdownItem from './mute'
|
import MuteDropdownItem from './mute'
|
||||||
import { DropdownItemUpVote } from './upvote'
|
import { DropdownItemUpVote } from './upvote'
|
||||||
import { useRoot } from './root'
|
import { useRoot } from './root'
|
||||||
|
import { MuteSubDropdownItem } from './territory-header'
|
||||||
|
|
||||||
export default function ItemInfo ({
|
export default function ItemInfo ({
|
||||||
item, full, commentsText = 'comments',
|
item, full, commentsText = 'comments',
|
||||||
|
@ -168,6 +169,11 @@ export default function ItemInfo ({
|
||||||
<hr className='dropdown-divider' />
|
<hr className='dropdown-divider' />
|
||||||
<OutlawDropdownItem item={item} />
|
<OutlawDropdownItem item={item} />
|
||||||
</>}
|
</>}
|
||||||
|
{me && !item.mine && sub && Number(me.id) !== Number(sub.userId) &&
|
||||||
|
<>
|
||||||
|
<hr className='dropdown-divider' />
|
||||||
|
<MuteSubDropdownItem item={item} sub={sub} />
|
||||||
|
</>}
|
||||||
{me && !item.mine &&
|
{me && !item.mine &&
|
||||||
<>
|
<>
|
||||||
<hr className='dropdown-divider' />
|
<hr className='dropdown-divider' />
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Badge, Button, CardFooter } from 'react-bootstrap'
|
import { Badge, Button, CardFooter, Dropdown } from 'react-bootstrap'
|
||||||
import { AccordianCard } from './accordian-item'
|
import { AccordianCard } from './accordian-item'
|
||||||
import TerritoryPaymentDue, { TerritoryBillingLine } from './territory-payment-due'
|
import TerritoryPaymentDue, { TerritoryBillingLine } from './territory-payment-due'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
@ -24,7 +24,7 @@ export default function TerritoryHeader ({ sub }) {
|
||||||
cache.modify({
|
cache.modify({
|
||||||
id: `Sub:{"name":"${sub.name}"}`,
|
id: `Sub:{"name":"${sub.name}"}`,
|
||||||
fields: {
|
fields: {
|
||||||
meMuteSub: () => toggleMuteSub.meMuteSub
|
meMuteSub: () => toggleMuteSub
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -90,3 +90,39 @@ export default function TerritoryHeader ({ sub }) {
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function MuteSubDropdownItem ({ item, sub }) {
|
||||||
|
const toaster = useToast()
|
||||||
|
|
||||||
|
const [toggleMuteSub] = useMutation(
|
||||||
|
gql`
|
||||||
|
mutation toggleMuteSub($name: String!) {
|
||||||
|
toggleMuteSub(name: $name)
|
||||||
|
}`, {
|
||||||
|
update (cache, { data: { toggleMuteSub } }) {
|
||||||
|
console.log(sub, toggleMuteSub)
|
||||||
|
cache.modify({
|
||||||
|
id: `Sub:{"name":"${sub.name}"}`,
|
||||||
|
fields: {
|
||||||
|
meMuteSub: () => toggleMuteSub
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dropdown.Item
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
await toggleMuteSub({ variables: { name: sub.name } })
|
||||||
|
} catch {
|
||||||
|
toaster.danger(`failed to ${sub.meMuteSub ? 'join' : 'mute'} territory`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
toaster.success(`${sub.meMuteSub ? 'joined' : 'muted'} territory`)
|
||||||
|
}}
|
||||||
|
>{sub.meMuteSub ? 'unmute' : 'mute'} ~{sub.name}
|
||||||
|
</Dropdown.Item>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,12 @@ export const COMMENTS_ITEM_EXT_FIELDS = gql`
|
||||||
bounty
|
bounty
|
||||||
bountyPaidTo
|
bountyPaidTo
|
||||||
subName
|
subName
|
||||||
|
sub {
|
||||||
|
name
|
||||||
|
userId
|
||||||
|
moderated
|
||||||
|
meMuteSub
|
||||||
|
}
|
||||||
user {
|
user {
|
||||||
name
|
name
|
||||||
optional {
|
optional {
|
||||||
|
|
|
@ -21,6 +21,7 @@ export const ITEM_FIELDS = gql`
|
||||||
name
|
name
|
||||||
userId
|
userId
|
||||||
moderated
|
moderated
|
||||||
|
meMuteSub
|
||||||
}
|
}
|
||||||
otsHash
|
otsHash
|
||||||
position
|
position
|
||||||
|
@ -78,6 +79,7 @@ export const ITEM_FULL_FIELDS = gql`
|
||||||
name
|
name
|
||||||
userId
|
userId
|
||||||
moderated
|
moderated
|
||||||
|
meMuteSub
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
forwards {
|
forwards {
|
||||||
|
|
Loading…
Reference in New Issue