rendering pinned post up top in profile page

This commit is contained in:
noumantahir 2024-08-29 17:20:59 +05:00
parent a0150f550c
commit 40ca621bfd
2 changed files with 22 additions and 11 deletions

View File

@ -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]);

View File

@ -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],