fixed get profile avatar and get user from back
This commit is contained in:
@@ -27,6 +27,7 @@ import { useModals } from "../hooks/useModals";
|
||||
import { useFeedActions } from "../hooks/useFeedActions";
|
||||
import { useFavorites } from "../hooks/useFavorites";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useProfile } from "../hooks/useProfile";
|
||||
|
||||
/**
|
||||
* MainFeed — корневой компонент приложения.
|
||||
@@ -35,7 +36,8 @@ import { useTranslation } from 'react-i18next';
|
||||
export default function MainFeed() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { user, token, isAuthenticated } = useAuthContext();
|
||||
const { user, token, isAuthenticated, updateUser } = useAuthContext();
|
||||
const { fetchProfile } = useProfile();
|
||||
const { cities } = useCities();
|
||||
const { loadFavorites, loadFavoritePosts, error: favoritesError } = useFavorites();
|
||||
const { t } = useTranslation();
|
||||
@@ -49,6 +51,7 @@ export default function MainFeed() {
|
||||
const [liked, setLiked] = useState(new Set());
|
||||
const [likeCountAdj, setLikeCountAdj] = useState({});
|
||||
const [favoritePosts, setFavoritePosts] = useState([]);
|
||||
const profileFetchedFor = useRef(null);
|
||||
const [favoritesLoading, setFavoritesLoading] = useState(false);
|
||||
|
||||
const feedRef = useRef(null);
|
||||
@@ -125,6 +128,30 @@ export default function MainFeed() {
|
||||
}
|
||||
}, [location.state]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// При загрузке приложения подтягиваем свежие данные профиля (аватар и т.д.)
|
||||
// с бэка, чтобы нижняя навигация и профиль отражали изменения с других
|
||||
// устройств, а не устаревший кэш контекста. Дергаем один раз на пользователя.
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && user?.id && profileFetchedFor.current !== user.id) {
|
||||
profileFetchedFor.current = user.id;
|
||||
fetchProfile(user.id).then(result => {
|
||||
if (result.success) updateUser(result.data);
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isAuthenticated, user?.id]);
|
||||
|
||||
// При открытии профиля подтягиваем свежие данные (аватар/профиль) с бэка,
|
||||
// чтобы изменения с других устройств отражались, а не брались из кэша контекста
|
||||
useEffect(() => {
|
||||
if (modals.isOpen("profile") && isAuthenticated && user?.id) {
|
||||
fetchProfile(user.id).then(result => {
|
||||
if (result.success) updateUser(result.data);
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [modals.isOpen("profile"), isAuthenticated, user?.id]);
|
||||
|
||||
// Загрузка основной ленты (не в режиме поиска)
|
||||
useEffect(() => {
|
||||
if (!isSearchView && selectedCities.length === 0 && !searchQuery.trim()) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { useState, useEffect, useMemo, useRef } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { getImageUrl } from "../config/authConstants";
|
||||
import { useAuthContext } from "../context/AuthContext";
|
||||
@@ -13,16 +13,19 @@ import RatingSummary from "../components/reviews/RatingSummary";
|
||||
import { useReviews } from "../hooks/useReviews";
|
||||
import "../styles/reviews.css";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useProfile } from "../hooks/useProfile";
|
||||
|
||||
export default function ReviewsPage() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const { user, token, isAuthenticated } = useAuthContext();
|
||||
const { user, token, isAuthenticated, updateUser } = useAuthContext();
|
||||
const { fetchProfile } = useProfile();
|
||||
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||
const [profileModalOpen, setProfileModalOpen] = useState(false);
|
||||
const [authModalOpen, setAuthModalOpen] = useState(false);
|
||||
const [rulesModalOpen, setRulesModalOpen] = useState(false);
|
||||
const profileFetchedFor = useRef(null);
|
||||
|
||||
const profileData = useMemo(() => {
|
||||
if (!user) return {};
|
||||
@@ -50,6 +53,30 @@ export default function ReviewsPage() {
|
||||
|
||||
useEffect(() => { loadReviews(); }, [loadReviews]);
|
||||
|
||||
// При загрузке страницы подтягиваем свежие данные профиля (аватар и т.д.)
|
||||
// с бэка, чтобы навигация отражала изменения с других устройств, а не кэш.
|
||||
// Дергаем один раз на пользователя.
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && user?.id && profileFetchedFor.current !== user.id) {
|
||||
profileFetchedFor.current = user.id;
|
||||
fetchProfile(user.id).then(result => {
|
||||
if (result.success) updateUser(result.data);
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isAuthenticated, user?.id]);
|
||||
|
||||
// При открытии профиля подтягиваем свежие данные (аватар/профиль) с бэка,
|
||||
// чтобы изменения с других устройств отражались, а не брались из кэша контекста
|
||||
useEffect(() => {
|
||||
if (profileModalOpen && isAuthenticated && user?.id) {
|
||||
fetchProfile(user.id).then(result => {
|
||||
if (result.success) updateUser(result.data);
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [profileModalOpen, isAuthenticated, user?.id]);
|
||||
|
||||
return (
|
||||
<div className="f-app">
|
||||
<Sidebar
|
||||
|
||||
Reference in New Issue
Block a user