Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
lovetingyuan committed Jan 8, 2024
1 parent d133e91 commit e459e54
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/components/CheckAppUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default React.memo(function CheckAppUpdate() {
}
Alert.alert(
'有新版本',
`${appUpdateInfo.currentVersion}${appUpdateInfo.latestVersion}\n${appUpdateInfo.changelog}`,
`${appUpdateInfo.currentVersion}${appUpdateInfo.latestVersion}\n\n${appUpdateInfo.changelog}`,
[
{
text: '取消',
Expand Down
2 changes: 1 addition & 1 deletion src/routes/About/Version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default React.memo(function Version() {
if (data.hasUpdate) {
Alert.alert(
'有新版本',
`${data.currentVersion}${data.latestVersion} \n ${data.changelog}`,
`${data.currentVersion}${data.latestVersion}\n\n${data.changelog}`,
[
{
text: '取消',
Expand Down
6 changes: 3 additions & 3 deletions src/routes/Follow/AddFollow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import { useStore } from '../../store'

function SearchedItem(props: { up: SearchedUpType }) {
const up = props.up
const { $followedUps, set$followedUps } = useStore()
const followed = $followedUps.find(v => v.mid == up.mid)
const { _followedUpsMap, get$followedUps, set$followedUps } = useStore()
const followed = up.mid in _followedUpsMap
const user = {
name: up.name,
face: up.face,
mid: up.mid,
sign: up.sign,
}
const handler = () => {
set$followedUps([user, ...$followedUps])
set$followedUps([user, ...get$followedUps()])
}
const goToDynamic = () => {
Linking.openURL(`https://m.bilibili.com/space/${up.mid}`)
Expand Down
135 changes: 68 additions & 67 deletions src/routes/Follow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,82 +58,85 @@ const TvImg: React.FC = () => {
/>
)
}
function Follow() {
export default React.memo(function Follow() {
// eslint-disable-next-line no-console
__DEV__ && console.log('Follow page')
const { $followedUps, $upUpdateMap, livingUps } = useStore()
const followListRef = React.useRef<FlatList | null>(null)
const dark = useIsDark()

const { width } = useWindowDimensions()
const columns = Math.floor(width / 90)
const followedUpListLen = $followedUps.length
const rest = followedUpListLen
? columns - (followedUpListLen ? followedUpListLen % columns : 0)
: 0

let displayUps: (UpInfo | null)[] = []
const pinUps: UpInfo[] = []
const liveUps: UpInfo[] = []
const updateUps: UpInfo[] = []
const otherUps: UpInfo[] = []
const content = React.useMemo(() => {
const followedUpListLen = $followedUps.length
const rest = followedUpListLen
? columns - (followedUpListLen ? followedUpListLen % columns : 0)
: 0
const pinUps: UpInfo[] = []
const liveUps: UpInfo[] = []
const updateUps: UpInfo[] = []
const otherUps: UpInfo[] = []

for (const up of $followedUps) {
if (up.pin) {
pinUps.push({ ...up })
} else if (livingUps[up.mid]) {
liveUps.push({ ...up })
} else {
if (
up.mid in $upUpdateMap &&
$upUpdateMap[up.mid].latestId !== $upUpdateMap[up.mid].currentLatestId
) {
updateUps.push({ ...up })
for (const up of $followedUps) {
if (up.pin) {
pinUps.push({ ...up })
} else if (livingUps[up.mid]) {
liveUps.push({ ...up })
} else {
otherUps.push({ ...up })
if (
up.mid in $upUpdateMap &&
$upUpdateMap[up.mid].latestId !== $upUpdateMap[up.mid].currentLatestId
) {
updateUps.push({ ...up })
} else {
otherUps.push({ ...up })
}
}
}
}
displayUps = [
...pinUps.sort((a, b) => b.pin! - a.pin!),
...liveUps,
...updateUps,
...otherUps,
...(rest ? Array.from({ length: rest }).map(() => null) : []),
]
const content = (
<>
<View style={commonStyles.flex1}>
<FlatList
data={displayUps}
renderItem={renderItem}
keyExtractor={(item, index) => (item ? item.mid + '' : index + '')}
onEndReachedThreshold={1}
persistentScrollbar
key={columns} // FlatList不支持直接更改columns
numColumns={columns}
ref={followListRef}
columnWrapperStyle={{
paddingHorizontal: 10,
}}
contentContainerStyle={{
paddingTop: 30,
}}
ListEmptyComponent={
<View>
<TvImg />
<Text style={styles.emptyText}>暂无关注,请添加</Text>
</View>
}
ListFooterComponent={
$followedUps.length ? (
<Text style={styles.bottomText}>到底了~</Text>
) : null
}
/>
</View>
<AddFollow />
</>
)
const displayUps = [
...pinUps.sort((a, b) => b.pin! - a.pin!),
...liveUps,
...updateUps,
...otherUps,
...(rest ? Array.from({ length: rest }).map(() => null) : []),
]
return (
<>
<View style={commonStyles.flex1}>
<FlatList
data={displayUps}
renderItem={renderItem}
keyExtractor={(item, index) => (item ? item.mid + '' : index + '')}
onEndReachedThreshold={1}
persistentScrollbar
key={columns} // FlatList不支持直接更改columns
numColumns={columns}
ref={followListRef}
columnWrapperStyle={{
paddingHorizontal: 10,
}}
contentContainerStyle={{
paddingTop: 30,
}}
ListEmptyComponent={
<View>
<TvImg />
<Text style={styles.emptyText}>暂无关注,请添加</Text>
</View>
}
ListFooterComponent={
$followedUps.length ? (
<Text style={styles.bottomText}>到底了~</Text>
) : null
}
/>
</View>
<AddFollow />
</>
)
}, [$followedUps, $upUpdateMap, livingUps, columns])

return (
<View style={styles.container}>
{dark ? (
Expand All @@ -148,9 +151,7 @@ function Follow() {
)}
</View>
)
}

export default React.memo(Follow)
})

const styles = StyleSheet.create({
container: {
Expand Down

0 comments on commit e459e54

Please sign in to comment.