fixed desktop version
This commit is contained in:
191
src/components/desktop/DesktopChats.jsx
Normal file
191
src/components/desktop/DesktopChats.jsx
Normal file
@@ -0,0 +1,191 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Sidebar from "../Sidebar";
|
||||
import ChatListItem from "../chat/ChatListItem";
|
||||
import Toast from "../Toast";
|
||||
import AuthModal from "../AuthModal";
|
||||
import { ProfileModal } from "../profile";
|
||||
import RulesModal from "../../pages/RulesModal";
|
||||
import ChatPage from "../../pages/ChatPage";
|
||||
import { DesktopIcons } from "./DesktopIcons";
|
||||
import { useChatList } from "../../hooks/useChatList";
|
||||
import { useProfileData } from "../../hooks/useProfileData";
|
||||
import { useAuthContext } from "../../context/AuthContext";
|
||||
import { getPostForChat } from "../../stores/chatPostStore";
|
||||
import { getChatDisplayInfo } from "../../utils/chatDisplay";
|
||||
|
||||
/**
|
||||
* DesktopChats — двухпанельный мессенджер десктопа: список чатов слева,
|
||||
* открытая переписка справа. Один компонент обслуживает /chats, /chats/new
|
||||
* и /chats/:chatId, поэтому список не перезагружается при переключении чатов.
|
||||
*/
|
||||
export default function DesktopChats() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { chatId } = useParams();
|
||||
const isDraft = location.pathname === "/chats/new";
|
||||
const { user } = useAuthContext();
|
||||
const profileData = useProfileData(user);
|
||||
const {
|
||||
chats, loading, fetchChats, unreadMap, isAuthenticated,
|
||||
handleDeleteChat, deleteError, clearDeleteError,
|
||||
} = useChatList();
|
||||
const [query, setQuery] = useState("");
|
||||
const [modal, setModal] = useState(null);
|
||||
|
||||
// Новое сообщение в открытом чате → обновляем превью в списке
|
||||
// (с небольшой задержкой, чтобы сервер успел сохранить сообщение).
|
||||
const refreshTimerRef = useRef(null);
|
||||
const refreshList = useCallback(() => {
|
||||
clearTimeout(refreshTimerRef.current);
|
||||
refreshTimerRef.current = setTimeout(() => fetchChats({ silent: true }), 700);
|
||||
}, [fetchChats]);
|
||||
useEffect(() => () => clearTimeout(refreshTimerRef.current), []);
|
||||
|
||||
const items = useMemo(() => {
|
||||
const q = query.trim().toLowerCase();
|
||||
return chats
|
||||
.map((chat) => {
|
||||
const post = getPostForChat(chat.id);
|
||||
const info = getChatDisplayInfo(chat, post, unreadMap, t);
|
||||
return { chat, post, info };
|
||||
})
|
||||
.filter(({ info }) => !q
|
||||
|| String(info.title || "").toLowerCase().includes(q)
|
||||
|| String(info.preview || "").toLowerCase().includes(q));
|
||||
}, [chats, unreadMap, query, t]);
|
||||
|
||||
const onDelete = async (id) => {
|
||||
const deleted = await handleDeleteChat(id);
|
||||
if (deleted && String(id) === String(chatId)) navigate("/chats", { replace: true });
|
||||
};
|
||||
|
||||
const goFeed = (state) => navigate("/feed", state ? { state } : undefined);
|
||||
|
||||
return (
|
||||
<div className="f-app fd-chats-app">
|
||||
<Sidebar
|
||||
open={false}
|
||||
activeNav="chat"
|
||||
onClose={() => {}}
|
||||
onNavClick={(key) => goFeed({ desktopNav: key })}
|
||||
isAuthenticated={isAuthenticated}
|
||||
onLoginClick={() => setModal("auth")}
|
||||
onRulesClick={() => setModal("rules")}
|
||||
onReviewsClick={() => navigate("/reviews")}
|
||||
onCreatePost={() => (isAuthenticated ? goFeed({ desktopAction: "create" }) : setModal("auth"))}
|
||||
onProfileClick={() => setModal("profile")}
|
||||
onMapClick={() => navigate("/feed?view=map")}
|
||||
profileData={profileData}
|
||||
/>
|
||||
|
||||
<div className="fd-chats">
|
||||
<section className="fd-chats-list" aria-label={t("chat.chats")}>
|
||||
<div className="fd-chats-list-head">
|
||||
<h1 className="fd-chats-title">
|
||||
{t("chat.chats")}
|
||||
{chats.length > 0 && <span className="fd-chats-count">{chats.length}</span>}
|
||||
</h1>
|
||||
{isAuthenticated && chats.length > 0 && (
|
||||
<label className="fd-chats-search">
|
||||
<DesktopIcons.Search size={17} />
|
||||
<input
|
||||
type="search"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
placeholder={t("desktop.chats.search")}
|
||||
aria-label={t("desktop.chats.search")}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="fd-chats-scroll">
|
||||
{!isAuthenticated ? (
|
||||
<div className="fd-empty fd-empty-sm">
|
||||
<div className="fd-empty-sub">{t("chat.loginToSee")}</div>
|
||||
</div>
|
||||
) : loading ? (
|
||||
Array.from({ length: 7 }, (_, i) => (
|
||||
<div key={i} className="fd-chat-skeleton" aria-hidden="true">
|
||||
<span className="fd-skeleton fd-chat-skeleton-avatar" />
|
||||
<span className="fd-chat-skeleton-lines">
|
||||
<span className="fd-skeleton fd-skeleton-line" />
|
||||
<span className="fd-skeleton fd-skeleton-line fd-skeleton-line-short" />
|
||||
</span>
|
||||
</div>
|
||||
))
|
||||
) : chats.length === 0 && !isDraft ? (
|
||||
<div className="fd-empty fd-empty-sm">
|
||||
<div className="fd-empty-icon"><DesktopIcons.Message size={24} /></div>
|
||||
<div className="fd-empty-title">{t("chat.noChats")}</div>
|
||||
</div>
|
||||
) : items.length === 0 && !isDraft ? (
|
||||
<div className="fd-empty fd-empty-sm">
|
||||
<div className="fd-empty-sub">{t("desktop.chats.nothingFound")}</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{isDraft && (
|
||||
<div className="fd-chat-row is-active">
|
||||
<div className="chat-list-item fd-chat-draft">
|
||||
<div className="chat-list-avatar"><DesktopIcons.Plus size={18} /></div>
|
||||
<div className="chat-list-info">
|
||||
<div className="chat-list-name">{location.state?.post?.title || t("desktop.chats.newChat")}</div>
|
||||
<div className="chat-list-preview">{t("desktop.chats.newChat")}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{items.map(({ chat, post }) => (
|
||||
<div
|
||||
key={chat.id}
|
||||
className={`fd-chat-row${String(chat.id) === String(chatId) ? " is-active" : ""}`}
|
||||
>
|
||||
<ChatListItem
|
||||
chat={chat}
|
||||
post={post}
|
||||
unreadMap={unreadMap}
|
||||
t={t}
|
||||
onOpen={(id) => navigate(`/chats/${id}`)}
|
||||
onDelete={onDelete}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="fd-chats-main">
|
||||
{!isAuthenticated ? (
|
||||
<div className="fd-chats-placeholder">
|
||||
<div className="fd-chats-placeholder-icon"><DesktopIcons.Message size={30} /></div>
|
||||
<div className="fd-empty-title">{t("chat.loginToSee")}</div>
|
||||
<button type="button" className="fd-btn fd-btn-primary" onClick={() => setModal("auth")}>
|
||||
{t("feed.login")}
|
||||
</button>
|
||||
</div>
|
||||
) : chatId || isDraft ? (
|
||||
<ChatPage key={chatId || "new"} embedded onActivity={refreshList} />
|
||||
) : (
|
||||
<div className="fd-chats-placeholder">
|
||||
<div className="fd-chats-placeholder-icon"><DesktopIcons.Message size={30} /></div>
|
||||
<div className="fd-empty-title">{t("desktop.chats.selectTitle")}</div>
|
||||
<div className="fd-empty-sub">{t("desktop.chats.selectSub")}</div>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{deleteError && <Toast message={deleteError} type="error" onDismiss={clearDeleteError} />}
|
||||
{modal === "auth" && <AuthModal onClose={() => setModal(null)} />}
|
||||
{modal === "rules" && <RulesModal onClose={() => setModal(null)} />}
|
||||
{modal === "profile" && isAuthenticated && (
|
||||
<ProfileModal onClose={() => setModal(null)} initialData={profileData} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
131
src/components/desktop/DesktopFeedHeader.jsx
Normal file
131
src/components/desktop/DesktopFeedHeader.jsx
Normal file
@@ -0,0 +1,131 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import FeedSearchBar from "../feed/FeedSearchBar";
|
||||
import CityFilter from "../CityFilter";
|
||||
import { DesktopIcons } from "./DesktopIcons";
|
||||
|
||||
const TITLE_KEYS = {
|
||||
home: "nav.home",
|
||||
items: "nav.items",
|
||||
pets: "nav.pets",
|
||||
myads: "nav.myAds",
|
||||
};
|
||||
|
||||
/**
|
||||
* Сегментированный переключатель «Все / Потери / Находки».
|
||||
* Индикатор активного сегмента — отдельный слой, который едет под кнопками.
|
||||
*/
|
||||
export function TypeSegment({ value, onChange, size = "md" }) {
|
||||
const { t } = useTranslation();
|
||||
const options = [
|
||||
{ key: null, label: t("desktop.typeAll") },
|
||||
{ key: "loss", label: t("feed.filterLoss"), tone: "loss" },
|
||||
{ key: "found", label: t("feed.filterFound"), tone: "found" },
|
||||
];
|
||||
const activeIndex = Math.max(0, options.findIndex((o) => o.key === value));
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`fd-segment fd-segment-${size}`}
|
||||
role="radiogroup"
|
||||
aria-label={String(t("feed.openFilter"))}
|
||||
style={{ "--fd-seg-index": activeIndex, "--fd-seg-count": options.length }}
|
||||
>
|
||||
<span className="fd-segment-thumb" aria-hidden="true" />
|
||||
{options.map((opt) => (
|
||||
<button
|
||||
key={opt.key ?? "all"}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={value === opt.key}
|
||||
className={`fd-segment-btn${value === opt.key ? " is-active" : ""}`}
|
||||
onClick={() => onChange(opt.key)}
|
||||
>
|
||||
{opt.tone && <span className={`fd-dot fd-dot-${opt.tone}`} aria-hidden="true" />}
|
||||
{opt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* DesktopFeedHeader — шапка ленты на десктопе: заголовок раздела, счётчик,
|
||||
* фильтр «потеря/находка», поиск с подсказками и мультивыбор городов.
|
||||
* На мобильном не рендерится (там FeedTopBar + шапка поиска).
|
||||
*/
|
||||
export default function DesktopFeedHeader({
|
||||
activeNav,
|
||||
typeFilter,
|
||||
onTypeFilterChange,
|
||||
searchQuery,
|
||||
onSearchChange,
|
||||
cities,
|
||||
selectedCities,
|
||||
onCitiesChange,
|
||||
count,
|
||||
loading,
|
||||
onMapClick,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const searching = searchQuery.trim().length > 0 || selectedCities.length > 0;
|
||||
const titleKey = TITLE_KEYS[activeNav] || "nav.home";
|
||||
const showSearch = activeNav !== "myads";
|
||||
const hasFilters = searching || typeFilter != null;
|
||||
|
||||
const reset = () => {
|
||||
onSearchChange("");
|
||||
onCitiesChange([]);
|
||||
onTypeFilterChange(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<header className="fd-feed-header">
|
||||
<div className="fd-feed-header-inner">
|
||||
<div className="fd-feed-title-row">
|
||||
<div className="fd-feed-title-block">
|
||||
<h1 className="fd-feed-title">
|
||||
{searching ? t("desktop.searchResults") : t(titleKey)}
|
||||
</h1>
|
||||
<p className="fd-feed-sub">
|
||||
{t(`desktop.feedSub.${TITLE_KEYS[activeNav] ? activeNav : "home"}`)}
|
||||
{!loading && count > 0 && (
|
||||
<>
|
||||
<span className="fd-sep" aria-hidden="true">·</span>
|
||||
<span className="fd-feed-count">{t("desktop.shown", { count })}</span>
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="fd-feed-title-actions">
|
||||
{hasFilters && (
|
||||
<button type="button" className="fd-link-btn" onClick={reset}>
|
||||
<DesktopIcons.Close size={16} />
|
||||
{t("desktop.resetFilters")}
|
||||
</button>
|
||||
)}
|
||||
{onMapClick && (
|
||||
<button type="button" className="fd-ghost-btn" onClick={onMapClick}>
|
||||
<DesktopIcons.Map size={18} />
|
||||
{t("nav.map")}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="fd-feed-controls">
|
||||
<TypeSegment value={typeFilter} onChange={onTypeFilterChange} />
|
||||
{showSearch && (
|
||||
<div className="fd-feed-search">
|
||||
<FeedSearchBar value={searchQuery} onChange={onSearchChange} t={t} />
|
||||
</div>
|
||||
)}
|
||||
{activeNav === "home" && (
|
||||
<div className="fd-feed-city">
|
||||
<CityFilter cities={cities} value={selectedCities} onChange={onCitiesChange} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
82
src/components/desktop/DesktopIcons.jsx
Normal file
82
src/components/desktop/DesktopIcons.jsx
Normal file
@@ -0,0 +1,82 @@
|
||||
// Линейные иконки десктопной раскладки (единый стиль: 24×24, stroke 2).
|
||||
const base = {
|
||||
viewBox: "0 0 24 24",
|
||||
fill: "none",
|
||||
stroke: "currentColor",
|
||||
strokeWidth: 2,
|
||||
strokeLinecap: "round",
|
||||
strokeLinejoin: "round",
|
||||
"aria-hidden": true,
|
||||
};
|
||||
|
||||
const Svg = ({ size = 20, children, ...rest }) => (
|
||||
<svg width={size} height={size} {...base} {...rest}>{children}</svg>
|
||||
);
|
||||
|
||||
export const DesktopIcons = {
|
||||
Map: (p) => (
|
||||
<Svg {...p}>
|
||||
<path d="M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z" />
|
||||
<path d="M15 5.764v15" />
|
||||
<path d="M9 3.236v15" />
|
||||
</Svg>
|
||||
),
|
||||
Plus: (p) => (
|
||||
<Svg strokeWidth={2.4} {...p}>
|
||||
<path d="M12 5v14" />
|
||||
<path d="M5 12h14" />
|
||||
</Svg>
|
||||
),
|
||||
User: (p) => (
|
||||
<Svg {...p}>
|
||||
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
|
||||
<circle cx="12" cy="7" r="4" />
|
||||
</Svg>
|
||||
),
|
||||
Pin: (p) => (
|
||||
<Svg {...p}>
|
||||
<path d="M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0" />
|
||||
<circle cx="12" cy="10" r="3" />
|
||||
</Svg>
|
||||
),
|
||||
ArrowRight: (p) => (
|
||||
<Svg {...p}>
|
||||
<path d="M5 12h14" />
|
||||
<path d="m12 5 7 7-7 7" />
|
||||
</Svg>
|
||||
),
|
||||
ChevronRight: (p) => (
|
||||
<Svg {...p}>
|
||||
<path d="m9 18 6-6-6-6" />
|
||||
</Svg>
|
||||
),
|
||||
Search: (p) => (
|
||||
<Svg {...p}>
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<path d="m21 21-4.3-4.3" />
|
||||
</Svg>
|
||||
),
|
||||
Message: (p) => (
|
||||
<Svg {...p}>
|
||||
<path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z" />
|
||||
</Svg>
|
||||
),
|
||||
Close: (p) => (
|
||||
<Svg {...p}>
|
||||
<path d="M18 6 6 18" />
|
||||
<path d="m6 6 12 12" />
|
||||
</Svg>
|
||||
),
|
||||
Sparkles: (p) => (
|
||||
<Svg {...p}>
|
||||
<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" />
|
||||
</Svg>
|
||||
),
|
||||
Image: (p) => (
|
||||
<Svg {...p}>
|
||||
<rect width="18" height="18" x="3" y="3" rx="2" />
|
||||
<circle cx="9" cy="9" r="2" />
|
||||
<path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" />
|
||||
</Svg>
|
||||
),
|
||||
};
|
||||
163
src/components/desktop/DesktopMapView.jsx
Normal file
163
src/components/desktop/DesktopMapView.jsx
Normal file
@@ -0,0 +1,163 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import MapView from "../MapView";
|
||||
import { TypeSegment } from "./DesktopFeedHeader";
|
||||
import { DesktopIcons } from "./DesktopIcons";
|
||||
import { getImageUrl } from "../../config/authConstants";
|
||||
import { CATEGORIES } from "../../config/feedConstants";
|
||||
|
||||
// Список рендерим ограниченным: в крупном масштабе в область могут попасть
|
||||
// сотни меток, а пользователю всё равно нужен ближайший десяток.
|
||||
const LIST_LIMIT = 150;
|
||||
|
||||
/**
|
||||
* DesktopMapView — карта объявлений для десктопа: слева панель с фильтрами
|
||||
* и списком объявлений из видимой области, справа карта.
|
||||
* Наведение на карточку подсвечивает метку и наоборот; клик по карточке
|
||||
* открывает объявление, кнопка с пином — плавно перелетает к метке.
|
||||
*/
|
||||
export default function DesktopMapView({ focusPostId, focusLat, focusLng, onPostClick }) {
|
||||
const { t } = useTranslation();
|
||||
const [type, setType] = useState(null);
|
||||
const [category, setCategory] = useState(null);
|
||||
const [markers, setMarkers] = useState(null);
|
||||
const [hoverId, setHoverId] = useState(null);
|
||||
const [focusTarget, setFocusTarget] = useState(null);
|
||||
const listRef = useRef(null);
|
||||
|
||||
const handleMarkers = useCallback((list) => setMarkers(list), []);
|
||||
|
||||
// Наведение на метку карты: подсвечиваем карточку и докручиваем к ней список.
|
||||
const handleMarkerHover = useCallback((id) => {
|
||||
setHoverId(id);
|
||||
if (id == null) return;
|
||||
const node = listRef.current?.querySelector(`[data-item-id="${CSS.escape(String(id))}"]`);
|
||||
node?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
||||
}, []);
|
||||
|
||||
// Открытие с фокусом на объявлении — сразу подсвечиваем его в списке.
|
||||
useEffect(() => {
|
||||
if (focusPostId != null) setHoverId(String(focusPostId));
|
||||
}, [focusPostId]);
|
||||
|
||||
const visible = markers ? markers.slice(0, LIST_LIMIT) : [];
|
||||
|
||||
return (
|
||||
<div className="fd-map">
|
||||
<aside className="fd-map-panel">
|
||||
<div className="fd-map-panel-head">
|
||||
<h1 className="fd-map-title-h">{t("desktop.map.title")}</h1>
|
||||
<TypeSegment value={type} onChange={setType} size="sm" />
|
||||
<div className="fd-chips" role="radiogroup" aria-label={t("post.category")}>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={category == null}
|
||||
className={`fd-chip${category == null ? " is-active" : ""}`}
|
||||
onClick={() => setCategory(null)}
|
||||
>
|
||||
{t("desktop.map.catAll")}
|
||||
</button>
|
||||
{CATEGORIES.map((c) => (
|
||||
<button
|
||||
key={c.value}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={category === c.value}
|
||||
className={`fd-chip${category === c.value ? " is-active" : ""}`}
|
||||
onClick={() => setCategory(c.value)}
|
||||
>
|
||||
{t(c.labelKey)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="fd-map-count">
|
||||
{markers == null
|
||||
? t("desktop.map.loading")
|
||||
: t("desktop.map.inArea", { count: markers.length })}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="fd-map-list" ref={listRef}>
|
||||
{markers == null && (
|
||||
Array.from({ length: 6 }, (_, i) => (
|
||||
<div key={i} className="fd-map-item fd-skeleton-item" aria-hidden="true">
|
||||
<span className="fd-map-item-thumb fd-skeleton" />
|
||||
<span className="fd-map-item-body">
|
||||
<span className="fd-skeleton fd-skeleton-line" />
|
||||
<span className="fd-skeleton fd-skeleton-line fd-skeleton-line-short" />
|
||||
</span>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
|
||||
{markers != null && markers.length === 0 && (
|
||||
<div className="fd-empty fd-empty-sm">
|
||||
<div className="fd-empty-icon"><DesktopIcons.Pin size={26} /></div>
|
||||
<div className="fd-empty-title">{t("desktop.map.emptyArea")}</div>
|
||||
<div className="fd-empty-sub">{t("desktop.map.emptyAreaSub")}</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{visible.map((m) => {
|
||||
const id = String(m.id);
|
||||
const img = m.imageUrl ? getImageUrl(m.imageUrl) : null;
|
||||
const isFound = m.type === "FOUND";
|
||||
return (
|
||||
<div
|
||||
key={id}
|
||||
data-item-id={id}
|
||||
className={`fd-map-item${hoverId === id ? " is-hl" : ""}`}
|
||||
onMouseEnter={() => setHoverId(id)}
|
||||
onMouseLeave={() => setHoverId(null)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="fd-map-item-main"
|
||||
onClick={() => onPostClick(id)}
|
||||
title={t("desktop.map.open")}
|
||||
>
|
||||
<span className="fd-map-item-thumb">
|
||||
{img
|
||||
? <img src={img} alt="" loading="lazy" decoding="async" />
|
||||
: <DesktopIcons.Image size={20} />}
|
||||
</span>
|
||||
<span className="fd-map-item-body">
|
||||
<span className="fd-map-item-title">{m.title}</span>
|
||||
<span className={`fd-badge ${isFound ? "fd-badge-found" : "fd-badge-loss"}`}>
|
||||
{isFound ? t("postCard.found") : t("postCard.loss")}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="fd-icon-btn fd-map-item-locate"
|
||||
onClick={() => setFocusTarget({ lat: m.latitude, lng: m.longitude })}
|
||||
title={t("desktop.map.showOnMap")}
|
||||
aria-label={t("desktop.map.showOnMap")}
|
||||
>
|
||||
<DesktopIcons.Pin size={18} />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div className="fd-map-canvas">
|
||||
<MapView
|
||||
focusPostId={focusPostId}
|
||||
focusLat={focusLat}
|
||||
focusLng={focusLng}
|
||||
type={type}
|
||||
category={category}
|
||||
onPostClick={onPostClick}
|
||||
onMarkersChange={handleMarkers}
|
||||
onMarkerHover={handleMarkerHover}
|
||||
highlightId={hoverId}
|
||||
focusTarget={focusTarget}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
240
src/components/desktop/DesktopSidebar.jsx
Normal file
240
src/components/desktop/DesktopSidebar.jsx
Normal file
@@ -0,0 +1,240 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { NavIcons } from "../icons/NavIcons";
|
||||
import SunIcon from "../icons/SunIcon";
|
||||
import MoonIcon from "../icons/MoonIcon";
|
||||
import GlobeIcon from "../icons/GlobeIcon";
|
||||
import NahodkaLogo from "../MainNahodkaLogo";
|
||||
import ProfileAvatar from "../profile/ProfileAvatar";
|
||||
import SupportModal from "../SupportModal";
|
||||
import UploadAdModal from "../UploadAdModal";
|
||||
import { useTheme } from "../../context/ThemeContext";
|
||||
import { useUnread } from "../../context/UnreadContext";
|
||||
import { useAuthContext } from "../../context/AuthContext";
|
||||
import { useLanguageToggle } from "../../hooks/useLanguageToggle";
|
||||
import { DesktopIcons } from "./DesktopIcons";
|
||||
|
||||
// Порядок пунктов основной навигации десктопа. «Карта» есть только здесь:
|
||||
// на мобильном она живёт в нижней панели (BottomNav).
|
||||
const MAIN_NAV = [
|
||||
{ key: "home", labelKey: "nav.home", icon: () => NavIcons.grid() },
|
||||
{ key: "items", labelKey: "nav.items", icon: () => NavIcons.box() },
|
||||
{ key: "pets", labelKey: "nav.pets", icon: () => NavIcons.paw() },
|
||||
{ key: "map", labelKey: "nav.map", icon: () => <DesktopIcons.Map /> },
|
||||
{ key: "myads", labelKey: "nav.myAds", icon: () => NavIcons.file() },
|
||||
{ key: "chat", labelKey: "nav.chat", icon: () => NavIcons.chat() },
|
||||
];
|
||||
|
||||
const ADMIN_NAV = [
|
||||
{ key: "admin-campaigns", labelKey: "adminPanel.campaignsNav", icon: () => NavIcons.grid(), to: "/admin/ads" },
|
||||
{ key: "admin-posts", labelKey: "adminPanel.postsNav", icon: () => NavIcons.rules(), to: "/admin/ads?tab=posts" },
|
||||
{ key: "admin-posts-rejected", labelKey: "adminPanel.postsRejectedNav", icon: () => NavIcons.rules(), to: "/admin/ads?tab=rejected" },
|
||||
];
|
||||
|
||||
/**
|
||||
* DesktopSidebar — левая навигация десктопной раскладки (>= 900px).
|
||||
*
|
||||
* На 900–1199px автоматически сворачивается в узкую «рейку» с иконками
|
||||
* (подписи скрываются CSS-ом, остаются title-подсказки), на >= 1200px —
|
||||
* полная панель с подписями. Мобильный drawer — отдельный компонент Sidebar.
|
||||
*/
|
||||
export default function DesktopSidebar({
|
||||
activeNav,
|
||||
onNavClick,
|
||||
isAuthenticated,
|
||||
onLoginClick,
|
||||
onRulesClick,
|
||||
onReviewsClick,
|
||||
onCreatePost,
|
||||
onProfileClick,
|
||||
onMapClick,
|
||||
profileData,
|
||||
}) {
|
||||
const navigate = useNavigate();
|
||||
const { t } = useTranslation();
|
||||
const { isAdmin } = useAuthContext();
|
||||
const { theme, toggle: toggleTheme } = useTheme();
|
||||
const { totalUnread } = useUnread();
|
||||
const { language, toggleLanguage } = useLanguageToggle();
|
||||
const [supportOpen, setSupportOpen] = useState(false);
|
||||
const [uploadAdOpen, setUploadAdOpen] = useState(false);
|
||||
|
||||
const profileName = `${profileData?.firstName || ""} ${profileData?.lastName || ""}`.trim();
|
||||
|
||||
const handleMain = (key) => {
|
||||
if (key === "chat") {
|
||||
if (!isAuthenticated) onLoginClick();
|
||||
else navigate("/chats");
|
||||
return;
|
||||
}
|
||||
if (key === "myads" && !isAuthenticated) {
|
||||
onLoginClick();
|
||||
return;
|
||||
}
|
||||
if (key === "map") {
|
||||
if (onMapClick) onMapClick();
|
||||
else navigate("/feed?view=map");
|
||||
return;
|
||||
}
|
||||
onNavClick(key);
|
||||
};
|
||||
|
||||
const handleProfile = () => {
|
||||
if (!isAuthenticated) onLoginClick();
|
||||
else onProfileClick?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<aside className="fd-sidebar" aria-label={t("feed.openMenu")}>
|
||||
<div className="fd-sb-head">
|
||||
<button
|
||||
type="button"
|
||||
className="fd-sb-logo"
|
||||
onClick={() => navigate("/")}
|
||||
title={t("app.name")}
|
||||
aria-label={t("app.name")}
|
||||
>
|
||||
<NahodkaLogo className="fd-sb-logo-full" />
|
||||
<img src="/favicon.svg" alt="" className="fd-sb-logo-mark" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className="fd-sb-cta"
|
||||
onClick={onCreatePost}
|
||||
title={t("desktop.createPost")}
|
||||
>
|
||||
<DesktopIcons.Plus />
|
||||
<span className="fd-sb-label">{t("desktop.createPost")}</span>
|
||||
</button>
|
||||
|
||||
<nav className="fd-sb-nav">
|
||||
{MAIN_NAV.map(({ key, labelKey, icon }) => (
|
||||
<button
|
||||
type="button"
|
||||
key={key}
|
||||
className={`fd-sb-item${activeNav === key ? " is-active" : ""}`}
|
||||
onClick={() => handleMain(key)}
|
||||
title={t(labelKey)}
|
||||
aria-current={activeNav === key ? "page" : undefined}
|
||||
>
|
||||
<span className="fd-sb-icon">
|
||||
{icon()}
|
||||
{key === "chat" && totalUnread > 0 && <span className="fd-sb-dot" />}
|
||||
</span>
|
||||
<span className="fd-sb-label">{t(labelKey)}</span>
|
||||
{key === "chat" && totalUnread > 0 && (
|
||||
<span className="fd-sb-badge">{totalUnread > 99 ? "99+" : totalUnread}</span>
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
|
||||
{isAdmin && (
|
||||
<>
|
||||
<div className="fd-sb-section">{t("desktop.adminSection")}</div>
|
||||
<button
|
||||
type="button"
|
||||
className="fd-sb-item"
|
||||
onClick={() => setUploadAdOpen(true)}
|
||||
title={t("admin.uploadAd")}
|
||||
>
|
||||
<span className="fd-sb-icon">{NavIcons.megaphone()}</span>
|
||||
<span className="fd-sb-label">{t("admin.uploadAd")}</span>
|
||||
</button>
|
||||
{ADMIN_NAV.map(({ key, labelKey, icon, to }) => (
|
||||
<button
|
||||
type="button"
|
||||
key={key}
|
||||
className={`fd-sb-item${activeNav === key ? " is-active" : ""}`}
|
||||
onClick={() => navigate(to)}
|
||||
title={t(labelKey)}
|
||||
>
|
||||
<span className="fd-sb-icon">{icon()}</span>
|
||||
<span className="fd-sb-label">{t(labelKey)}</span>
|
||||
</button>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</nav>
|
||||
|
||||
<div className="fd-sb-bottom">
|
||||
<button
|
||||
type="button"
|
||||
className={`fd-sb-item fd-sb-item-sm${activeNav === "reviews" ? " is-active" : ""}`}
|
||||
onClick={onReviewsClick}
|
||||
title={t("nav.reviews")}
|
||||
>
|
||||
<span className="fd-sb-icon">{NavIcons.star()}</span>
|
||||
<span className="fd-sb-label">{t("nav.reviews")}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="fd-sb-item fd-sb-item-sm"
|
||||
onClick={onRulesClick}
|
||||
title={t("nav.rules")}
|
||||
>
|
||||
<span className="fd-sb-icon">{NavIcons.rules()}</span>
|
||||
<span className="fd-sb-label">{t("nav.rules")}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="fd-sb-item fd-sb-item-sm"
|
||||
onClick={() => setSupportOpen(true)}
|
||||
title={t("nav.support")}
|
||||
>
|
||||
<span className="fd-sb-icon">{NavIcons.help()}</span>
|
||||
<span className="fd-sb-label">{t("nav.support")}</span>
|
||||
</button>
|
||||
|
||||
<div className="fd-sb-prefs">
|
||||
<button
|
||||
type="button"
|
||||
className="fd-sb-pref"
|
||||
onClick={toggleTheme}
|
||||
title={theme === "dark" ? t("sidebar.lightTheme") : t("sidebar.darkTheme")}
|
||||
aria-label={theme === "dark" ? t("sidebar.lightTheme") : t("sidebar.darkTheme")}
|
||||
>
|
||||
{theme === "dark" ? <SunIcon /> : <MoonIcon />}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="fd-sb-pref fd-sb-pref-lang"
|
||||
onClick={toggleLanguage}
|
||||
title={language === "ru" ? "English" : "Русский"}
|
||||
aria-label={language === "ru" ? "English" : "Русский"}
|
||||
>
|
||||
<GlobeIcon />
|
||||
<span>{language === "ru" ? "RU" : "EN"}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className="fd-sb-profile"
|
||||
onClick={handleProfile}
|
||||
title={isAuthenticated ? t("desktop.myProfile") : t("feed.login")}
|
||||
>
|
||||
{isAuthenticated ? (
|
||||
<ProfileAvatar avatar={profileData?.avatar} name={profileName} />
|
||||
) : (
|
||||
<span className="fd-sb-profile-guest"><DesktopIcons.User /></span>
|
||||
)}
|
||||
<span className="fd-sb-profile-info fd-sb-label">
|
||||
<span className="fd-sb-profile-name">
|
||||
{isAuthenticated ? profileName || profileData?.login : t("feed.login")}
|
||||
</span>
|
||||
<span className="fd-sb-profile-sub">
|
||||
{isAuthenticated ? `@${profileData?.login || t("profile.default")}` : t("desktop.guestText")}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
{supportOpen && <SupportModal onClose={() => setSupportOpen(false)} />}
|
||||
{uploadAdOpen && <UploadAdModal onClose={() => setUploadAdOpen(false)} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user