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