Merge pull request #2631 from ecency/nt/post-screen-spinners

Nt/post screen spinners
This commit is contained in:
Feruz M 2023-03-06 12:55:49 +02:00 committed by GitHub
commit 0e2c0c2966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 15 deletions

View File

@ -42,7 +42,7 @@ const PostComments = forwardRef(
permlink, permlink,
mainAuthor, mainAuthor,
postContentView, postContentView,
isLoading, isPostLoading,
onRefresh, onRefresh,
handleOnCommentsLoaded, handleOnCommentsLoaded,
handleOnReplyPress, handleOnReplyPress,
@ -67,7 +67,6 @@ const PostComments = forwardRef(
const [selectedFilter, setSelectedFilter] = useState('trending'); const [selectedFilter, setSelectedFilter] = useState('trending');
const [selectedOptionIndex, setSelectedOptionIndex] = useState(0); const [selectedOptionIndex, setSelectedOptionIndex] = useState(0);
const [shouldRenderComments, setShouldRenderComments] = useState(false);
const [headerHeight, setHeaderHeight] = useState(0); const [headerHeight, setHeaderHeight] = useState(0);
@ -84,7 +83,7 @@ const PostComments = forwardRef(
} }
}, },
scrollToComments: () => { scrollToComments: () => {
if (commentsListRef.current && (!sortedSections.length || !shouldRenderComments)) { if (commentsListRef.current && !sortedSections.length) {
commentsListRef.current.scrollToOffset({ offset: headerHeight + 200 }); commentsListRef.current.scrollToOffset({ offset: headerHeight + 200 });
} else if (commentsListRef.current && sortedSections.length) { } else if (commentsListRef.current && sortedSections.length) {
commentsListRef.current.scrollToIndex({ index: 0, viewOffset: 108 }); commentsListRef.current.scrollToIndex({ index: 0, viewOffset: 108 });
@ -233,10 +232,9 @@ const PostComments = forwardRef(
const _onContentSizeChange = (x: number, y: number) => { const _onContentSizeChange = (x: number, y: number) => {
// lazy render comments after post is rendered; // update header height
if (!shouldRenderComments) { if (y !== headerHeight) {
setHeaderHeight(y); setHeaderHeight(y);
setShouldRenderComments(true);
} }
}; };
@ -245,7 +243,7 @@ const PostComments = forwardRef(
const _postContentView = ( const _postContentView = (
<> <>
{postContentView && postContentView} {postContentView && postContentView}
{!isLoading && ( {!isPostLoading && (
<FilterBar <FilterBar
dropdownIconName="arrow-drop-down" dropdownIconName="arrow-drop-down"
options={VALUE.map((val) => intl.formatMessage({ id: `comment_filter.${val}` }))} options={VALUE.map((val) => intl.formatMessage({ id: `comment_filter.${val}` }))}
@ -260,6 +258,11 @@ const PostComments = forwardRef(
); );
const _renderEmptyContent = () => { const _renderEmptyContent = () => {
if(isPostLoading){
return null;
}
if (discussionQuery.isLoading || !!sortedSections.length) { if (discussionQuery.isLoading || !!sortedSections.length) {
return ( return (
<ActivityIndicator style={{ marginTop: 16 }} color={EStyleSheet.value('$primaryBlack')} /> <ActivityIndicator style={{ marginTop: 16 }} color={EStyleSheet.value('$primaryBlack')} />
@ -308,7 +311,7 @@ const PostComments = forwardRef(
contentContainerStyle={styles.listContent} contentContainerStyle={styles.listContent}
ListHeaderComponent={_postContentView} ListHeaderComponent={_postContentView}
ListEmptyComponent={_renderEmptyContent} ListEmptyComponent={_renderEmptyContent}
data={shouldRenderComments ? sortedSections : []} data={isPostLoading ? [] : sortedSections}
onContentSizeChange={_onContentSizeChange} onContentSizeChange={_onContentSizeChange}
renderItem={_renderItem} renderItem={_renderItem}
keyExtractor={(item) => `${item.author}/${item.permlink}`} keyExtractor={(item) => `${item.author}/${item.permlink}`}

View File

@ -1,12 +1,11 @@
import React, { Fragment, useState, useEffect, useRef } from 'react'; import React, { Fragment, useState, useEffect, useRef } from 'react';
import { Linking, Modal, PermissionsAndroid, Platform, View } from 'react-native'; import { Modal, PermissionsAndroid, Platform, View } from 'react-native';
import CameraRoll from '@react-native-community/cameraroll'; import CameraRoll from '@react-native-community/cameraroll';
import { useIntl, injectIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import EStyleSheet from 'react-native-extended-stylesheet'; import EStyleSheet from 'react-native-extended-stylesheet';
import ImageViewer from 'react-native-image-zoom-viewer'; import ImageViewer from 'react-native-image-zoom-viewer';
import RNFetchBlob from 'rn-fetch-blob'; import RNFetchBlob from 'rn-fetch-blob';
import ActionSheetView from 'react-native-actions-sheet'; import ActionSheetView from 'react-native-actions-sheet';
import { connect } from 'react-redux';
// Services and Actions // Services and Actions
import { useNavigation } from '@react-navigation/native'; import { useNavigation } from '@react-navigation/native';
@ -20,12 +19,14 @@ import { isCommunity } from '../../../../utils/communityValidation';
import { GLOBAL_POST_FILTERS_VALUE } from '../../../../constants/options/filters'; import { GLOBAL_POST_FILTERS_VALUE } from '../../../../constants/options/filters';
import { PostHtmlRenderer, VideoPlayer } from '../../..'; import { PostHtmlRenderer, VideoPlayer } from '../../..';
import getWindowDimensions from '../../../../utils/getWindowDimensions'; import getWindowDimensions from '../../../../utils/getWindowDimensions';
import { useAppDispatch } from '../../../../hooks';
const WIDTH = getWindowDimensions().width; const WIDTH = getWindowDimensions().width;
const PostBody = ({ body, dispatch, onLoadEnd, width }) => { const PostBody = ({ body, onLoadEnd, width }) => {
console.log('body : ', body); console.log('body : ', body);
const navigation = useNavigation(); const navigation = useNavigation();
const dispatch = useAppDispatch();
const [isImageModalOpen, setIsImageModalOpen] = useState(false); const [isImageModalOpen, setIsImageModalOpen] = useState(false);
@ -341,6 +342,5 @@ const areEqual = (prevProps, nextProps) => {
return false; return false;
}; };
const mapStateToProps = (state) => ({});
export default React.memo(injectIntl(connect(mapStateToProps)(PostBody)), areEqual); export default React.memo(PostBody, areEqual);

View File

@ -303,7 +303,7 @@ const PostDisplayView = ({
handleOnReplyPress={_showQuickReplyModal} handleOnReplyPress={_showQuickReplyModal}
handleOnCommentsLoaded={_handleOnCommentsLoaded} handleOnCommentsLoaded={_handleOnCommentsLoaded}
fetchedAt={post?.post_fetched_at} fetchedAt={post?.post_fetched_at}
isLoading={postBodyLoading} isPostLoading={postBodyLoading}
postContentView={_postContentView} postContentView={_postContentView}
onRefresh={onRefresh} onRefresh={onRefresh}
onUpvotePress={_onUpvotePress} onUpvotePress={_onUpvotePress}