From a6cbb6b759168187aebd68d8cf38291669f5368d Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Fri, 15 Jul 2022 11:53:30 -0600 Subject: [PATCH] Small notifications ux improvements --- common/user.ts | 3 ++ functions/src/create-user.ts | 6 ++- web/pages/notifications.tsx | 74 ++++++++++++++++++++---------------- 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/common/user.ts b/common/user.ts index 2960bda0..6eed3bdb 100644 --- a/common/user.ts +++ b/common/user.ts @@ -69,3 +69,6 @@ export type PortfolioMetrics = { timestamp: number userId: string } + +export const MANIFOLD_USERNAME = 'ManifoldMarkets' +export const MANIFOLD_AVATAR_URL = 'https://manifold.markets/logo-bg-white.png' diff --git a/functions/src/create-user.ts b/functions/src/create-user.ts index 332c1872..1fd23894 100644 --- a/functions/src/create-user.ts +++ b/functions/src/create-user.ts @@ -1,6 +1,8 @@ import * as admin from 'firebase-admin' import { z } from 'zod' import { + MANIFOLD_AVATAR_URL, + MANIFOLD_USERNAME, PrivateUser, STARTING_BALANCE, SUS_STARTING_BALANCE, @@ -160,8 +162,8 @@ const addUserToDefaultGroups = async (user: User) => { text: `Welcome, ${user.name} (@${user.username})!`, createdTime: Date.now(), userName: 'Manifold Markets', - userUsername: 'ManifoldMarkets', - userAvatarUrl: 'https://manifold.markets/logo-bg-white.png', + userUsername: MANIFOLD_USERNAME, + userAvatarUrl: MANIFOLD_AVATAR_URL, }) } } diff --git a/web/pages/notifications.tsx b/web/pages/notifications.tsx index f86c4fef..94c18d64 100644 --- a/web/pages/notifications.tsx +++ b/web/pages/notifications.tsx @@ -9,7 +9,12 @@ import { Title } from 'web/components/title' import { doc, updateDoc } from 'firebase/firestore' import { db } from 'web/lib/firebase/init' import { UserLink } from 'web/components/user-page' -import { notification_subscribe_types, PrivateUser } from 'common/user' +import { + MANIFOLD_AVATAR_URL, + MANIFOLD_USERNAME, + notification_subscribe_types, + PrivateUser, +} from 'common/user' import { ChoicesToggleGroup } from 'web/components/choices-toggle-group' import { listenForPrivateUser, updatePrivateUser } from 'web/lib/firebase/users' import { LoadingIndicator } from 'web/components/loading-indicator' @@ -37,6 +42,7 @@ import Custom404 from 'web/pages/404' import { track } from '@amplitude/analytics-browser' import { Pagination } from 'web/components/pagination' import { useWindowSize } from 'web/hooks/use-window-size' +import Router from 'next/router' export const NOTIFICATIONS_PER_PAGE = 30 const MULTIPLE_USERS_KEY = 'multipleUsers' @@ -550,6 +556,8 @@ function NotificationItem(props: { setNotificationsAsSeen([notification]) }, [notification]) + const questionNeedsResolution = sourceUpdateType == 'closed' + if (justSummary) { return ( @@ -565,7 +573,7 @@ function NotificationItem(props: { {sourceType && reason && - getReasonForShowingNotification(notification, true, true)} + getReasonForShowingNotification(notification, true)}
- +
{ + event.stopPropagation() + Router.push(getSourceUrl(notification) ?? '') track('Notification Clicked', { type: 'notification item', sourceType, @@ -602,14 +612,20 @@ function NotificationItem(props: { sourceUserUsername, sourceText, }) - } + }} >
) } @@ -769,17 +784,10 @@ function NotificationTextLabel(props: { justSummary?: boolean }) { const { className, notification, justSummary } = props - const { - sourceUpdateType, - sourceType, - sourceText, - sourceContractTitle, - reasonText, - } = notification + const { sourceUpdateType, sourceType, sourceText, reasonText } = notification const defaultText = sourceText ?? reasonText ?? '' if (sourceType === 'contract') { - if (justSummary) return {sourceContractTitle} - if (!sourceText) return
+ if (justSummary || !sourceText) return
// Resolved contracts if (sourceType === 'contract' && sourceUpdateType === 'resolved') { { @@ -857,27 +865,27 @@ function NotificationTextLabel(props: { function getReasonForShowingNotification( notification: Notification, - simple?: boolean, - replaceOn?: boolean + justSummary: boolean ) { const { sourceType, sourceUpdateType, reason, sourceSlug } = notification let reasonText: string switch (sourceType) { case 'comment': if (reason === 'reply_to_users_answer') - reasonText = !simple ? 'replied to you on' : 'replied' + reasonText = justSummary ? 'replied' : 'replied to you on' else if (reason === 'tagged_user') - reasonText = !simple ? 'tagged you on' : 'tagged you' + reasonText = justSummary ? 'tagged you' : 'tagged you on' else if (reason === 'reply_to_users_comment') - reasonText = !simple ? 'replied to you on' : 'replied' - else reasonText = `commented on` + reasonText = justSummary ? 'replied' : 'replied to you on' + else reasonText = justSummary ? `commented` : `commented on` break case 'contract': - if (reason === 'you_follow_user') reasonText = 'asked' - else if (sourceUpdateType === 'resolved') reasonText = `resolved` - else if (sourceUpdateType === 'closed') - reasonText = `Please resolve your question` - else reasonText = `updated` + if (reason === 'you_follow_user') + reasonText = justSummary ? 'asked the question' : 'asked' + else if (sourceUpdateType === 'resolved') + reasonText = justSummary ? `resolved the question` : `resolved` + else if (sourceUpdateType === 'closed') reasonText = `Please resolve` + else reasonText = justSummary ? 'updated the question' : `updated` break case 'answer': if (reason === 'on_users_contract') reasonText = `answered your question ` @@ -904,7 +912,7 @@ function getReasonForShowingNotification( default: reasonText = '' } - return replaceOn ? reasonText.replace(' on', '') : reasonText + return reasonText } // TODO: where should we put referral bonus notifications?