91 lines
3.4 KiB
JavaScript
91 lines
3.4 KiB
JavaScript
import { useState } from "react";
|
|
import { useTranslation } from 'react-i18next';
|
|
import ProfileAvatar from "./profile/ProfileAvatar";
|
|
|
|
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>
|
|
);
|
|
}
|
|
|
|
export default function RightSidebar({ ads, profileData, isAuthenticated, onProfileClick, onLoginClick, onNavClick }) {
|
|
const { t } = useTranslation();
|
|
|
|
const suggestions = [...(ads || [])]
|
|
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
|
.slice(0, 4);
|
|
|
|
const profileName = isAuthenticated
|
|
? `${profileData?.firstName || ""} ${profileData?.lastName || ""}`.trim() || profileData?.login
|
|
: null;
|
|
|
|
return (
|
|
<div className="f-right">
|
|
<div className="f-right-profile">
|
|
{isAuthenticated ? (
|
|
<>
|
|
<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>
|
|
</>
|
|
) : (
|
|
<>
|
|
<div className="f-ig-ring">
|
|
<div className="f-ig-avatar">👤</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>
|
|
</>
|
|
)}
|
|
</div>
|
|
|
|
<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')}
|
|
</button>
|
|
</div>
|
|
|
|
{suggestions.length === 0 && (
|
|
<div className="f-right-suggest-sub">{t('rightSidebar.empty')}</div>
|
|
)}
|
|
|
|
{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>
|
|
))}
|
|
|
|
<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>
|
|
);
|
|
}
|