Skip to content

Commit

Permalink
- [帖子] 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
czy0729 committed Sep 1, 2024
1 parent 80c7e89 commit 616cfb2
Show file tree
Hide file tree
Showing 30 changed files with 261 additions and 296 deletions.
22 changes: 11 additions & 11 deletions src/components/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* @Author: czy0729
* @Date: 2019-03-15 06:17:18
* @Last Modified by: czy0729
* @Last Modified time: 2024-08-19 07:15:12
* @Last Modified time: 2024-09-01 10:10:32
*/
import React from 'react'
import { Image as RNImage } from 'react-native'
import { observer } from 'mobx-react'
import { _, systemStore } from '@stores'
import { getTimestamp, omit, pick } from '@utils'
import { r } from '@utils/dev'
import { EVENT, HOST_CDN_AVATAR, IOS, STORYBOOK } from '@constants'
import { EVENT, HOST_CDN_AVATAR, IOS, WEB } from '@constants'
import { IOS_IPA, TEXT_ONLY } from '@/config'
import { AnyObject, Fn } from '@types'
import { Component } from '../component'
Expand Down Expand Up @@ -63,8 +63,8 @@ export const Image = observer(
autoSize: 0,
border: false,
borderWidth: _.hairlineWidth,
cache: !STORYBOOK,
delay: !STORYBOOK,
cache: !WEB,
delay: !WEB,
event: EVENT,
imageViewer: false,
withoutFeedback: false,
Expand All @@ -77,7 +77,7 @@ export const Image = observer(
}

state: State = {
uri: STORYBOOK ? fixedRemoteImageUrl(this.props.src) : undefined,
uri: WEB ? fixedRemoteImageUrl(this.props.src) : undefined,
width: 0,
height: 0,
loaded: false,
Expand Down Expand Up @@ -111,7 +111,7 @@ export const Image = observer(
const { src } = this.props

// 不缓存图片
if (!this.props.cache || STORYBOOK) {
if (!this.props.cache || WEB) {
this.setState({
uri: fixedRemoteImageUrl(src)
})
Expand Down Expand Up @@ -146,7 +146,7 @@ export const Image = observer(
if (this.props.textOnly) return

if (nextProps.src !== this.props.src) {
if (STORYBOOK) {
if (WEB) {
this.setState({
uri: fixedRemoteImageUrl(nextProps.src)
})
Expand Down Expand Up @@ -515,11 +515,11 @@ export const Image = observer(
if (autoSize) {
image.push({
width: w || 160,
height: h || (STORYBOOK ? 'auto' : 160)
height: h || (WEB ? 'auto' : 160)
})
} else if (autoHeight) {
image.push({
width: w || (STORYBOOK ? 'auto' : 160),
width: w || (WEB ? 'auto' : 160),
height: h || 160
})
} else if (size) {
Expand Down Expand Up @@ -613,7 +613,7 @@ export const Image = observer(
if (this.props.errorToHide) return null

// 加载错误后显示显示图形
if (!STORYBOOK) {
if (!WEB) {
return (
<Error style={this.computedStyle.image} size={this.props.width || this.props.size} />
)
Expand Down Expand Up @@ -663,7 +663,7 @@ export const Image = observer(

// 获取图片的宽高中, 占位
if (
!(IOS || STORYBOOK) &&
!(IOS || WEB) &&
((autoSize && !this.state.width) || (autoHeight && !this.state.height))
) {
return <Placeholder style={this.computedStyle.image} />
Expand Down
15 changes: 4 additions & 11 deletions src/components/image/skeleton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
* @Author: czy0729
* @Date: 2023-04-12 09:06:35
* @Last Modified by: czy0729
* @Last Modified time: 2024-06-13 19:25:28
* @Last Modified time: 2024-09-01 10:11:15
*/
import React, { useEffect, useRef, useState } from 'react'
import { useObserver } from 'mobx-react'
import { _, systemStore } from '@stores'
import { STORYBOOK } from '@constants'
import { WEB } from '@constants'
import { Skeleton as SkeletonComp } from '../../skeleton'

function Skeleton({ style, type, textOnly, placeholder, loaded }) {
const [show, setShow] = useState(true)
const timeoutRef = useRef(null)

useEffect(() => {
if (!systemStore.setting.imageSkeleton || STORYBOOK || textOnly || !placeholder || loaded) {
if (!systemStore.setting.imageSkeleton || WEB || textOnly || !placeholder || loaded) {
return
}

Expand All @@ -30,14 +30,7 @@ function Skeleton({ style, type, textOnly, placeholder, loaded }) {
}, [textOnly, placeholder, loaded])

return useObserver(() => {
if (
!systemStore.setting.imageSkeleton ||
STORYBOOK ||
textOnly ||
!placeholder ||
loaded ||
!show
) {
if (!systemStore.setting.imageSkeleton || WEB || textOnly || !placeholder || loaded || !show) {
return null
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/image/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* @Author: czy0729
* @Date: 2022-05-28 02:06:44
* @Last Modified by: czy0729
* @Last Modified time: 2024-08-19 07:18:43
* @Last Modified time: 2024-09-01 10:11:09
*/
import { _ } from '@stores'
import { getCover400, getStorage, setStorage, showImageViewer } from '@utils'
import { t } from '@utils/fetch'
import hash from '@utils/thirdParty/hash'
import ImageCacheManager from '@utils/thirdParty/image-cache-manager'
import { DEV, HOST_CDN, IOS, STORYBOOK } from '@constants'
import { DEV, HOST_CDN, IOS, WEB } from '@constants'
import {
CACHE_KEY_404,
CACHE_KEY_451,
Expand Down Expand Up @@ -214,7 +214,7 @@ export function getRecoveryBgmCover(src: any, width: number, height: number, siz
// 如果是触发回滚机制的图, 通常是游戏类的横屏图, 所以可以使用 height 去检查加大一个级别
const w = Math.max(width || 0, height || 0, size || 0)
let coverSize: 100 | 200 | 400 = 100
if (STORYBOOK) {
if (WEB) {
if (w > 200) {
coverSize = 400
} else if (w > 100) {
Expand Down
8 changes: 6 additions & 2 deletions src/components/render-html/a/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2022-05-13 05:12:53
* @Last Modified by: czy0729
* @Last Modified time: 2024-08-23 12:35:19
* @Last Modified time: 2024-09-01 10:30:09
*/
import React, { useEffect, useState } from 'react'
import { useObserver } from 'mobx-react'
Expand Down Expand Up @@ -63,7 +63,11 @@ function A({ style, attrs = {}, passProps, children, onPress, ...other }: Props)
selectable
underline={!WEB}
{...other}
onPress={() => onPress(null, href)}
onPress={() => {
setTimeout(() => {
onPress(null, href)
}, 80)
}}
>
{filterChildren(children)}
</Text>
Expand Down
6 changes: 3 additions & 3 deletions src/components/render-html/a/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* @Author: czy0729
* @Date: 2022-05-13 05:32:07
* @Last Modified by: czy0729
* @Last Modified time: 2024-05-16 16:35:56
* @Last Modified time: 2024-09-01 10:09:07
*/
import React from 'react'
import { View } from 'react-native'
import { _, rakuenStore, subjectStore } from '@stores'
import { getInt } from '@stores/rakuen/utils'
import { navigationReference, runAfter } from '@utils'
import { IOS } from '@constants'
import { IOS, WEB } from '@constants'
import { Fn, ReactNode } from '@types'
import { Cover } from '../../cover'
import { Flex } from '../../flex'
Expand All @@ -23,7 +23,7 @@ import { memoStyles } from './styles'

/** @todo 待优化, 安卓 Text 中一定要过滤非文字节点 */
export function filterChildren(children: ReactNode | ReactNode[]): ReactNode | ReactNode[] {
if (IOS) return children
if (IOS || WEB) return children

const childrens = React.Children.toArray(children)
const data = childrens.filter(
Expand Down
2 changes: 1 addition & 1 deletion src/components/render-html/toggle-image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2019-08-14 10:15:24
* @Last Modified by: czy0729
* @Last Modified time: 2024-07-31 13:29:37
* @Last Modified time: 2024-09-01 10:26:05
*/
import React from 'react'
import { View } from 'react-native'
Expand Down
6 changes: 3 additions & 3 deletions src/screens/_/item/post/icon-extra/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* @Author: czy0729
* @Date: 2021-01-20 12:15:22
* @Last Modified by: czy0729
* @Last Modified time: 2024-07-03 11:16:49
* @Last Modified time: 2024-09-01 09:33:48
*/
import React from 'react'
import { Flex, Iconfont } from '@components'
import { _, rakuenStore, uiStore } from '@stores'
import { _, rakuenStore, uiStore, userStore } from '@stores'
import {
confirm,
copy,
Expand Down Expand Up @@ -59,7 +59,7 @@ function IconExtra(
rakuenStore.setting.likes && likeType && ACTION_LIKES,

// 回复
replySub && !$?.isLimit && $?.showFixedTextarea && ACTION_REPLY,
replySub && !userStore.isLimit && $?.showFixedTextarea && ACTION_REPLY,

// 复制
ACTION_COPY,
Expand Down
4 changes: 2 additions & 2 deletions src/screens/_/item/post/sub/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2020-12-21 16:03:04
* @Last Modified by: czy0729
* @Last Modified time: 2024-01-23 19:16:31
* @Last Modified time: 2024-09-01 09:31:52
*/
import React from 'react'
import { rakuenStore } from '@stores'
Expand Down Expand Up @@ -53,7 +53,7 @@ export default obc(
avatar={avatar}
blockKeywords={blockKeywords}
erase={erase}
filterDelete={$?.filterDelete}
filterDelete={rakuenStore.setting.filterDelete}
floor={floor}
directFloor={$?.state?.directFloor === floor}
id={id}
Expand Down
6 changes: 3 additions & 3 deletions src/screens/rakuen/topic/component/bottom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* @Author: czy0729
* @Date: 2022-03-14 22:47:37
* @Last Modified by: czy0729
* @Last Modified time: 2024-04-07 09:33:33
* @Last Modified time: 2024-09-01 09:30:34
*/
import React from 'react'
import { FixedTextarea, Flex, SafeAreaBottom, Text } from '@components'
import { _ } from '@stores'
import { _, userStore } from '@stores'
import { appNavigate } from '@utils'
import { obc } from '@utils/decorators'
import { Ctx } from '../../types'
Expand All @@ -15,7 +15,7 @@ import { COMPONENT, MARKS } from './ds'
import { memoStyles } from './styles'

function Bottom({ fixedTextareaRef, onDirect }, { $, navigation }: Ctx) {
if (!$.isWebLogin || $.isLimit) return null
if (!userStore.isWebLogin || userStore.isLimit) return null

const styles = memoStyles()
const { tip = '' } = $.topic
Expand Down
4 changes: 2 additions & 2 deletions src/screens/rakuen/topic/component/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2020-03-19 00:38:46
* @Last Modified by: czy0729
* @Last Modified time: 2024-01-03 20:35:45
* @Last Modified time: 2024-09-01 09:34:47
*/
import React, { useCallback } from 'react'
import { appNavigate } from '@utils'
Expand All @@ -11,7 +11,7 @@ import { Ctx } from '../../types'
import Content from './content'
import { COMPONENT } from './ds'

function ContentWrap(props, { $, navigation }: Ctx) {
function ContentWrap(_props, { $, navigation }: Ctx) {
const onLinkPress = useCallback(
(href, passProps = {}) => {
appNavigate(href, navigation, passProps, {
Expand Down
4 changes: 2 additions & 2 deletions src/screens/rakuen/topic/component/ep/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2021-10-05 15:14:31
* @Last Modified by: czy0729
* @Last Modified time: 2024-01-03 20:42:28
* @Last Modified time: 2024-09-01 09:34:47
*/
import React from 'react'
import { Flex, Iconfont, Text, Touchable } from '@components'
Expand All @@ -14,7 +14,7 @@ import { Ctx } from '../../types'
import { COMPONENT } from './ds'
import { memoStyles } from './styles'

function Ep(props, { $, navigation }: Ctx) {
function Ep(_props, { $, navigation }: Ctx) {
if (!$.groupHref?.includes('/subject/')) return null

const subjectId = Number($.groupHref.replace('/subject/', ''))
Expand Down
4 changes: 2 additions & 2 deletions src/screens/rakuen/topic/component/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PaginationList2 } from '@_'
import { _ } from '@stores'
import { keyExtractor } from '@utils'
import { memo } from '@utils/decorators'
import { STORYBOOK } from '@constants'
import { WEB } from '@constants'
import Item from '../item'
import { COMPONENT_MAIN, DEFAULT_PROPS, LISTVIEW_PROPS } from './ds'

Expand Down Expand Up @@ -46,7 +46,7 @@ const List = memo(
} as const

const { list } = data
if (STORYBOOK || list.length <= 80) {
if (WEB || list.length <= 80) {
return <ListView {...passProps} ref={forwardRef} data={data} />
}

Expand Down
4 changes: 2 additions & 2 deletions src/screens/rakuen/topic/component/milestone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2022-01-11 10:11:54
* @Last Modified by: czy0729
* @Last Modified time: 2024-04-12 17:18:39
* @Last Modified time: 2024-09-01 09:34:52
*/
import React from 'react'
import { View } from 'react-native'
Expand All @@ -12,7 +12,7 @@ import { Ctx } from '../../types'
import { COMPONENT } from './ds'
import { memoStyles } from './styles'

function Milestone(props, { $ }: Ctx) {
function Milestone(_props, { $ }: Ctx) {
if ($.topicId !== 'group/366561') return null

const styles = memoStyles()
Expand Down
2 changes: 1 addition & 1 deletion src/screens/rakuen/topic/component/section-title/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Segment from '../segment'
import { COMPONENT } from './ds'
import { memoStyles } from './styles'

function SectionTitle(props, { $ }: Ctx) {
function SectionTitle(_props, { $ }: Ctx) {
const styles = memoStyles()
const { list = [] } = $.comments
let commentsCount = 0
Expand Down
8 changes: 4 additions & 4 deletions src/screens/rakuen/topic/component/segment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
* @Author: czy0729
* @Date: 2021-01-20 19:55:44
* @Last Modified by: czy0729
* @Last Modified time: 2024-07-03 16:22:29
* @Last Modified time: 2024-09-01 09:28:02
*/
import React from 'react'
import { View } from 'react-native'
import { Heatmap, SegmentedControl } from '@components'
import { _, rakuenStore } from '@stores'
import { _, rakuenStore, userStore } from '@stores'
import { feedback, info } from '@utils'
import { obc } from '@utils/decorators'
import { Ctx } from '../../types'
import { COMPONENT } from './ds'
import { styles } from './styles'

function Segement(props, { $ }: Ctx) {
function Segement(_props, { $ }: Ctx) {
const segmentedControlDS = ['全部']
if ($.state.filterPost) {
segmentedControlDS.push('跳转')
Expand All @@ -24,7 +24,7 @@ function Segement(props, { $ }: Ctx) {
if (likesCounts) segmentedControlDS.push(`贴贴 ${likesCounts}`)
}

const hasLogin = !!$.myId
const hasLogin = !!userStore.myId
if (hasLogin && $.commentMeCount) segmentedControlDS.push(`我 ${$.commentMeCount}`)
if (hasLogin && $.commentFriendsCount) segmentedControlDS.push(`好友 ${$.commentFriendsCount}`)
}
Expand Down
Loading

0 comments on commit 616cfb2

Please sign in to comment.