added feed

This commit is contained in:
SlimusMinus
2026-05-06 01:51:01 +03:00
parent eeda490e55
commit fc829c8c7a
18 changed files with 947 additions and 1 deletions

51
src/components/AdCard.jsx Normal file
View File

@@ -0,0 +1,51 @@
import PinIcon from "./icons/PinIcon";
import CalendarIcon from "./icons/CalendarIcon";
import PhoneIcon from "./icons/PhoneIcon";
import MapIcon from "./icons/MapIcon";
import HeartIcon from "./icons/HeartIcon";
export default function AdCard({ ad, liked, onLike }) {
return (
<div className="f-card">
<div className="f-card-img">
{ad.image
? <img src={ad.image} alt={ad.title} />
: <span className="f-card-emoji">{ad.emoji || "📋"}</span>
}
{ad.category && <div className="f-cat-badge">{ad.category}</div>}
<div className={`f-type-badge ${ad.type === "loss" ? "f-type-loss" : "f-type-found"}`}>
{ad.type === "loss" ? "Потеря" : "Находка"}
</div>
</div>
<div className="f-card-body">
<div className="f-card-title">{ad.title}</div>
<div className="f-card-desc">{ad.description}</div>
<div className="f-card-meta">
{ad.location && <div className="f-meta-pill"><PinIcon /> {ad.location}</div>}
{ad.date && <div className="f-meta-pill"><CalendarIcon /> {ad.date}</div>}
</div>
{ad.location && (
<button className="f-card-map" onClick={e => e.stopPropagation()}>
<MapIcon /> Показать на карте — {ad.location}
</button>
)}
<div className="f-card-foot">
{ad.phone
? <a className="f-card-phone" href={`tel:${ad.phone}`} onClick={e => e.stopPropagation()}>
<PhoneIcon /> {ad.phone}
</a>
: <span />
}
<span className="f-card-date">{ad.date || ""}</span>
<button
className={`f-like-btn${liked ? " liked" : ""}`}
onClick={e => { e.stopPropagation(); onLike(ad.id); }}
>
<HeartIcon filled={liked} />
{liked ? (ad.likes || 0) + 1 : (ad.likes || 0)}
</button>
</div>
</div>
</div>
);
}

View File

@@ -0,0 +1,157 @@
import {useCallback, useState} from "react";
import {API_URL} from "../config/constants";
import PinIcon from "./icons/PinIcon";
import CloseIcon from "./icons/CloseIcon";
import { EMPTY_FORM, CATEGORIES } from "../config/feedConstants";
export default function PostModal({ onClose, onSuccess }) {
const [form, setForm] = useState(EMPTY_FORM);
const [errors, setErrors] = useState({});
const [loading, setLoading] = useState(false);
const [apiError, setApiError] = useState("");
const set = useCallback((k, v) => {
setForm(p => ({ ...p, [k]: v }));
setErrors(p => ({ ...p, [k]: "" }));
setApiError("");
}, []);
const validate = () => {
const e = {};
if (!form.title.trim()) e.title = "Введите название";
if (!form.description.trim()) e.description = "Введите описание";
if (!form.category) e.category = "Выберите категорию";
if (!form.phone.trim()) e.phone = "Введите номер телефона";
setErrors(e);
return !Object.keys(e).length;
};
const handleSubmit = async () => {
if (!validate()) return;
setLoading(true);
setApiError("");
try {
const res = await fetch(`${API_URL}/api/ads`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(form),
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
throw new Error(data.message || `Ошибка ${res.status}`);
}
const newAd = await res.json();
onSuccess(newAd);
onClose();
} catch (err) {
setApiError(err.message || "Не удалось разместить объявление");
} finally {
setLoading(false);
}
};
return (
<div className="f-modal-bg" onClick={e => e.target === e.currentTarget && onClose()}>
<div className="f-modal">
<div className="f-modal-head">
<span className="f-modal-title">Новое объявление</span>
<button className="f-close-btn" onClick={onClose}><CloseIcon /></button>
</div>
<div className="f-m-group">
<label className="f-m-label">Тип объявления</label>
<div className="f-type-toggle">
<button className={`f-type-opt${form.type === "loss" ? " loss" : ""}`} onClick={() => set("type", "loss")}>
Потеря
</button>
<button className={`f-type-opt${form.type === "found" ? " found" : ""}`} onClick={() => set("type", "found")}>
Находка
</button>
</div>
</div>
<div className="f-m-group">
<label className="f-m-label">Название</label>
<input
className={`f-m-field${errors.title ? " err" : ""}`}
type="text"
placeholder="Например: Кошелёк чёрный кожаный"
value={form.title}
onChange={e => set("title", e.target.value)}
/>
{errors.title && <p className="f-err-msg">{errors.title}</p>}
</div>
<div className="f-m-group">
<label className="f-m-label">Описание</label>
<textarea
className={`f-m-field${errors.description ? " err" : ""}`}
rows={3}
placeholder="Подробно опишите предмет — цвет, размер, особые приметы..."
value={form.description}
onChange={e => set("description", e.target.value)}
/>
{errors.description && <p className="f-err-msg">{errors.description}</p>}
</div>
<div className="f-m-row">
<div className="f-m-group">
<label className="f-m-label">Категория</label>
<select
className={`f-m-field${errors.category ? " err" : ""}`}
value={form.category}
onChange={e => set("category", e.target.value)}
>
<option value="">Выбрать...</option>
{CATEGORIES.map(c => <option key={c} value={c}>{c}</option>)}
</select>
{errors.category && <p className="f-err-msg">{errors.category}</p>}
</div>
<div className="f-m-group">
<label className="f-m-label">Дата события</label>
<input
className="f-m-field"
type="date"
value={form.date}
onChange={e => set("date", e.target.value)}
/>
</div>
</div>
<div className="f-m-group">
<label className="f-m-label">Место на карте</label>
<div className="f-map-pick">
<PinIcon size={14} />
Нажмите, чтобы отметить место
</div>
<p className="f-hint">Карта будет добавлена в следующей версии</p>
</div>
<div className="f-m-group">
<label className="f-m-label">Номер телефона</label>
<input
className={`f-m-field${errors.phone ? " err" : ""}`}
type="tel"
placeholder="+7 (___) ___-__-__"
value={form.phone}
onChange={e => set("phone", e.target.value)}
/>
{errors.phone && <p className="f-err-msg">{errors.phone}</p>}
</div>
{apiError && (
<p className="f-err-msg" style={{ textAlign: "center", marginBottom: 10 }}>
{apiError}
</p>
)}
<button className="f-m-submit" onClick={handleSubmit} disabled={loading}>
<div className="f-m-submit-row">
{loading && <div className="f-m-spinner" />}
{loading ? "Размещаем..." : "Разместить объявление"}
</div>
</button>
</div>
</div>
);
}

View File

@@ -0,0 +1,14 @@
export default function RightSidebar() {
return (
<div className="f-right">
<div className="f-right-label">Реклама</div>
<div className="f-right-empty">
<div className="f-right-empty-icon">📢</div>
<div className="f-right-empty-text">
Здесь будет<br />ваша реклама
</div>
<button className="f-add-promo-btn">+ Добавить рекламу</button>
</div>
</div>
);
}

View File

@@ -0,0 +1,46 @@
import LogoIcon from "./icons/LogoIcon";
import React from "react";
import {NAV_BOTTOM, NAV_ITEMS} from "../config/feedConstants";
import {NavIcons} from "./icons/NavIcons";
export default function Sidebar({ open, activeNav, onClose, onNavClick }) {
return (
<>
<div className={`f-overlay${open ? " show" : ""}`} onClick={onClose} />
<div className={`f-sidebar${open ? " open" : ""}`}>
<div className="f-sb-head">
<div className="f-sb-logo"><LogoIcon /></div>
<span className="f-sb-name">Находка</span>
</div>
<nav className="f-sb-nav">
{NAV_ITEMS.map(({ icon, label }) => {
const Ic = NavIcons[icon];
return (
<div
key={label}
className={`f-sb-item${activeNav === label ? " active" : ""}`}
onClick={() => { onNavClick(label); onClose(); }}
>
<Ic /> {label}
</div>
);
})}
</nav>
<div className="f-sb-bottom">
{NAV_BOTTOM.map(({ icon, label }) => {
const Ic = NavIcons[icon];
return (
<div
key={label}
className={`f-sb-item${activeNav === label ? " active" : ""}`}
onClick={() => { onNavClick(label); onClose(); }}
>
<Ic /> {label}
</div>
);
})}
</div>
</div>
</>
);
}

View File

@@ -0,0 +1,10 @@
export default function CalendarIcon () {
return (
<svg width={12} height={12} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<rect x="3" y="4" width="18" height="18" rx="2" />
<line x1="16" y1="2" x2="16" y2="6" />
<line x1="8" y1="2" x2="8" y2="6" />
<line x1="3" y1="10" x2="21" y2="10" />
</svg>
);
}

View File

@@ -0,0 +1,9 @@
export default function CloseIcon() {
return (
<svg width={16} height={16} viewBox="0 0 24 24" fill="none"
stroke="currentColor" strokeWidth={2.5} strokeLinecap="round">
<line x1="18" y1="6" x2="6" y2="18"/>
<line x1="6" y1="6" x2="18" y2="18"/>
</svg>
);
}

View File

@@ -0,0 +1,10 @@
export default function HeartIcon({filled}) {
return (
<svg width={14} height={14} viewBox="0 0 24 24"
fill={filled ? "#ff6b6b" : "none"} stroke="#ff6b6b" strokeWidth={2}
strokeLinecap="round">
<path
d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/>
</svg>
);
}

View File

@@ -0,0 +1,13 @@
import magnifier from "../../assets/magnifier.png";
export default function LogoIcon() {
return (
<img
src={magnifier}
alt="logo"
width={20}
height={20}
style={{ objectFit: "contain" }}
/>
);
}

View File

@@ -0,0 +1,10 @@
export default function MapIcon() {
return (
<svg width={14} height={14} viewBox="0 0 24 24" fill="none"
stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<polygon points="1 6 1 22 8 18 16 22 23 18 23 2 16 6 8 2 1 6"/>
<line x1="8" y1="2" x2="8" y2="18"/>
<line x1="16" y1="6" x2="16" y2="22"/>
</svg>
);
}

View File

@@ -0,0 +1,9 @@
export default function MenuIcon () {
return (
<svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.8)" strokeWidth={2.2} strokeLinecap="round">
<line x1="3" y1="6" x2="21" y2="6" />
<line x1="3" y1="12" x2="21" y2="12" />
<line x1="3" y1="18" x2="21" y2="18" />
</svg>
);
}

View File

@@ -0,0 +1,39 @@
export const NavIcons = {
grid: () => (
<svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<rect x="3" y="3" width="7" height="7" rx="1" /><rect x="14" y="3" width="7" height="7" rx="1" />
<rect x="3" y="14" width="7" height="7" rx="1" /><rect x="14" y="14" width="7" height="7" rx="1" />
</svg>
),
alert: () => (
<svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<circle cx="12" cy="12" r="9" /><line x1="12" y1="8" x2="12" y2="12" /><line x1="12" y1="16" x2="12.01" y2="16" />
</svg>
),
search: () => (
<svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<circle cx="11" cy="11" r="7" /><line x1="16.5" y1="16.5" x2="21" y2="21" />
</svg>
),
chat: () => (
<svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
</svg>
),
file: () => (
<svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" /><polyline points="14 2 14 8 20 8" />
</svg>
),
user: () => (
<svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<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>
),
settings: () => (
<svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<circle cx="12" cy="12" r="3" />
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" />
</svg>
),
};

View File

@@ -0,0 +1,9 @@
export default function PhoneIcon() {
return (
<svg width={12} height={12} viewBox="0 0 24 24" fill="none"
stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<path
d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.69 12 19.79 19.79 0 0 1 1.61 3.4 2 2 0 0 1 3.6 1.22h3a2 2 0 0 1 2 1.72c.127.96.361 1.903.7 2.81a2 2 0 0 1-.45 2.11L7.91 8.77a16 16 0 0 0 6.29 6.29l.95-.95a2 2 0 0 1 2.11-.45c.907.339 1.85.573 2.81.7A2 2 0 0 1 22 16.92z"/>
</svg>
);
}

View File

@@ -0,0 +1,8 @@
export default function PinIcon ({ size = 12 }) {
return (
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round">
<path d="M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0 1 18 0z" />
<circle cx="12" cy="10" r="3" />
</svg>
);
}