mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-23 16:36:37 +03:00
rendering pinned post up top in profile page
This commit is contained in:
parent
a0150f550c
commit
40ca621bfd
@ -41,14 +41,6 @@ const TabContent = ({
|
||||
const { username } = currentAccount;
|
||||
const userPinned = currentAccount.about?.profile?.pinned;
|
||||
|
||||
const feedQuery = useFeedQuery({
|
||||
feedUsername,
|
||||
filterKey,
|
||||
tag,
|
||||
cachePage: isInitialTab && isFeedScreen,
|
||||
enableFetchOnAppState: isFeedScreen,
|
||||
});
|
||||
const promotedPostsQuery = usePromotedPostsQuery();
|
||||
|
||||
// state
|
||||
const [sessionUser, setSessionUser] = useState(username);
|
||||
@ -61,6 +53,18 @@ const TabContent = ({
|
||||
const sessionUserRef = useRef(sessionUser);
|
||||
const postFetchTimerRef = useRef<any>(null);
|
||||
|
||||
|
||||
const feedQuery = useFeedQuery({
|
||||
feedUsername,
|
||||
filterKey,
|
||||
tag,
|
||||
cachePage: isInitialTab && isFeedScreen,
|
||||
enableFetchOnAppState: isFeedScreen,
|
||||
pinnedPermlink:curPinned
|
||||
|
||||
});
|
||||
const promotedPostsQuery = usePromotedPostsQuery();
|
||||
|
||||
// init state refs;
|
||||
sessionUserRef.current = sessionUser;
|
||||
|
||||
@ -98,9 +102,9 @@ const TabContent = ({
|
||||
useEffect(() => {
|
||||
console.log('curPinned change', userPinned);
|
||||
if (pageType === 'ownProfile' && userPinned !== curPinned) {
|
||||
setCurPinned(userPinned);
|
||||
_scrollToTop();
|
||||
feedQuery.refresh();
|
||||
setCurPinned(userPinned);
|
||||
}
|
||||
}, [userPinned]);
|
||||
|
||||
|
@ -10,6 +10,7 @@ import { getAccountPosts, getRankedPosts } from '../../hive/dhive';
|
||||
import { calculateTimeLeftForPostCheck } from '../../../components/tabbedPosts/services/tabbedPostsHelpers';
|
||||
import { getPromotedEntries } from '../../ecency/ecency';
|
||||
import filterNsfwPost from '../../../utils/filterNsfwPost';
|
||||
import { useGetPostQuery } from './postQueries';
|
||||
|
||||
const POSTS_FETCH_COUNT = 10;
|
||||
|
||||
@ -19,6 +20,7 @@ interface FeedQueryParams {
|
||||
tag?: string;
|
||||
cachePage?: boolean;
|
||||
enableFetchOnAppState?: boolean;
|
||||
pinnedPermlink?:string;
|
||||
}
|
||||
|
||||
export const useFeedQuery = ({
|
||||
@ -27,6 +29,7 @@ export const useFeedQuery = ({
|
||||
tag,
|
||||
cachePage,
|
||||
enableFetchOnAppState,
|
||||
pinnedPermlink
|
||||
}: FeedQueryParams) => {
|
||||
const postFetchTimerRef = useRef(null);
|
||||
const appState = useRef(AppState.currentState);
|
||||
@ -42,6 +45,8 @@ export const useFeedQuery = ({
|
||||
const nsfw = useAppSelector((state) => state.application.nsfw);
|
||||
const { mutes } = currentAccount;
|
||||
|
||||
const pinnedPostQuery = useGetPostQuery(feedUsername, pinnedPermlink);
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// side effects
|
||||
@ -179,7 +184,9 @@ export const useFeedQuery = ({
|
||||
setIsRefreshing(true);
|
||||
setPageKeys(['']);
|
||||
|
||||
pinnedPostQuery.refetch();
|
||||
await feedQueries[0].refetch();
|
||||
|
||||
setIsRefreshing(false);
|
||||
};
|
||||
|
||||
@ -197,7 +204,7 @@ export const useFeedQuery = ({
|
||||
|
||||
// schedules post fetch
|
||||
const _scheduleLatestPostsCheck = (firstPost?: any) => {
|
||||
if (!firstPost && feedQueries[0].data) {
|
||||
if (!firstPost && Array.isArray(feedQueries[0].data)) {
|
||||
[firstPost] = feedQueries[0].data;
|
||||
}
|
||||
|
||||
@ -252,7 +259,7 @@ export const useFeedQuery = ({
|
||||
setLatestPosts([]);
|
||||
};
|
||||
|
||||
const _data = unionBy(...feedQueries.map((query) => query.data), 'url');
|
||||
const _data = unionBy(pinnedPostQuery.data ? [pinnedPostQuery.data] : [], ...feedQueries.map((query) => query.data), 'url');
|
||||
const _filteredData = useMemo(
|
||||
() => _data.filter((post) => (isArray(mutes) ? mutes.indexOf(post?.author) < 0 : true)),
|
||||
[mutes, _data],
|
||||
|
Loading…
Reference in New Issue
Block a user