fixed desktop version
This commit is contained in:
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