Skip to content

Commit

Permalink
enhance: slimmer query, satsummary notification links to full satistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Soxasora committed Dec 23, 2024
1 parent 5d12a90 commit 6e4e4ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
16 changes: 7 additions & 9 deletions api/resolvers/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,13 @@ export default {

if (meFull.noteSatSummary) {
queries.push(
`(SELECT CONCAT('stats_', date_trunc('day', t))::text as id,
t AS "sortTime",
NULL as "earnedSats",
'SatSummary' AS type
`(SELECT 'stats_' || date_trunc('day', t)::text as id,
t AS "sortTime", NULL as "earnedSats", 'SatSummary' AS type
FROM user_stats_days
WHERE "user_stats_days"."id" = $1
WHERE id = $1
AND t >= date_trunc('day', CURRENT_DATE - INTERVAL '1 day')
AND t <= $2
GROUP BY t, msats_stacked, msats_spent
GROUP BY t
ORDER BY "sortTime" DESC
LIMIT ${LIMIT})`
)
Expand Down Expand Up @@ -505,14 +503,14 @@ export default {
},
SatSummary: {
date: async (n, args, { models }) => {
return new Date(n.id.replace('stats_', ''))
return new Date(n.sortTime)
},
stacked: async (n, args, { me, models }) => { // msats_rewards is already counted in msats_stacked
const [{ stacked }] = await models.$queryRaw`
SELECT sum(msats_stacked) as stacked
FROM user_stats_days
WHERE id = ${Number(me.id)}
AND t = ${new Date(n.id.replace('stats_', ''))}::timestamp
AND t = ${n.sortTime}::timestamp
`
return (stacked && msatsToSats(stacked)) || 0
},
Expand All @@ -521,7 +519,7 @@ export default {
SELECT sum(msats_spent) as spent
FROM user_stats_days
WHERE id = ${Number(me.id)}
AND t = ${new Date(n.id.replace('stats_', ''))}::timestamp
AND t = ${n.sortTime}::timestamp
`
return (spent && msatsToSats(spent)) || 0
}
Expand Down
9 changes: 4 additions & 5 deletions components/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import HandCoin from '@/svgs/hand-coin-fill.svg'
import UserAdd from '@/svgs/user-add-fill.svg'
import { LOST_BLURBS, FOUND_BLURBS, UNKNOWN_LINK_REL } from '@/lib/constants'
import CowboyHatIcon from '@/svgs/cowboy.svg'
import JusticeIcon from '@/svgs/scales-of-justice.svg' // WIP
import ScalesIcon from '@/svgs/scales-of-justice.svg'
import BaldIcon from '@/svgs/bald.svg'
import GunIcon from '@/svgs/revolver.svg'
import HorseIcon from '@/svgs/horse.svg'
Expand Down Expand Up @@ -164,7 +164,7 @@ const defaultOnClick = n => {
if (type === 'Referral') return { href: '/referrals/month' }
if (type === 'ReferralReward') return { href: '/referrals/month' }
if (type === 'Streak') return {}
if (type === 'SatSummary') return {}
if (type === 'SatSummary') return { href: '/satistics?inc=stacked,spent' }
if (type === 'TerritoryTransfer') return { href: `/~${n.sub.name}` }

if (!n.item) return {}
Expand Down Expand Up @@ -203,11 +203,10 @@ function Streak ({ n }) {
)
}

function SatSummary ({ n }) { // WIP
// stacked and spent
function SatSummary ({ n }) {
return (
<div className='d-flex'>
<div style={{ fontSize: '2rem' }}><JusticeIcon className='fill-grey' fill='gray' height={40} width={40} /></div>
<div style={{ fontSize: '2rem' }}><ScalesIcon className='fill-grey' fill='gray' height={40} width={40} /></div>
<div className='ms-1 p-1'>
<span className='fw-bold'>you stacked {numWithUnits(n.stacked, { abbreviate: false })} and spent {numWithUnits(n.spent, { abbreviate: false })}</span>
<div><small style={{ lineHeight: '140%', display: 'inline-block' }}>on {dayMonthYear(new Date(n.date))}</small></div>
Expand Down

0 comments on commit 6e4e4ff

Please sign in to comment.