Merge pull request #101 from SlimusMinus/add-review_load
All checks were successful
deploy-frontend / deploy (push) Successful in 43s
All checks were successful
deploy-frontend / deploy (push) Successful in 43s
added review load
This commit is contained in:
@@ -16,8 +16,10 @@ export function useReviews({ isAuthenticated, onAuthRequired, authorFallbackName
|
|||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [submitError, setSubmitError] = useState("");
|
const [submitError, setSubmitError] = useState("");
|
||||||
|
|
||||||
const loadReviews = useCallback(async () => {
|
// silent — фоновое обновление (pull-to-refresh): список не подменяется
|
||||||
setLoading(true);
|
// спиннером, а при ошибке остаются уже показанные отзывы
|
||||||
|
const loadReviews = useCallback(async ({ silent = false } = {}) => {
|
||||||
|
if (!silent) setLoading(true);
|
||||||
setError("");
|
setError("");
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/api/v1/reviews`);
|
const res = await fetch(`${API_URL}/api/v1/reviews`);
|
||||||
@@ -27,7 +29,7 @@ export function useReviews({ isAuthenticated, onAuthRequired, authorFallbackName
|
|||||||
setReviews(list);
|
setReviews(list);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message || "Failed to load reviews");
|
setError(err.message || "Failed to load reviews");
|
||||||
setReviews([]);
|
if (!silent) setReviews([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useMemo, useRef } from "react";
|
import { useState, useEffect, useMemo, useRef, useCallback } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { getImageUrl } from "../config/authConstants";
|
import { getImageUrl } from "../config/authConstants";
|
||||||
import { useAuthContext } from "../context/AuthContext";
|
import { useAuthContext } from "../context/AuthContext";
|
||||||
@@ -10,6 +10,7 @@ import RulesModal from "./RulesModal";
|
|||||||
import ReviewCard from "../components/reviews/ReviewCard";
|
import ReviewCard from "../components/reviews/ReviewCard";
|
||||||
import ReviewForm from "../components/reviews/ReviewForm";
|
import ReviewForm from "../components/reviews/ReviewForm";
|
||||||
import RatingSummary from "../components/reviews/RatingSummary";
|
import RatingSummary from "../components/reviews/RatingSummary";
|
||||||
|
import PullToRefresh from "../components/feed/PullToRefresh";
|
||||||
import { useReviews } from "../hooks/useReviews";
|
import { useReviews } from "../hooks/useReviews";
|
||||||
import "../styles/reviews.css";
|
import "../styles/reviews.css";
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@@ -52,6 +53,11 @@ export default function ReviewsPage() {
|
|||||||
|
|
||||||
useEffect(() => { loadReviews(); }, [loadReviews]);
|
useEffect(() => { loadReviews(); }, [loadReviews]);
|
||||||
|
|
||||||
|
// Pull-to-refresh: тянем страницу вниз, находясь в самом верху, — отзывы
|
||||||
|
// перезагружаются (как в ленте «Вещи»/«Питомцы»/«Мои объявления»)
|
||||||
|
const scrollRef = useRef(null);
|
||||||
|
const refreshReviews = useCallback(() => loadReviews({ silent: true }), [loadReviews]);
|
||||||
|
|
||||||
// При загрузке страницы подтягиваем свежие данные профиля (аватар и т.д.)
|
// При загрузке страницы подтягиваем свежие данные профиля (аватар и т.д.)
|
||||||
// с бэка, чтобы навигация отражала изменения с других устройств, а не кэш.
|
// с бэка, чтобы навигация отражала изменения с других устройств, а не кэш.
|
||||||
// Дергаем один раз на пользователя.
|
// Дергаем один раз на пользователя.
|
||||||
@@ -103,6 +109,8 @@ export default function ReviewsPage() {
|
|||||||
hideWordmark
|
hideWordmark
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<div className="rv-scroll" ref={scrollRef}>
|
||||||
|
<PullToRefresh containerRef={scrollRef} onRefresh={refreshReviews} disabled={loading} />
|
||||||
<div className="rv-layout">
|
<div className="rv-layout">
|
||||||
<div className="rv-sidebar">
|
<div className="rv-sidebar">
|
||||||
<RatingSummary
|
<RatingSummary
|
||||||
@@ -148,6 +156,7 @@ export default function ReviewsPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{profileModalOpen && isAuthenticated && (
|
{profileModalOpen && isAuthenticated && (
|
||||||
<ProfileModal onClose={() => setProfileModalOpen(false)} initialData={profileData} />
|
<ProfileModal onClose={() => setProfileModalOpen(false)} initialData={profileData} />
|
||||||
|
|||||||
@@ -6,13 +6,22 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Скролл-контейнер страницы: первым элементом в нём живёт индикатор
|
||||||
|
pull-to-refresh, под ним — колонки .rv-layout */
|
||||||
|
.rv-scroll {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow-y: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
}
|
||||||
|
|
||||||
.rv-layout {
|
.rv-layout {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 24px;
|
gap: 24px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
flex: 1;
|
flex: 1 0 auto;
|
||||||
overflow-y: auto;
|
|
||||||
overscroll-behavior: contain;
|
|
||||||
max-width: 900px;
|
max-width: 900px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|||||||
Reference in New Issue
Block a user