mirror of
https://github.com/tooot-app/app
synced 2025-04-19 04:37:24 +02:00
More visually stable me page
This commit is contained in:
parent
7ac789c18c
commit
0c28ea6b0c
@ -2,18 +2,35 @@ import { MenuContainer, MenuRow } from '@components/Menu'
|
|||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import { useAnnouncementQuery } from '@utils/queryHooks/announcement'
|
import { useAnnouncementQuery } from '@utils/queryHooks/announcement'
|
||||||
import { useListsQuery } from '@utils/queryHooks/lists'
|
import { useListsQuery } from '@utils/queryHooks/lists'
|
||||||
import React from 'react'
|
import { getMePage, updateContextMePage } from '@utils/slices/contextsSlice'
|
||||||
|
import React, { useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
|
|
||||||
const Collections: React.FC = () => {
|
const Collections: React.FC = () => {
|
||||||
const { t } = useTranslation('screenTabs')
|
const { t } = useTranslation('screenTabs')
|
||||||
const navigation = useNavigation<any>()
|
const navigation = useNavigation<any>()
|
||||||
|
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
const mePage = useSelector(
|
||||||
|
getMePage,
|
||||||
|
(a, b) => a.announcements.unread === b.announcements.unread
|
||||||
|
)
|
||||||
|
|
||||||
const listsQuery = useListsQuery({
|
const listsQuery = useListsQuery({
|
||||||
options: {
|
options: {
|
||||||
notifyOnChangeProps: ['data']
|
notifyOnChangeProps: ['data']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
useEffect(() => {
|
||||||
|
if (listsQuery.isSuccess) {
|
||||||
|
dispatch(
|
||||||
|
updateContextMePage({
|
||||||
|
lists: { shown: listsQuery.data?.length ? true : false }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, [listsQuery.isSuccess, listsQuery.data?.length])
|
||||||
|
|
||||||
const announcementsQuery = useAnnouncementQuery({
|
const announcementsQuery = useAnnouncementQuery({
|
||||||
showAll: true,
|
showAll: true,
|
||||||
@ -21,6 +38,20 @@ const Collections: React.FC = () => {
|
|||||||
notifyOnChangeProps: ['data']
|
notifyOnChangeProps: ['data']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
useEffect(() => {
|
||||||
|
if (announcementsQuery.isSuccess) {
|
||||||
|
dispatch(
|
||||||
|
updateContextMePage({
|
||||||
|
announcements: {
|
||||||
|
shown: announcementsQuery.data?.length ? true : false,
|
||||||
|
unread: announcementsQuery.data.filter(
|
||||||
|
announcement => !announcement.read
|
||||||
|
).length
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, [announcementsQuery.isSuccess, announcementsQuery.data?.length])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuContainer>
|
<MenuContainer>
|
||||||
@ -42,7 +73,7 @@ const Collections: React.FC = () => {
|
|||||||
title={t('me.stacks.favourites.name')}
|
title={t('me.stacks.favourites.name')}
|
||||||
onPress={() => navigation.navigate('Tab-Me-Favourites')}
|
onPress={() => navigation.navigate('Tab-Me-Favourites')}
|
||||||
/>
|
/>
|
||||||
{listsQuery.data?.length ? (
|
{mePage.lists.shown ? (
|
||||||
<MenuRow
|
<MenuRow
|
||||||
iconFront='List'
|
iconFront='List'
|
||||||
iconBack='ChevronRight'
|
iconBack='ChevronRight'
|
||||||
@ -50,18 +81,15 @@ const Collections: React.FC = () => {
|
|||||||
onPress={() => navigation.navigate('Tab-Me-Lists')}
|
onPress={() => navigation.navigate('Tab-Me-Lists')}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{announcementsQuery.data?.length ? (
|
{mePage.announcements.shown ? (
|
||||||
<MenuRow
|
<MenuRow
|
||||||
iconFront='Clipboard'
|
iconFront='Clipboard'
|
||||||
iconBack='ChevronRight'
|
iconBack='ChevronRight'
|
||||||
title={t('screenAnnouncements:heading')}
|
title={t('screenAnnouncements:heading')}
|
||||||
content={
|
content={
|
||||||
announcementsQuery.data.filter(announcement => !announcement.read)
|
mePage.announcements.unread
|
||||||
.length
|
|
||||||
? t('me.root.announcements.content.unread', {
|
? t('me.root.announcements.content.unread', {
|
||||||
amount: announcementsQuery.data.filter(
|
amount: mePage.announcements.unread
|
||||||
announcement => !announcement.read
|
|
||||||
).length
|
|
||||||
})
|
})
|
||||||
: t('me.root.announcements.content.read')
|
: t('me.root.announcements.content.read')
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import createSecureStore from '@neverdull-agency/expo-unlimited-secure-store'
|
import createSecureStore from '@neverdull-agency/expo-unlimited-secure-store'
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||||
import { AnyAction, configureStore, Reducer } from '@reduxjs/toolkit'
|
import { AnyAction, configureStore, Reducer } from '@reduxjs/toolkit'
|
||||||
|
import contextsMigration from '@utils/migrations/contexts/migration'
|
||||||
import instancesMigration from '@utils/migrations/instances/migration'
|
import instancesMigration from '@utils/migrations/instances/migration'
|
||||||
import contextsSlice, { ContextsState } from '@utils/slices/contextsSlice'
|
import contextsSlice, { ContextsState } from '@utils/slices/contextsSlice'
|
||||||
import instancesSlice, { InstancesState } from '@utils/slices/instancesSlice'
|
import instancesSlice, { InstancesState } from '@utils/slices/instancesSlice'
|
||||||
@ -15,7 +16,10 @@ const prefix = 'tooot'
|
|||||||
const contextsPersistConfig = {
|
const contextsPersistConfig = {
|
||||||
key: 'contexts',
|
key: 'contexts',
|
||||||
prefix,
|
prefix,
|
||||||
storage: AsyncStorage
|
storage: AsyncStorage,
|
||||||
|
version: 1,
|
||||||
|
// @ts-ignore
|
||||||
|
migrate: createMigrate(contextsMigration)
|
||||||
}
|
}
|
||||||
|
|
||||||
const instancesPersistConfig = {
|
const instancesPersistConfig = {
|
||||||
|
16
src/utils/migrations/contexts/migration.ts
Normal file
16
src/utils/migrations/contexts/migration.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { ContextsV0 } from './v0'
|
||||||
|
|
||||||
|
const contextsMigration = {
|
||||||
|
1: (state: ContextsV0) => {
|
||||||
|
return (state = {
|
||||||
|
...state,
|
||||||
|
// @ts-ignore
|
||||||
|
mePage: {
|
||||||
|
lists: { shown: false },
|
||||||
|
announcements: { shown: false, unread: 0 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default contextsMigration
|
13
src/utils/migrations/contexts/v0.ts
Normal file
13
src/utils/migrations/contexts/v0.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
export type ContextsV0 = {
|
||||||
|
storeReview: {
|
||||||
|
context: Readonly<number>
|
||||||
|
current: number
|
||||||
|
shown: boolean
|
||||||
|
}
|
||||||
|
publicRemoteNotice: {
|
||||||
|
context: Readonly<number>
|
||||||
|
current: number
|
||||||
|
hidden: boolean
|
||||||
|
}
|
||||||
|
previousTab: 'Tab-Local' | 'Tab-Public' | 'Tab-Notifications' | 'Tab-Me'
|
||||||
|
}
|
@ -17,6 +17,10 @@ export type ContextsState = {
|
|||||||
hidden: boolean
|
hidden: boolean
|
||||||
}
|
}
|
||||||
previousTab: 'Tab-Local' | 'Tab-Public' | 'Tab-Notifications' | 'Tab-Me'
|
previousTab: 'Tab-Local' | 'Tab-Public' | 'Tab-Notifications' | 'Tab-Me'
|
||||||
|
mePage: {
|
||||||
|
lists: { shown: boolean }
|
||||||
|
announcements: { shown: boolean; unread: number }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const contextsInitialState = {
|
export const contextsInitialState = {
|
||||||
@ -32,7 +36,11 @@ export const contextsInitialState = {
|
|||||||
current: 0,
|
current: 0,
|
||||||
hidden: false
|
hidden: false
|
||||||
},
|
},
|
||||||
previousTab: 'Tab-Me'
|
previousTab: 'Tab-Me',
|
||||||
|
mePage: {
|
||||||
|
lists: { shown: false },
|
||||||
|
announcements: { shown: false, unread: 0 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextsSlice = createSlice({
|
const contextsSlice = createSlice({
|
||||||
@ -61,6 +69,12 @@ const contextsSlice = createSlice({
|
|||||||
action: PayloadAction<ContextsState['previousTab']>
|
action: PayloadAction<ContextsState['previousTab']>
|
||||||
) => {
|
) => {
|
||||||
state.previousTab = action.payload
|
state.previousTab = action.payload
|
||||||
|
},
|
||||||
|
updateContextMePage: (
|
||||||
|
state,
|
||||||
|
action: PayloadAction<Partial<ContextsState['mePage']>>
|
||||||
|
) => {
|
||||||
|
state.mePage = { ...state.mePage, ...action.payload }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -68,10 +82,13 @@ const contextsSlice = createSlice({
|
|||||||
export const getPublicRemoteNotice = (state: RootState) =>
|
export const getPublicRemoteNotice = (state: RootState) =>
|
||||||
state.contexts.publicRemoteNotice
|
state.contexts.publicRemoteNotice
|
||||||
export const getPreviousTab = (state: RootState) => state.contexts.previousTab
|
export const getPreviousTab = (state: RootState) => state.contexts.previousTab
|
||||||
|
export const getMePage = (state: RootState) => state.contexts.mePage
|
||||||
|
export const getContexts = (state: RootState) => state.contexts
|
||||||
|
|
||||||
export const {
|
export const {
|
||||||
updateStoreReview,
|
updateStoreReview,
|
||||||
updatePublicRemoteNotice,
|
updatePublicRemoteNotice,
|
||||||
updatePreviousTab
|
updatePreviousTab,
|
||||||
|
updateContextMePage
|
||||||
} = contextsSlice.actions
|
} = contextsSlice.actions
|
||||||
export default contextsSlice.reducer
|
export default contextsSlice.reducer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user