Chore: change misleading query name

This commit is contained in:
csrapr 2021-02-17 17:51:36 +00:00 committed by Josh Harvey
parent b89ba7d939
commit 2401238b2f
5 changed files with 45 additions and 28 deletions

View file

@ -327,7 +327,7 @@ const typeDefs = gql`
insertBlacklistRow(cryptoCode: String!, address: String!): Blacklist insertBlacklistRow(cryptoCode: String!, address: String!): Blacklist
createPromoCode(code: String!, discount: Int!): PromoCode createPromoCode(code: String!, discount: Int!): PromoCode
deletePromoCode(codeId: ID!): PromoCode deletePromoCode(codeId: ID!): PromoCode
clearNotification(id: ID!): Notification toggleClearNotification(id: ID!, read: Boolean!): Notification
clearAllNotifications: Notification clearAllNotifications: Notification
} }
` `
@ -418,7 +418,7 @@ const resolvers = {
// revokeToken: (...[, { token }]) => tokenManager.revokeToken(token) // revokeToken: (...[, { token }]) => tokenManager.revokeToken(token)
createPromoCode: (...[, { code, discount }]) => promoCodeManager.createPromoCode(code, discount), createPromoCode: (...[, { code, discount }]) => promoCodeManager.createPromoCode(code, discount),
deletePromoCode: (...[, { codeId }]) => promoCodeManager.deletePromoCode(codeId), deletePromoCode: (...[, { codeId }]) => promoCodeManager.deletePromoCode(codeId),
clearNotification: (...[, { id }]) => notifierQueries.markAsRead(id), toggleClearNotification: (...[, { id, read }]) => notifierQueries.setRead(id, read),
clearAllNotifications: () => notifierQueries.markAllAsRead() clearAllNotifications: () => notifierQueries.markAllAsRead()
} }
} }

View file

@ -56,10 +56,9 @@ const getNotifications = () => {
const sql = `SELECT * FROM notifications ORDER BY created DESC` const sql = `SELECT * FROM notifications ORDER BY created DESC`
return db.any(sql).catch(console.error) return db.any(sql).catch(console.error)
} }
const setRead = (id, read) => {
const markAsRead = (id) => { const sql = `UPDATE notifications SET read = $1 WHERE id = $2`
const sql = `UPDATE notifications SET read = 't' WHERE id = $1` return db.none(sql, [read, id]).catch(console.error)
return db.none(sql, [id]).catch(console.error)
} }
const markAllAsRead = () => { const markAllAsRead = () => {
@ -87,7 +86,7 @@ module.exports = {
clearBlacklistNotification, clearBlacklistNotification,
getValidNotifications, getValidNotifications,
getNotifications, getNotifications,
markAsRead, setRead,
markAllAsRead, markAllAsRead,
hasUnreadNotifications, hasUnreadNotifications,
getAlerts, getAlerts,

View file

@ -35,10 +35,11 @@ const GET_NOTIFICATIONS = gql`
} }
` `
const CLEAR_NOTIFICATION = gql` const TOGGLE_CLEAR_NOTIFICATION = gql`
mutation clearNotification($id: ID!) { mutation toggleClearNotification($id: ID!, $read: Boolean!) {
clearNotification(id: $id) { toggleClearNotification(id: $id, read: $read) {
id id
read
} }
} }
` `
@ -67,7 +68,7 @@ const NotificationCenter = ({ close, notifyUnread }) => {
if (!hasUnread) { if (!hasUnread) {
notifyUnread && notifyUnread() notifyUnread && notifyUnread()
} }
const [clearNotification] = useMutation(CLEAR_NOTIFICATION, { const [toggleClearNotification] = useMutation(TOGGLE_CLEAR_NOTIFICATION, {
onError: () => console.error('Error while clearing notification'), onError: () => console.error('Error while clearing notification'),
refetchQueries: () => ['getNotifications'] refetchQueries: () => ['getNotifications']
}) })
@ -76,9 +77,6 @@ const NotificationCenter = ({ close, notifyUnread }) => {
refetchQueries: () => ['getNotifications'] refetchQueries: () => ['getNotifications']
}) })
const handleClearNotification = id => {
clearNotification({ variables: { id } })
}
const buildNotifications = () => { const buildNotifications = () => {
const notificationsToShow = const notificationsToShow =
!showingUnread || !hasUnread !showingUnread || !hasUnread
@ -96,7 +94,11 @@ const NotificationCenter = ({ close, notifyUnread }) => {
created={n.created} created={n.created}
read={n.read} read={n.read}
valid={n.valid} valid={n.valid}
onClear={handleClearNotification} toggleClear={() =>
toggleClearNotification({
variables: { id: n.id, read: !n.read }
})
}
/> />
) )
}) })
@ -123,14 +125,16 @@ const NotificationCenter = ({ close, notifyUnread }) => {
{showingUnread ? 'Show all' : 'Show unread'} {showingUnread ? 'Show all' : 'Show unread'}
</ActionButton> </ActionButton>
)} )}
<ActionButton {hasUnread && (
color="primary" <ActionButton
Icon={ClearAllIcon} color="primary"
InverseIcon={ClearAllIconInverse} Icon={ClearAllIcon}
className={classes.clearAllButton} InverseIcon={ClearAllIconInverse}
onClick={clearAllNotifications}> className={classes.clearAllButton}
Mark all as read onClick={clearAllNotifications}>
</ActionButton> Mark all as read
</ActionButton>
)}
</div> </div>
<div className={classes.notificationsList}> <div className={classes.notificationsList}>
{!loading && buildNotifications()} {!loading && buildNotifications()}

View file

@ -34,7 +34,8 @@ const styles = {
}, },
actionButtons: { actionButtons: {
display: 'flex', display: 'flex',
marginLeft: spacer * 2 marginLeft: spacer * 2,
height: 0
}, },
notificationIcon: { notificationIcon: {
position: 'absolute', position: 'absolute',
@ -56,7 +57,7 @@ const styles = {
width: 440, width: 440,
height: '90vh', height: '90vh',
maxHeight: '100vh', maxHeight: '100vh',
marginTop: 8, marginTop: spacer * 3,
marginLeft: 0, marginLeft: 0,
marginRight: 10, marginRight: 10,
overflowY: 'auto', overflowY: 'auto',
@ -80,6 +81,7 @@ const styles = {
}, },
unreadIcon: { unreadIcon: {
marginLeft: spacer, marginLeft: spacer,
marginTop: 5,
width: '12px', width: '12px',
height: '12px', height: '12px',
backgroundColor: secondaryColor, backgroundColor: secondaryColor,
@ -87,6 +89,16 @@ const styles = {
cursor: 'pointer', cursor: 'pointer',
zIndex: 1 zIndex: 1
}, },
readIcon: {
marginLeft: spacer,
marginTop: 5,
width: '12px',
height: '12px',
border: `1px solid ${comet}`,
borderRadius: '50%',
cursor: 'pointer',
zIndex: 1
},
notificationTitle: { notificationTitle: {
margin: 0, margin: 0,
color: comet color: comet

View file

@ -32,7 +32,7 @@ const NotificationRow = ({
created, created,
read, read,
valid, valid,
onClear toggleClear
}) => { }) => {
const classes = useStyles() const classes = useStyles()
@ -73,8 +73,10 @@ const NotificationRow = ({
</Grid> </Grid>
</Grid> </Grid>
<Grid item xs={3} style={{ zIndex: 1 }}> <Grid item xs={3} style={{ zIndex: 1 }}>
{!read && ( {read ? (
<div onClick={() => onClear(id)} className={classes.unreadIcon} /> <div onClick={() => toggleClear(id)} className={classes.readIcon} />
) : (
<div onClick={() => toggleClear(id)} className={classes.unreadIcon} />
)} )}
</Grid> </Grid>
{!valid && <StripesSvg className={classes.stripes} />} {!valid && <StripesSvg className={classes.stripes} />}