Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: list and assets translations #547

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 58 additions & 35 deletions src/containers/UserInformation/UserInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
MenuItemType,
UserInformationContainer as UserMenuComponent
} from 'decentraland-ui/dist/components/UserInformationContainer/UserInformationContainer'
import { DCLNotification, NotificationActiveTab, NotificationLocale } from 'decentraland-ui/dist/components/Notifications/types'
import {
DCLNotification,
NotificationActiveTab,
NotificationLocale
} from 'decentraland-ui/dist/components/Notifications/types'

import { getAnalytics } from '../../modules/analytics/utils'
import { t } from '../../modules/translation/utils'
Expand All @@ -15,9 +19,13 @@ import {
DROPDOWN_MENU_SIGN_IN_EVENT,
DROPDOWN_MENU_SIGN_OUT_EVENT
} from './constants'
import { NotificationsAPI, checkIsOnboarding, setOnboardingDone} from '../../modules/notifications'
import {
NotificationsAPI,
checkIsOnboarding,
setOnboardingDone
} from '../../modules/notifications'

const NOTIFICATIONS_QUERY_INTERVAL = 60000;
const NOTIFICATIONS_QUERY_INTERVAL = 60000

export const UserInformation = (props: UserInformationProps) => {
const analytics = getAnalytics()
Expand All @@ -33,14 +41,17 @@ export const UserInformation = (props: UserInformationProps) => {
...rest
} = props

const [{ isLoading, notifications }, setUserNotifications] = useState<{ isLoading: boolean, notifications: DCLNotification[] }>({
const [{ isLoading, notifications }, setUserNotifications] = useState<{
isLoading: boolean
notifications: DCLNotification[]
}>({
isLoading: false,
notifications: []
})
const [notificationsState, setNotificationsState] = useState({
activeTab: NotificationActiveTab.NEWEST,
isOnboarding: checkIsOnboarding(),
isOpen: false,
isOpen: false
})

let client: NotificationsAPI
Expand All @@ -59,8 +70,8 @@ export const UserInformation = (props: UserInformationProps) => {
settings: t('@dapps.user_menu.settings'),
wallet: t('@dapps.user_menu.wallet'),
profile: t('@dapps.user_menu.profile'),
myAssets: t('@dapps.user_menu.myAssets'),
myLists: t('@dapps.user_menu.myLists')
myAssets: t('@dapps.user_menu.my_assets'),
myLists: t('@dapps.user_menu.my_lists')
}
}, [hasTranslations])

Expand Down Expand Up @@ -129,41 +140,48 @@ export const UserInformation = (props: UserInformationProps) => {

const fetchNotificationsState = () => {
setUserNotifications({ notifications: [], isLoading: true })
client.getNotifications()
.then((retrievedNotifications) => {
setUserNotifications({ isLoading: false, notifications: retrievedNotifications })
client.getNotifications().then(retrievedNotifications => {
setUserNotifications({
isLoading: false,
notifications: retrievedNotifications
})
})
}

const handleNotificationsOpen = async () => {
const currentOpenState = notificationsState.isOpen
setNotificationsState((prevState) => {
return ({ ...prevState, isOpen: !prevState.isOpen})

setNotificationsState(prevState => {
return { ...prevState, isOpen: !prevState.isOpen }
})

if (!currentOpenState) {
const unreadNotifications = notifications.filter((notification) => !notification.read).map(({ id }) => id)
const unreadNotifications = notifications
.filter(notification => !notification.read)
.map(({ id }) => id)
if (unreadNotifications.length) {
await client.markNotificationsAsRead(unreadNotifications)
}
} else {
// update state when closes the modal
const markNotificationAsReadInState = notifications.map((notification) => {
const markNotificationAsReadInState = notifications.map(notification => {
if (notification.read) return notification
return ({

return {
...notification,
read: true
})
}
})
setUserNotifications({
isLoading,
notifications: markNotificationAsReadInState
})
setUserNotifications({ isLoading, notifications: markNotificationAsReadInState })
}
}

const handleOnBegin = () => {
setOnboardingDone()
setNotificationsState((prevState) => ({ ...prevState, isOnboarding: false }))
setNotificationsState(prevState => ({ ...prevState, isOnboarding: false }))
}

useEffect(() => {
Expand All @@ -173,7 +191,7 @@ export const UserInformation = (props: UserInformationProps) => {
const interval = setInterval(() => {
fetchNotificationsState()
}, NOTIFICATIONS_QUERY_INTERVAL)

return () => {
clearInterval(interval)
}
Expand All @@ -185,19 +203,24 @@ export const UserInformation = (props: UserInformationProps) => {
return (
<UserMenuComponent
notifications={
withNotifications ? {
locale: props.locale as NotificationLocale,
isLoading,
isOnboarding: notificationsState.isOnboarding,
isOpen: notificationsState.isOpen,
items: notifications,
activeTab: notificationsState.activeTab,
onClick: handleNotificationsOpen,
onClose: handleNotificationsOpen,
onBegin: handleOnBegin,
onChangeTab: (_, tab) => setNotificationsState((prevState) => ({ ...prevState, activeTab: tab }),)
}
: undefined
withNotifications
? {
locale: props.locale as NotificationLocale,
isLoading,
isOnboarding: notificationsState.isOnboarding,
isOpen: notificationsState.isOpen,
items: notifications,
activeTab: notificationsState.activeTab,
onClick: handleNotificationsOpen,
onClose: handleNotificationsOpen,
onBegin: handleOnBegin,
onChangeTab: (_, tab) =>
setNotificationsState(prevState => ({
...prevState,
activeTab: tab
}))
}
: undefined
}
onSignOut={handleSignOut}
onSignIn={handleSignIn}
Expand Down