changed reward on button

This commit is contained in:
SlimusMinus
2026-09-10 00:57:31 +03:00
parent 8839b9b2cc
commit c58a921d73
16 changed files with 1239 additions and 9 deletions

View File

@@ -0,0 +1,150 @@
import { useState, useRef, useEffect } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { useTranslation } from "react-i18next";
import MenuIconBase from "../icons/MenuIcon";
import NahodkaLogoBase from "../NahodkaLogo";
import type { Ref, ComponentType } from "react";
// Legacy .jsx-компоненты: TS инферирует их сигнатуры из JS неточно —
// приводим к нормальному виду для корректной проверки пропсов.
const NahodkaLogo = NahodkaLogoBase as unknown as ComponentType<{
className?: string;
width?: number;
height?: number;
}>;
const MenuIcon = MenuIconBase as unknown as ComponentType<{ className?: string }>;
interface FeedTopBarProps {
onMenuClick: () => void;
typeFilter: "loss" | "found" | null;
onTypeFilterChange: (key: "loss" | "found" | null) => void;
hidden?: boolean;
/** Реф на сам стеклянный бар — родитель меряет его высоту для CSS-переменной --feed-fade-height */
topBarRef?: Ref<HTMLDivElement>;
}
/**
* FeedTopBar — «стеклянная» шапка ленты (Telegram-style).
*
* Эффекты (разделены, чтобы было понятно что за что отвечает):
* - стекло: backdrop-filter blur+saturate + полупрозрачный фон (см. .f-topbar в layout.css);
* - плавное скрытие/появление при скролле: родитель передаёт `hidden`
* (значение из useScrollDirection), CSS делает transform: translateY(-100%)
* — скрывается вверх, контент ленты проплывает под ним;
* - self-contained: вся логика дропдауна фильтра типа осталась здесь.
*/
export default function FeedTopBar({
onMenuClick,
typeFilter,
onTypeFilterChange,
hidden = false,
topBarRef,
}: FeedTopBarProps) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const menuRef = useRef<HTMLDivElement>(null);
const btnRef = useRef<HTMLButtonElement>(null);
const options: { key: "loss" | "found" | null; label: string }[] = [
{ key: "loss", label: t("feed.filterLoss") },
{ key: null, label: t("feed.filterAll") },
{ key: "found", label: t("feed.filterFound") },
];
useEffect(() => {
if (!open) return;
const handler = (e: MouseEvent) => {
if (
menuRef.current && !menuRef.current.contains(e.target as Node) &&
btnRef.current && !btnRef.current.contains(e.target as Node)
) {
setOpen(false);
}
};
document.addEventListener("mousedown", handler);
return () => document.removeEventListener("mousedown", handler);
}, [open]);
const handleSelect = (key: "loss" | "found" | null) => {
onTypeFilterChange(key);
setOpen(false);
};
return (
<div className="f-topbar-dropdown-wrap">
<div className={`f-topbar${hidden ? " f-topbar-hidden" : ""}`} ref={topBarRef}>
<button
type="button"
className="f-menu-btn"
onClick={onMenuClick}
aria-label={String(t("feed.openMenu"))}
>
<MenuIcon />
</button>
<button
ref={btnRef}
type="button"
className="f-logo-btn"
onClick={() => setOpen((v) => !v)}
aria-label={String(t("feed.openFilter"))}
aria-haspopup="menu"
aria-expanded={open}
>
<NahodkaLogo className="f-topbar-logo" />
<svg
className={`f-topbar-chevron${open ? " open" : ""}`}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<polyline points="6 9 12 15 18 9" />
</svg>
</button>
<span className="f-topbar-spacer" />
</div>
<AnimatePresence>
{open && (
<motion.div
className="f-topbar-dropdown-overlay"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.15 }}
onClick={() => setOpen(false)}
/>
)}
</AnimatePresence>
<AnimatePresence>
{open && (
<motion.div
ref={menuRef}
className="f-topbar-dropdown-menu"
initial={{ opacity: 0, scale: 0.95, y: -8 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.95, y: -8 }}
transition={{ duration: 0.18, ease: "easeOut" }}
>
{options.map((opt) => (
<button
key={opt.key ?? "all"}
type="button"
className={`f-topbar-dropdown-item${typeFilter === opt.key ? " active" : ""}`}
onClick={() => handleSelect(opt.key)}
>
{opt.label}
</button>
))}
</motion.div>
)}
</AnimatePresence>
</div>
);
}