mirror of
https://github.com/tooot-app/app
synced 2025-04-19 04:37:24 +02:00
Refine querying followed tags
This commit is contained in:
parent
4cddbb9bad
commit
2a40043b2e
@ -4,15 +4,13 @@ import ParseEmojis from '@components/Parse/Emojis'
|
|||||||
import { useNavigation, useRoute } from '@react-navigation/native'
|
import { useNavigation, useRoute } from '@react-navigation/native'
|
||||||
import { StackNavigationProp } from '@react-navigation/stack'
|
import { StackNavigationProp } from '@react-navigation/stack'
|
||||||
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
||||||
import { useFollowedTagsQuery } from '@utils/queryHooks/tags'
|
import { useAccountStorage, useGlobalStorage } from '@utils/storage/actions'
|
||||||
import { useGlobalStorage } from '@utils/storage/actions'
|
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import layoutAnimation from '@utils/styles/layoutAnimation'
|
import layoutAnimation from '@utils/styles/layoutAnimation'
|
||||||
import { adaptiveScale } from '@utils/styles/scaling'
|
import { adaptiveScale } from '@utils/styles/scaling'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import { ChildNode } from 'domhandler'
|
import { ChildNode } from 'domhandler'
|
||||||
import { ElementType, parseDocument } from 'htmlparser2'
|
import { ElementType, parseDocument } from 'htmlparser2'
|
||||||
import { isEqual } from 'lodash'
|
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { Pressable, Text, TextStyleIOS, View } from 'react-native'
|
import { Pressable, Text, TextStyleIOS, View } from 'react-native'
|
||||||
@ -72,7 +70,7 @@ const ParseHTML: React.FC<Props> = ({
|
|||||||
numberOfLines = 4
|
numberOfLines = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
const followedTags = useFollowedTagsQuery()
|
const [followedTags] = useAccountStorage.object('followed_tags')
|
||||||
|
|
||||||
const [totalLines, setTotalLines] = useState<number>()
|
const [totalLines, setTotalLines] = useState<number>()
|
||||||
const [expanded, setExpanded] = useState(highlighted)
|
const [expanded, setExpanded] = useState(highlighted)
|
||||||
@ -112,11 +110,11 @@ const ParseHTML: React.FC<Props> = ({
|
|||||||
const href = node.attribs.href
|
const href = node.attribs.href
|
||||||
if (classes) {
|
if (classes) {
|
||||||
if (classes.includes('hashtag')) {
|
if (classes.includes('hashtag')) {
|
||||||
const tag = href.match(new RegExp(/\/tags?\/(.*)/, 'i'))?.[1]
|
const tag = href.match(new RegExp(/\/tags?\/(.*)/, 'i'))?.[1].toLowerCase()
|
||||||
const paramsHashtag = (params as { hashtag: Mastodon.Tag['name'] } | undefined)
|
const paramsHashtag = (params as { hashtag: Mastodon.Tag['name'] } | undefined)
|
||||||
?.hashtag
|
?.hashtag
|
||||||
const sameHashtag = paramsHashtag === tag
|
const sameHashtag = paramsHashtag === tag
|
||||||
const isFollowing = followedTags.data?.pages[0]?.body.find(t => t.name === tag)
|
const isFollowing = followedTags?.find(t => t.name === tag)
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
key={index}
|
key={index}
|
||||||
|
@ -2,7 +2,6 @@ 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 { useFollowedTagsQuery } from '@utils/queryHooks/tags'
|
|
||||||
import { useAccountStorage } from '@utils/storage/actions'
|
import { useAccountStorage } from '@utils/storage/actions'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -13,12 +12,6 @@ const Collections: React.FC = () => {
|
|||||||
|
|
||||||
const [pageMe, setPageMe] = useAccountStorage.object('page_me')
|
const [pageMe, setPageMe] = useAccountStorage.object('page_me')
|
||||||
|
|
||||||
useFollowedTagsQuery({
|
|
||||||
options: {
|
|
||||||
onSuccess: data =>
|
|
||||||
setPageMe({ ...pageMe, followedTags: { shown: !!data?.pages?.[0].body?.length } })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
useListsQuery({
|
useListsQuery({
|
||||||
options: {
|
options: {
|
||||||
onSuccess: data => setPageMe({ ...pageMe, lists: { shown: !!data?.length } })
|
onSuccess: data => setPageMe({ ...pageMe, lists: { shown: !!data?.length } })
|
||||||
|
@ -18,6 +18,7 @@ import { useFiltersQuery } from '@utils/queryHooks/filters'
|
|||||||
import { useInstanceQuery } from '@utils/queryHooks/instance'
|
import { useInstanceQuery } from '@utils/queryHooks/instance'
|
||||||
import { usePreferencesQuery } from '@utils/queryHooks/preferences'
|
import { usePreferencesQuery } from '@utils/queryHooks/preferences'
|
||||||
import { useProfileQuery } from '@utils/queryHooks/profile'
|
import { useProfileQuery } from '@utils/queryHooks/profile'
|
||||||
|
import { useFollowedTagsQuery } from '@utils/queryHooks/tags'
|
||||||
import { setAccount, setGlobalStorage, useGlobalStorage } from '@utils/storage/actions'
|
import { setAccount, setGlobalStorage, useGlobalStorage } from '@utils/storage/actions'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import { themes } from '@utils/styles/themes'
|
import { themes } from '@utils/styles/themes'
|
||||||
@ -88,6 +89,7 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
|||||||
usePreferencesQuery({ options: { enabled: !!accountActive } })
|
usePreferencesQuery({ options: { enabled: !!accountActive } })
|
||||||
useFiltersQuery({ options: { enabled: !!accountActive } })
|
useFiltersQuery({ options: { enabled: !!accountActive } })
|
||||||
useEmojisQuery({ options: { enabled: !!accountActive } })
|
useEmojisQuery({ options: { enabled: !!accountActive } })
|
||||||
|
useFollowedTagsQuery({ options: { enabled: !!accountActive } })
|
||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
const navigationContainerOnStateChange = () => {
|
const navigationContainerOnStateChange = () => {
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
import { PagedResponse } from '@utils/api/helpers'
|
import { PagedResponse } from '@utils/api/helpers'
|
||||||
import apiInstance from '@utils/api/instance'
|
import apiInstance from '@utils/api/instance'
|
||||||
import { featureCheck } from '@utils/helpers/featureCheck'
|
import { featureCheck } from '@utils/helpers/featureCheck'
|
||||||
|
import { setAccountStorage } from '@utils/storage/actions'
|
||||||
import { AxiosError } from 'axios'
|
import { AxiosError } from 'axios'
|
||||||
import { infinitePageParams } from './utils'
|
import { infinitePageParams } from './utils'
|
||||||
|
|
||||||
@ -40,7 +41,21 @@ const useFollowedTagsQuery = (
|
|||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
cacheTime: Infinity,
|
cacheTime: Infinity,
|
||||||
...params?.options,
|
...params?.options,
|
||||||
...infinitePageParams
|
...infinitePageParams,
|
||||||
|
onSuccess: data => {
|
||||||
|
setAccountStorage([
|
||||||
|
{
|
||||||
|
key: 'followed_tags',
|
||||||
|
value: data.pages[0].body.map(tag => ({
|
||||||
|
name: tag.name.toLowerCase(),
|
||||||
|
following: tag.following
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
])
|
||||||
|
if (params?.options?.onSuccess) {
|
||||||
|
params.options.onSuccess(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ export type AccountV0 = {
|
|||||||
// boolean
|
// boolean
|
||||||
// object
|
// object
|
||||||
preferences?: Mastodon.Preferences
|
preferences?: Mastodon.Preferences
|
||||||
|
followed_tags?: Pick<Mastodon.Tag, 'name' | 'following'>[]
|
||||||
notifications: PushNotification
|
notifications: PushNotification
|
||||||
push: {
|
push: {
|
||||||
global: boolean
|
global: boolean
|
||||||
|
Loading…
x
Reference in New Issue
Block a user