mirror of
https://github.com/tooot-app/app
synced 2025-02-20 13:50:49 +01:00
Clean up props
This commit is contained in:
parent
3c25f4b36a
commit
2bc6e3277c
@ -5,8 +5,8 @@ import TimelinesCombined from 'src/stacks/common/TimelinesCombined'
|
|||||||
export default function Local () {
|
export default function Local () {
|
||||||
return (
|
return (
|
||||||
<TimelinesCombined
|
<TimelinesCombined
|
||||||
page='Local'
|
name='Local'
|
||||||
route={[
|
content={[
|
||||||
{ title: '关注', timeline: { endpoint: 'home' } },
|
{ title: '关注', timeline: { endpoint: 'home' } },
|
||||||
{ title: '本站', timeline: { endpoint: 'public', local: true } }
|
{ title: '本站', timeline: { endpoint: 'public', local: true } }
|
||||||
]}
|
]}
|
||||||
|
@ -26,7 +26,9 @@ export default function Notifications () {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Stack.Screen name='Notifications'>
|
<Stack.Screen name='Notifications'>
|
||||||
{props => <Timeline endpoint='notifications' {...props} />}
|
{props => (
|
||||||
|
<Timeline timeline={{ endpoint: 'notifications' }} {...props} />
|
||||||
|
)}
|
||||||
</Stack.Screen>
|
</Stack.Screen>
|
||||||
</Stack.Navigator>
|
</Stack.Navigator>
|
||||||
)
|
)
|
||||||
|
@ -5,8 +5,8 @@ import TimelinesCombined from 'src/stacks/common/TimelinesCombined'
|
|||||||
export default function Public () {
|
export default function Public () {
|
||||||
return (
|
return (
|
||||||
<TimelinesCombined
|
<TimelinesCombined
|
||||||
page='Public'
|
name='Public'
|
||||||
route={[
|
content={[
|
||||||
{ title: '跨站', timeline: { endpoint: 'public' } },
|
{ title: '跨站', timeline: { endpoint: 'public' } },
|
||||||
{ title: '他站', timeline: { remote: true } }
|
{ title: '他站', timeline: { remote: true } }
|
||||||
]}
|
]}
|
||||||
|
@ -6,7 +6,7 @@ import { useSelector, useDispatch } from 'react-redux'
|
|||||||
import TootTimeline from 'src/components/TootTimeline'
|
import TootTimeline from 'src/components/TootTimeline'
|
||||||
import { fetch, getToots, getStatus } from './timelineSlice'
|
import { fetch, getToots, getStatus } from './timelineSlice'
|
||||||
|
|
||||||
const Default = ({ toots, status, remote, endpoint, local }) => {
|
const Default = ({ dispatch, toots, status, timeline }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FlatList
|
<FlatList
|
||||||
@ -14,15 +14,11 @@ const Default = ({ toots, status, remote, endpoint, local }) => {
|
|||||||
keyExtractor={({ id }) => id}
|
keyExtractor={({ id }) => id}
|
||||||
renderItem={TootTimeline}
|
renderItem={TootTimeline}
|
||||||
onRefresh={() =>
|
onRefresh={() =>
|
||||||
dispatch(
|
dispatch(fetch({ ...timeline, id: toots[0].id, newer: true }))
|
||||||
fetch({ remote, endpoint, local, id: toots[0].id, newer: true })
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
refreshing={status === 'loading'}
|
refreshing={status === 'loading'}
|
||||||
onEndReached={() =>
|
onEndReached={() =>
|
||||||
dispatch(
|
dispatch(fetch({ ...timeline, id: toots[toots.length - 1].id }))
|
||||||
fetch({ remote, endpoint, local, id: toots[toots.length - 1].id })
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
onEndReachedThreshold={0.5}
|
onEndReachedThreshold={0.5}
|
||||||
style={{ height: '100%', width: '100%' }}
|
style={{ height: '100%', width: '100%' }}
|
||||||
@ -32,7 +28,7 @@ const Default = ({ toots, status, remote, endpoint, local }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Notifications = ({ toots, status, endpoint }) => {
|
const Notifications = ({ dispatch, toots, status, timeline }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FlatList
|
<FlatList
|
||||||
@ -41,13 +37,15 @@ const Notifications = ({ toots, status, endpoint }) => {
|
|||||||
renderItem={({ item }) => (
|
renderItem={({ item }) => (
|
||||||
<TootTimeline item={item} notification={true} />
|
<TootTimeline item={item} notification={true} />
|
||||||
)}
|
)}
|
||||||
// onRefresh={() =>
|
onRefresh={() =>
|
||||||
// dispatch(fetch({ endpoint, id: toots[0].status.id, newer: true }))
|
dispatch(fetch({ ...timeline, id: toots[0].id, newer: true }))
|
||||||
// }
|
}
|
||||||
// refreshing={status === 'loading'}
|
refreshing={status === 'loading'}
|
||||||
// onEndReached={() =>
|
onEndReached={() =>
|
||||||
// dispatch(fetch({ endpoint, id: toots[toots.length - 1].status.id }))
|
dispatch(
|
||||||
// }
|
fetch({ ...timeline, id: toots[toots.length - 1].id })
|
||||||
|
)
|
||||||
|
}
|
||||||
onEndReachedThreshold={0.5}
|
onEndReachedThreshold={0.5}
|
||||||
style={{ height: '100%', width: '100%' }}
|
style={{ height: '100%', width: '100%' }}
|
||||||
/>
|
/>
|
||||||
@ -56,18 +54,14 @@ const Notifications = ({ toots, status, endpoint }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Timeline ({ remote, endpoint, local }) {
|
export default function Timeline ({ timeline }) {
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const toots = useSelector(state =>
|
const toots = useSelector(state => getToots(state)(timeline))
|
||||||
getToots(state)({ remote, endpoint, local })
|
const status = useSelector(state => getStatus(state)(timeline))
|
||||||
)
|
|
||||||
const status = useSelector(state =>
|
|
||||||
getStatus(state)({ remote, endpoint, local })
|
|
||||||
)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (status === 'idle') {
|
if (status === 'idle') {
|
||||||
dispatch(fetch({ remote, endpoint, local }))
|
dispatch(fetch(timeline))
|
||||||
}
|
}
|
||||||
}, [status, dispatch])
|
}, [status, dispatch])
|
||||||
|
|
||||||
@ -75,18 +69,22 @@ export default function Timeline ({ remote, endpoint, local }) {
|
|||||||
if (status === 'error') {
|
if (status === 'error') {
|
||||||
content = <Text>Error message</Text>
|
content = <Text>Error message</Text>
|
||||||
} else {
|
} else {
|
||||||
if (endpoint === 'notifications') {
|
if (timeline.endpoint === 'notifications') {
|
||||||
content = (
|
content = (
|
||||||
<Notifications toots={toots} status={status} endpoint={endpoint} />
|
<Notifications
|
||||||
|
dispatch={dispatch}
|
||||||
|
toots={toots}
|
||||||
|
status={status}
|
||||||
|
timeline={timeline}
|
||||||
|
/>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
content = (
|
content = (
|
||||||
<Default
|
<Default
|
||||||
|
dispatch={dispatch}
|
||||||
toots={toots}
|
toots={toots}
|
||||||
status={status}
|
status={status}
|
||||||
remote={remote}
|
timeline={timeline}
|
||||||
endpoint={endpoint}
|
|
||||||
local={local}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -96,7 +94,9 @@ export default function Timeline ({ remote, endpoint, local }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Timeline.propTypes = {
|
Timeline.propTypes = {
|
||||||
remote: PropTypes.bool,
|
timeline: PropTypes.exact({
|
||||||
endpoint: PropTypes.string,
|
remote: PropTypes.bool,
|
||||||
local: PropTypes.bool
|
endpoint: PropTypes.string,
|
||||||
|
local: PropTypes.bool
|
||||||
|
}).isRequired
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import Timeline from './Timeline'
|
|||||||
|
|
||||||
const Stack = createNativeStackNavigator()
|
const Stack = createNativeStackNavigator()
|
||||||
|
|
||||||
export default function TimelinesCombined ({ page, route }) {
|
export default function TimelinesCombined ({ name, content }) {
|
||||||
const [segment, setSegment] = useState(0)
|
const [segment, setSegment] = useState(0)
|
||||||
const [renderHeader, setRenderHeader] = useState(false)
|
const [renderHeader, setRenderHeader] = useState(false)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ export default function TimelinesCombined ({ page, route }) {
|
|||||||
headerCenter: () =>
|
headerCenter: () =>
|
||||||
renderHeader ? (
|
renderHeader ? (
|
||||||
<SegmentedControl
|
<SegmentedControl
|
||||||
values={[route[0].title, route[1].title]}
|
values={[content[0].title, content[1].title]}
|
||||||
selectedIndex={segment}
|
selectedIndex={segment}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
setSegment(e.nativeEvent.selectedSegmentIndex)
|
setSegment(e.nativeEvent.selectedSegmentIndex)
|
||||||
@ -48,7 +48,7 @@ export default function TimelinesCombined ({ page, route }) {
|
|||||||
) : null
|
) : null
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Stack.Screen name={page}>
|
<Stack.Screen name={name}>
|
||||||
{props => (
|
{props => (
|
||||||
<Animated.View
|
<Animated.View
|
||||||
style={{
|
style={{
|
||||||
@ -59,10 +59,10 @@ export default function TimelinesCombined ({ page, route }) {
|
|||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<View style={{ width: Dimensions.get('window').width }}>
|
<View style={{ width: Dimensions.get('window').width }}>
|
||||||
<Timeline {...route[0].timeline} />
|
<Timeline timeline={content[0].timeline} />
|
||||||
</View>
|
</View>
|
||||||
<View style={{ width: Dimensions.get('window').width }}>
|
<View style={{ width: Dimensions.get('window').width }}>
|
||||||
<Timeline {...route[1].timeline} />
|
<Timeline timeline={content[1].timeline} />
|
||||||
</View>
|
</View>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
)}
|
)}
|
||||||
@ -72,10 +72,11 @@ export default function TimelinesCombined ({ page, route }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TimelinesCombined.propTypes = {
|
TimelinesCombined.propTypes = {
|
||||||
route: PropTypes.arrayOf(
|
name: PropTypes.string.isRequired,
|
||||||
|
content: PropTypes.arrayOf(
|
||||||
PropTypes.exact({
|
PropTypes.exact({
|
||||||
title: PropTypes.string.isRequired,
|
title: PropTypes.string.isRequired,
|
||||||
timeline: PropTypes.exact(Timeline.propTypes).isRequired
|
timeline: Timeline.propTypes.timeline
|
||||||
})
|
})
|
||||||
).isRequired
|
).isRequired
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user