fixed desktop version

This commit is contained in:
SlimusMinus
2026-10-23 00:02:44 +03:00
parent 83ae74636b
commit 140a31982a
19 changed files with 2446 additions and 132 deletions

View File

@@ -1,90 +1,160 @@
import { useState } from "react";
import { useTranslation } from 'react-i18next';
import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import ProfileAvatar from "./profile/ProfileAvatar";
import SupportModal from "./SupportModal";
import { DesktopIcons } from "./desktop/DesktopIcons";
import { getImageUrl } from "../config/authConstants";
import { POST_STATUS_CLOSED } from "../config/postConstants";
import { formatRelativeTime } from "../utils/relativeTime";
function FollowButton() {
const [following, setFollowing] = useState(false);
const { t } = useTranslation();
return (
<button className="f-right-action-btn" onClick={() => setFollowing(f => !f)}>
{following ? t('rightSidebar.following') : t('rightSidebar.subscribe')}
</button>
);
}
const FRESH_LIMIT = 5;
export default function RightSidebar({ ads, profileData, isAuthenticated, onProfileClick, onLoginClick, onNavClick }) {
const { t } = useTranslation();
/**
* RightSidebar — правая колонка десктопной ленты (>= 1280px, ниже скрыта CSS):
* карточка профиля, CTA размещения, переход на карту и свежие объявления.
* На мобильной раскладке не отображается.
*
* @param {{
* ads: any[], profileData: any, isAuthenticated: boolean,
* onProfileClick: () => void, onLoginClick: () => void, onNavClick?: (key: string) => void,
* onCreatePost?: () => void, onMapClick?: () => void, onPostClick?: (id: any) => void,
* onRulesClick?: () => void, onReviewsClick?: () => void,
* }} props
*/
export default function RightSidebar({
ads,
profileData,
isAuthenticated,
onProfileClick,
onLoginClick,
onNavClick,
onCreatePost,
onMapClick,
onPostClick,
onRulesClick,
onReviewsClick,
}) {
const { t, i18n } = useTranslation();
const [supportOpen, setSupportOpen] = useState(false);
const suggestions = [...(ads || [])]
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
.slice(0, 4);
// Свежие активные объявления: по дате создания, найденные не показываем.
const fresh = useMemo(() => (
[...(ads || [])]
.filter((ad) => ad.status !== POST_STATUS_CLOSED)
.sort((a, b) => new Date(b.createdAt || 0) - new Date(a.createdAt || 0))
.slice(0, FRESH_LIMIT)
), [ads]);
const profileName = isAuthenticated
? `${profileData?.firstName || ""} ${profileData?.lastName || ""}`.trim() || profileData?.login
: null;
return (
<div className="f-right">
<div className="f-right-profile">
<aside className="f-right fd-right">
{/* Профиль / гость */}
<section className="fd-card fd-profile-card">
{isAuthenticated ? (
<>
<button type="button" className="fd-profile-row" onClick={onProfileClick}>
<ProfileAvatar avatar={profileData?.avatar} name={profileName} />
<div className="f-right-profile-info">
<div className="f-right-profile-name">{profileName}</div>
<div className="f-right-profile-sub">{profileData?.login}</div>
</div>
<button className="f-right-action-btn" onClick={onProfileClick}>
{t('rightSidebar.yourProfile')}
</button>
</>
<span className="fd-profile-info">
<span className="fd-profile-name">{profileName}</span>
<span className="fd-profile-sub">@{profileData?.login}</span>
</span>
<DesktopIcons.ChevronRight size={18} />
</button>
) : (
<>
<div className="f-ig-ring">
<div className="f-ig-avatar">👤</div>
<div className="fd-guest">
<div className="fd-guest-icon"><DesktopIcons.User size={22} /></div>
<div className="fd-guest-text">
<div className="fd-guest-title">{t("desktop.guestTitle")}</div>
<div className="fd-guest-sub">{t("desktop.guestText")}</div>
</div>
<div className="f-right-profile-info">
<div className="f-right-profile-name">{t('rightSidebar.guest')}</div>
<div className="f-right-profile-sub">{t('rightSidebar.guestSub')}</div>
</div>
<button className="f-right-action-btn" onClick={onLoginClick}>
{t('feed.login')}
<button type="button" className="fd-btn fd-btn-primary fd-btn-block" onClick={onLoginClick}>
{t("feed.login")}
</button>
</>
</div>
)}
</div>
</section>
<div className="f-right-header">
<span className="f-right-label">{t('rightSidebar.suggestions')}</span>
<button className="f-right-link" onClick={() => onNavClick?.("home")}>
{t('rightSidebar.all')}
{/* CTA размещения */}
<section className="fd-card fd-cta-card">
<div className="fd-cta-glow" aria-hidden="true" />
<div className="fd-cta-icon"><DesktopIcons.Sparkles size={20} /></div>
<div className="fd-cta-title">{t("desktop.ctaTitle")}</div>
<div className="fd-cta-text">{t("desktop.ctaText")}</div>
<button type="button" className="fd-btn fd-btn-brand fd-btn-block fd-cta-btn" onClick={onCreatePost}>
<DesktopIcons.Plus size={18} />
<span className="fd-cta-btn-label">{t("desktop.createPost")}</span>
</button>
</div>
</section>
{suggestions.length === 0 && (
<div className="f-right-suggest-sub">{t('rightSidebar.empty')}</div>
)}
{/* Карта */}
<button type="button" className="fd-card fd-map-card" onClick={onMapClick}>
<span className="fd-map-art" aria-hidden="true">
<span className="fd-map-road fd-map-road-1" />
<span className="fd-map-road fd-map-road-2" />
<span className="fd-map-road fd-map-road-3" />
<span className="fd-map-pin fd-map-pin-loss" style={{ left: "22%", top: "38%" }} />
<span className="fd-map-pin fd-map-pin-found" style={{ left: "58%", top: "24%" }} />
<span className="fd-map-pin fd-map-pin-loss" style={{ left: "72%", top: "62%" }} />
<span className="fd-map-pin fd-map-pin-found" style={{ left: "36%", top: "70%" }} />
</span>
<span className="fd-map-body">
<span className="fd-map-title">{t("desktop.mapCardTitle")}</span>
<span className="fd-map-text">{t("desktop.mapCardText")}</span>
<span className="fd-map-link">
{t("desktop.mapCardBtn")}
<DesktopIcons.ArrowRight size={16} />
</span>
</span>
</button>
{suggestions.map(ad => (
<div className="f-right-suggest" key={ad.id}>
<div className="f-ig-ring f-ig-ring-sm">
<div className="f-ig-avatar">{ad.emoji || "📋"}</div>
</div>
<div className="f-right-suggest-info">
<div className="f-right-suggest-name">{ad.title}</div>
<div className="f-right-suggest-sub">
{ad.city || (ad.type === "loss" ? t('postCard.loss') : t('postCard.found'))}
</div>
</div>
<FollowButton />
</div>
))}
{/* Свежие объявления */}
<section className="fd-card fd-fresh">
<div className="fd-card-head">
<span className="fd-card-title">{t("desktop.fresh")}</span>
<button type="button" className="fd-link-btn" onClick={() => onNavClick?.("home")}>
{t("desktop.seeAll")}
</button>
</div>
{fresh.length === 0 ? (
<div className="fd-fresh-empty">{t("desktop.freshEmpty")}</div>
) : (
<ul className="fd-fresh-list">
{fresh.map((ad) => {
const img = Array.isArray(ad.images) && ad.images[0] ? getImageUrl(ad.images[0]) : null;
const when = formatRelativeTime(ad.createdAt, i18n.language);
return (
<li key={ad.id}>
<button type="button" className="fd-fresh-item" onClick={() => onPostClick?.(ad.id)}>
<span className="fd-fresh-thumb">
{img ? <img src={img} alt="" loading="lazy" decoding="async" /> : <span>{ad.emoji || "📋"}</span>}
<span className={`fd-fresh-type fd-fresh-type-${ad.type === "found" ? "found" : "loss"}`} />
</span>
<span className="fd-fresh-info">
<span className="fd-fresh-title">{ad.title}</span>
<span className="fd-fresh-sub">
{ad.type === "found" ? t("postCard.found") : t("postCard.loss")}
{ad.city && <> · {ad.city}</>}
{when && <> · {when}</>}
</span>
</span>
</button>
</li>
);
})}
</ul>
)}
</section>
<div className="f-right-foot">
<span>© {new Date().getFullYear()} {t('app.name')}</span>
<span>{t('rightSidebar.footRules')}</span>
<span>{t('rightSidebar.footPrivacy')}</span>
<span>{t('rightSidebar.footSupport')}</span>
</div>
</div>
<footer className="fd-right-foot">
<button type="button" onClick={onRulesClick}>{t("rightSidebar.footRules")}</button>
<button type="button" onClick={onReviewsClick}>{t("nav.reviews")}</button>
<button type="button" onClick={() => setSupportOpen(true)}>{t("rightSidebar.footSupport")}</button>
<span>© {new Date().getFullYear()} {t("app.name")}</span>
</footer>
{supportOpen && <SupportModal onClose={() => setSupportOpen(false)} />}
</aside>
);
}