Skip to content

Commit

Permalink
🚸 Update pull-to-refresh logic for following SL feed
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt committed Aug 8, 2020
1 parent cf634e8 commit f4e0623
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 56 deletions.
75 changes: 27 additions & 48 deletions app/components/content-list/content-list.super-like.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,28 @@
import * as React from "react"
import {
ListRenderItem,
RefreshControl,
SectionListStatic,
View,
} from "react-native"
import {
FlatList,
SectionList as SectionListBase,
} from 'react-navigation'
import { ListRenderItem, RefreshControl, SectionListStatic, View } from "react-native"
import { FlatList, SectionList as SectionListBase } from "react-navigation"
import { observer } from "mobx-react"
import { SwipeRow } from "react-native-swipe-list-view"

import {
SuperLikedContentListProps as Props,
} from "./content-list.props"
import {
ContentListStyle as Style,
RefreshControlColors,
} from "./content-list.style"

import {
ContentListItemSkeleton,
SuperLikeContentListItem,
} from "../content-list-item"
import { SuperLikedContentListProps as Props } from "./content-list.props"
import { ContentListStyle as Style, RefreshControlColors } from "./content-list.style"

import { ContentListItemSkeleton, SuperLikeContentListItem } from "../content-list-item"
import { wrapScrollViewShadow } from "../wrap-scrollview-shadow"
import { Text } from "../text"

import {
SuperLikedContent,
} from "../../models/super-liked-content"
import { SuperLikedContent } from "../../models/super-liked-content"

const ContentSectionList: SectionListStatic<SuperLikedContent> = SectionListBase

@observer
class SuperLikeContentListBase extends React.Component<Props> {
listItemRefs = {} as { [key: string]: React.RefObject<SwipeRow<{}>> }

private keyExtractor = (content: SuperLikedContent) =>
`${this.props.lastFetched}${content.id}`
private keyExtractor = (content: SuperLikedContent) => `${this.props.lastFetched}${content.id}`

private onEndReach = () => {
if (
this.props.onFetchMore &&
this.props.hasFetched &&
!this.props.hasFetchedAll
) {
if (this.props.onFetchMore && this.props.hasFetched && !this.props.hasFetchedAll) {
this.props.onFetchMore()
}
}
Expand Down Expand Up @@ -116,23 +93,25 @@ class SuperLikeContentListBase extends React.Component<Props> {
)
}

private renderHeader = () => this.props.titleLabelTx ? (
<Text
tx={this.props.titleLabelTx}
color="likeGreen"
align="center"
weight="600"
style={Style.Header}
/>
) : null
private renderHeader = () =>
this.props.titleLabelTx ? (
<Text
tx={this.props.titleLabelTx}
color="likeGreen"
align="center"
weight="600"
style={Style.Header}
/>
) : null

private renderRefreshControl = () => (
<RefreshControl
colors={RefreshControlColors}
refreshing={this.props.hasFetched && this.props.isLoading}
onRefresh={this.props.onRefresh}
/>
)
private renderRefreshControl = () =>
this.props.onRefresh ? (
<RefreshControl
colors={RefreshControlColors}
refreshing={this.props.hasFetched && this.props.isLoading}
onRefresh={this.props.onRefresh}
/>
) : null

private renderContent: ListRenderItem<SuperLikedContent> = ({ item: content }) => (
<SuperLikeContentListItem
Expand Down
2 changes: 1 addition & 1 deletion app/models/reader-store/reader-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export const ReaderStoreModel = types

const superLikedContents: SuperLikedContent[] = []
for (let i = 0; i < result.data.length; i++) {
const data = result.data[i];
const data = result.data[i]
const superLikedContent = self.parseSuperLikeFeedItemToModel(data)

const timestamp = Math.min(superLikedContent.timestamp, Date.now())
Expand Down
7 changes: 0 additions & 7 deletions app/screens/reader-screen/reader-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ class ReaderScreenBase extends React.Component<Props> {
}
}

private onRefreshSuperLikeFeed = () => {
if (this.state.activePageIndex === 0) {
this.props.readerStore.fetchFollowedSuperLikedFeed()
}
}

render() {
if (this.props.currentUser.isSuperLiker) {
return this.renderSuperLikeScreen()
Expand Down Expand Up @@ -254,7 +248,6 @@ class ReaderScreenBase extends React.Component<Props> {
onPressItem={this.props.onPressSuperLikeItem}
onToggleBookmark={this.props.onToggleBookmark}
onToggleFollow={this.props.onToggleFollow}
onRefresh={this.onRefreshSuperLikeFeed}
style={Style.SuperLikeFeed}
/>
)
Expand Down

0 comments on commit f4e0623

Please sign in to comment.