add muted section to territory select
This commit is contained in:
parent
214e863458
commit
f267137662
|
@ -79,19 +79,23 @@ export default {
|
|||
})
|
||||
},
|
||||
subs: async (parent, args, { models, me }) => {
|
||||
if (me) {
|
||||
return await models.$queryRaw`
|
||||
SELECT "Sub".*, COALESCE(json_agg("MuteSub".*) FILTER (WHERE "MuteSub"."userId" IS NOT NULL), '[]') AS "MuteSub"
|
||||
FROM "Sub"
|
||||
LEFT JOIN "MuteSub" ON "Sub".name = "MuteSub"."subName" AND "MuteSub"."userId" = ${me.id}::INTEGER
|
||||
WHERE status <> 'STOPPED'
|
||||
GROUP BY "Sub".name, "MuteSub"."userId"
|
||||
ORDER BY "MuteSub"."userId" NULLS FIRST, "Sub".name ASC
|
||||
`
|
||||
}
|
||||
|
||||
return await models.sub.findMany({
|
||||
where: {
|
||||
status: {
|
||||
not: 'STOPPED'
|
||||
}
|
||||
},
|
||||
include: {
|
||||
MuteSub: {
|
||||
where: {
|
||||
userId: Number(me.id)
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
name: 'asc'
|
||||
}
|
||||
|
@ -187,7 +191,7 @@ export default {
|
|||
return await models.user.findUnique({ where: { id: sub.userId } })
|
||||
},
|
||||
meMuteSub: async (sub, args, { models }) => {
|
||||
return sub.MuteSub.length > 0
|
||||
return sub.MuteSub?.length > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,15 @@ export function useSubs ({ prependSubs = [], sub, filterSubs = () => true, appen
|
|||
...appendSubs.filter(s => s !== sub)])
|
||||
useEffect(() => {
|
||||
if (!data) return
|
||||
setSubs([...prependSubs, ...data.subs.filter(filterSubs).map(s => s.name), ...appendSubs])
|
||||
console.log(data)
|
||||
const joined = data.subs.filter(filterSubs).filter(s => !s.meMuteSub).map(s => s.name)
|
||||
const muted = data.subs.filter(filterSubs).filter(s => s.meMuteSub).map(s => s.name)
|
||||
const mutedSection = muted.length ? [{ label: 'muted', items: muted }] : []
|
||||
setSubs([
|
||||
...prependSubs,
|
||||
...joined,
|
||||
...mutedSection,
|
||||
...appendSubs])
|
||||
}, [data])
|
||||
|
||||
return subs
|
||||
|
|
Loading…
Reference in New Issue