Give explicit names to MobX observer components (#1413)
* Consider observer(...) as components * Add display names to MobX observers * Temporarily suppress nested components * Suppress new false positives for react/prop-types
This commit is contained in:
parent
69209c988f
commit
8a93321fb1
72 changed files with 2868 additions and 2836 deletions
|
@ -40,7 +40,7 @@ import {NavigationProp, CommonNavigatorParams} from 'lib/routes/types'
|
|||
import {router} from '../../../routes'
|
||||
import {makeProfileLink} from 'lib/routes/links'
|
||||
|
||||
const ProfileCard = observer(() => {
|
||||
const ProfileCard = observer(function ProfileCardImpl() {
|
||||
const store = useStores()
|
||||
const {isDesktop} = useWebMediaQueries()
|
||||
const size = isDesktop ? 64 : 48
|
||||
|
@ -103,78 +103,82 @@ interface NavItemProps {
|
|||
iconFilled: JSX.Element
|
||||
label: string
|
||||
}
|
||||
const NavItem = observer(
|
||||
({count, href, icon, iconFilled, label}: NavItemProps) => {
|
||||
const pal = usePalette('default')
|
||||
const store = useStores()
|
||||
const {isDesktop, isTablet} = useWebMediaQueries()
|
||||
const [pathName] = React.useMemo(() => router.matchPath(href), [href])
|
||||
const currentRouteInfo = useNavigationState(state => {
|
||||
if (!state) {
|
||||
return {name: 'Home'}
|
||||
const NavItem = observer(function NavItemImpl({
|
||||
count,
|
||||
href,
|
||||
icon,
|
||||
iconFilled,
|
||||
label,
|
||||
}: NavItemProps) {
|
||||
const pal = usePalette('default')
|
||||
const store = useStores()
|
||||
const {isDesktop, isTablet} = useWebMediaQueries()
|
||||
const [pathName] = React.useMemo(() => router.matchPath(href), [href])
|
||||
const currentRouteInfo = useNavigationState(state => {
|
||||
if (!state) {
|
||||
return {name: 'Home'}
|
||||
}
|
||||
return getCurrentRoute(state)
|
||||
})
|
||||
let isCurrent =
|
||||
currentRouteInfo.name === 'Profile'
|
||||
? isTab(currentRouteInfo.name, pathName) &&
|
||||
(currentRouteInfo.params as CommonNavigatorParams['Profile']).name ===
|
||||
store.me.handle
|
||||
: isTab(currentRouteInfo.name, pathName)
|
||||
const {onPress} = useLinkProps({to: href})
|
||||
const onPressWrapped = React.useCallback(
|
||||
(e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
|
||||
if (e.ctrlKey || e.metaKey || e.altKey) {
|
||||
return
|
||||
}
|
||||
return getCurrentRoute(state)
|
||||
})
|
||||
let isCurrent =
|
||||
currentRouteInfo.name === 'Profile'
|
||||
? isTab(currentRouteInfo.name, pathName) &&
|
||||
(currentRouteInfo.params as CommonNavigatorParams['Profile']).name ===
|
||||
store.me.handle
|
||||
: isTab(currentRouteInfo.name, pathName)
|
||||
const {onPress} = useLinkProps({to: href})
|
||||
const onPressWrapped = React.useCallback(
|
||||
(e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
|
||||
if (e.ctrlKey || e.metaKey || e.altKey) {
|
||||
return
|
||||
}
|
||||
e.preventDefault()
|
||||
if (isCurrent) {
|
||||
store.emitScreenSoftReset()
|
||||
} else {
|
||||
onPress()
|
||||
}
|
||||
},
|
||||
[onPress, isCurrent, store],
|
||||
)
|
||||
e.preventDefault()
|
||||
if (isCurrent) {
|
||||
store.emitScreenSoftReset()
|
||||
} else {
|
||||
onPress()
|
||||
}
|
||||
},
|
||||
[onPress, isCurrent, store],
|
||||
)
|
||||
|
||||
return (
|
||||
<PressableWithHover
|
||||
style={styles.navItemWrapper}
|
||||
hoverStyle={pal.viewLight}
|
||||
// @ts-ignore the function signature differs on web -prf
|
||||
onPress={onPressWrapped}
|
||||
// @ts-ignore web only -prf
|
||||
href={href}
|
||||
dataSet={{noUnderline: 1}}
|
||||
accessibilityRole="tab"
|
||||
accessibilityLabel={label}
|
||||
accessibilityHint="">
|
||||
<View
|
||||
style={[
|
||||
styles.navItemIconWrapper,
|
||||
isTablet && styles.navItemIconWrapperTablet,
|
||||
]}>
|
||||
{isCurrent ? iconFilled : icon}
|
||||
{typeof count === 'string' && count ? (
|
||||
<Text
|
||||
type="button"
|
||||
style={[
|
||||
styles.navItemCount,
|
||||
isTablet && styles.navItemCountTablet,
|
||||
]}>
|
||||
{count}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
{isDesktop && (
|
||||
<Text type="title" style={[isCurrent ? s.bold : s.normal, pal.text]}>
|
||||
{label}
|
||||
return (
|
||||
<PressableWithHover
|
||||
style={styles.navItemWrapper}
|
||||
hoverStyle={pal.viewLight}
|
||||
// @ts-ignore the function signature differs on web -prf
|
||||
onPress={onPressWrapped}
|
||||
// @ts-ignore web only -prf
|
||||
href={href}
|
||||
dataSet={{noUnderline: 1}}
|
||||
accessibilityRole="tab"
|
||||
accessibilityLabel={label}
|
||||
accessibilityHint="">
|
||||
<View
|
||||
style={[
|
||||
styles.navItemIconWrapper,
|
||||
isTablet && styles.navItemIconWrapperTablet,
|
||||
]}>
|
||||
{isCurrent ? iconFilled : icon}
|
||||
{typeof count === 'string' && count ? (
|
||||
<Text
|
||||
type="button"
|
||||
style={[
|
||||
styles.navItemCount,
|
||||
isTablet && styles.navItemCountTablet,
|
||||
]}>
|
||||
{count}
|
||||
</Text>
|
||||
)}
|
||||
</PressableWithHover>
|
||||
)
|
||||
},
|
||||
)
|
||||
) : null}
|
||||
</View>
|
||||
{isDesktop && (
|
||||
<Text type="title" style={[isCurrent ? s.bold : s.normal, pal.text]}>
|
||||
{label}
|
||||
</Text>
|
||||
)}
|
||||
</PressableWithHover>
|
||||
)
|
||||
})
|
||||
|
||||
function ComposeBtn() {
|
||||
const store = useStores()
|
||||
|
|
|
@ -13,7 +13,7 @@ import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
|||
import {pluralize} from 'lib/strings/helpers'
|
||||
import {formatCount} from 'view/com/util/numeric/format'
|
||||
|
||||
export const DesktopRightNav = observer(function DesktopRightNav() {
|
||||
export const DesktopRightNav = observer(function DesktopRightNavImpl() {
|
||||
const store = useStores()
|
||||
const pal = usePalette('default')
|
||||
const palError = usePalette('error')
|
||||
|
@ -78,7 +78,7 @@ export const DesktopRightNav = observer(function DesktopRightNav() {
|
|||
)
|
||||
})
|
||||
|
||||
const InviteCodes = observer(() => {
|
||||
const InviteCodes = observer(function InviteCodesImpl() {
|
||||
const store = useStores()
|
||||
const pal = usePalette('default')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue