From 17825cd611c3bbc47fe55b5e7dfe1a39fdca2274 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Wed, 16 Nov 2022 13:05:36 -0600 Subject: [PATCH] Add placeholder loading states --- src/view/com/notifications/Feed.tsx | 5 +- src/view/com/posts/Feed.tsx | 5 +- src/view/com/util/LoadingPlaceholder.tsx | 122 ++++++++++++++++++++++- src/view/com/util/PostCtrls.tsx | 2 +- src/view/screens/Profile.tsx | 3 +- 5 files changed, 128 insertions(+), 9 deletions(-) diff --git a/src/view/com/notifications/Feed.tsx b/src/view/com/notifications/Feed.tsx index ac56823f66..90d16604d8 100644 --- a/src/view/com/notifications/Feed.tsx +++ b/src/view/com/notifications/Feed.tsx @@ -1,11 +1,12 @@ import React from 'react' import {observer} from 'mobx-react-lite' -import {Text, View, FlatList} from 'react-native' +import {View, FlatList} from 'react-native' import { NotificationsViewModel, NotificationsViewItemModel, } from '../../../state/models/notifications-view' import {FeedItem} from './FeedItem' +import {NotificationFeedLoadingPlaceholder} from '../util/LoadingPlaceholder' import {ErrorMessage} from '../util/ErrorMessage' import {EmptyState} from '../util/EmptyState' @@ -32,7 +33,7 @@ export const Feed = observer(function Feed({ return ( {view.isLoading && !view.isRefreshing && !view.hasContent && ( - Loading... + )} {view.hasError && ( {feed.isLoading && !feed.isRefreshing && !feed.hasContent && ( - Loading... + )} {feed.hasError && ( ) } + +export function PostLoadingPlaceholder({ + style, +}: { + style?: StyleProp +}) { + return ( + + + + + + + + + + + + + + + + + + + + + + + + ) +} + +export function PostFeedLoadingPlaceholder() { + return ( + <> + + + + + + + + + + + + + ) +} + +export function NotificationLoadingPlaceholder({ + style, +}: { + style?: StyleProp +}) { + return ( + + + + + + + + ) +} + +export function NotificationFeedLoadingPlaceholder() { + return ( + <> + + + + + + + + + + + + + ) +} + +const styles = StyleSheet.create({ + post: { + flexDirection: 'row', + backgroundColor: colors.white, + borderRadius: 6, + padding: 10, + margin: 1, + }, + avatar: { + borderRadius: 25, + marginRight: 10, + }, + notification: { + backgroundColor: colors.white, + borderRadius: 6, + padding: 10, + paddingLeft: 46, + margin: 1, + }, + smallAvatar: { + borderRadius: 15, + marginRight: 10, + }, +}) diff --git a/src/view/com/util/PostCtrls.tsx b/src/view/com/util/PostCtrls.tsx index ab9e261cfa..5362228a96 100644 --- a/src/view/com/util/PostCtrls.tsx +++ b/src/view/com/util/PostCtrls.tsx @@ -77,7 +77,7 @@ export function PostCtrls(opts: PostCtrlsOpts) { icon={['far', 'comment']} size={14} /> - {opts.replyCount} + {opts.replyCount} diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index aed482bfbb..0edb503da0 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -12,6 +12,7 @@ import {ConfirmModel} from '../../state/models/shell-ui' import {ProfileHeader} from '../com/profile/ProfileHeader' import {FeedItem} from '../com/posts/FeedItem' import {ProfileCard} from '../com/profile/ProfileCard' +import {PostFeedLoadingPlaceholder} from '../com/util/LoadingPlaceholder' import {ErrorScreen} from '../com/util/ErrorScreen' import {ErrorMessage} from '../com/util/ErrorMessage' import {EmptyState} from '../com/util/EmptyState' @@ -106,7 +107,7 @@ export const Profile = observer(({visible, params}: ScreenParams) => { if (uiState) { if (uiState.isInitialLoading) { items.push(LOADING_ITEM) - renderItem = () => Loading... + renderItem = () => } else if (uiState.currentView.hasError) { items.push({ _reactKey: '__error__',