fixing thsu frontend views

This commit is contained in:
Micha
2026-01-16 01:43:07 +01:00
parent fd29b928d8
commit f9de433545
27 changed files with 538 additions and 51 deletions

View File

@@ -114,6 +114,24 @@ function PortalHeader({
return
}
if (location.pathname.startsWith('/ucp')) {
setCrumbs([
{ ...base[0] },
{ ...base[1] },
{ label: t('portal.user_control_panel'), to: '/ucp', current: true },
])
return
}
if (location.pathname.startsWith('/profile/')) {
setCrumbs([
{ ...base[0] },
{ ...base[1] },
{ label: t('portal.user_profile'), to: location.pathname, current: true },
])
return
}
setCrumbs([{ ...base[0] }, { ...base[1], current: true }])
}

View File

@@ -74,6 +74,16 @@ export async function getCurrentUser() {
return apiFetch('/user/me')
}
export async function updateCurrentUser(payload) {
return apiFetch('/user/me', {
method: 'PATCH',
headers: {
'Content-Type': 'application/merge-patch+json',
},
body: JSON.stringify(payload),
})
}
export async function uploadAvatar(file) {
const body = new FormData()
body.append('file', file)
@@ -91,6 +101,10 @@ export async function fetchVersion() {
return apiFetch('/version')
}
export async function fetchStats() {
return apiFetch('/stats')
}
export async function fetchSetting(key) {
// TODO: Prefer fetchSettings() when multiple settings are needed.
const cacheBust = Date.now()

View File

@@ -1181,6 +1181,33 @@ a {
font-size: 0.9rem;
}
.bb-board-last {
display: flex;
flex-direction: column;
gap: 0.2rem;
align-items: center;
}
.bb-board-last-by {
color: var(--bb-ink-muted);
font-weight: 600;
}
.bb-board-last-link {
color: var(--bb-accent, #f29b3f);
font-weight: 600;
}
.bb-board-last-link:hover {
color: var(--bb-accent, #f29b3f);
text-decoration: none;
}
.bb-board-last-date {
color: var(--bb-ink-muted);
font-weight: 500;
}
.bb-board-title {
display: flex;
align-items: flex-start;
@@ -1425,6 +1452,16 @@ a {
color: var(--bb-ink-muted);
}
.bb-portal-topic-author {
color: var(--bb-accent, #f29b3f);
font-weight: 600;
}
.bb-portal-topic-author:hover {
color: var(--bb-accent, #f29b3f);
text-decoration: none;
}
.bb-portal-topic-forum-link {
color: var(--bb-accent, #f29b3f);
font-weight: 600;
@@ -1441,6 +1478,36 @@ a {
font-weight: 600;
}
.bb-portal-last {
display: flex;
flex-direction: column;
gap: 0.2rem;
align-items: flex-start;
}
.bb-portal-last-by {
color: var(--bb-ink-muted);
font-weight: 600;
}
.bb-portal-last-link {
color: var(--bb-accent, #f29b3f);
font-weight: 600;
display: inline-flex;
align-items: center;
gap: 0.35rem;
}
.bb-portal-last-link:hover {
color: var(--bb-accent, #f29b3f);
text-decoration: none;
}
.bb-portal-last-date {
color: var(--bb-ink-muted);
font-weight: 500;
}
.bb-portal-user-card {
display: flex;
flex-direction: column;

View File

@@ -1061,7 +1061,7 @@ export default function Acp({ isAdmin }) {
<div className="fw-semibold d-flex align-items-center gap-2">
<span>{node.name}</span>
</div>
<div className="bb-muted">{node.description || t('forum.no_description')}</div>
<div className="bb-muted">{node.description || ''}</div>
</div>
</div>
<div className="d-flex align-items-center gap-3">

View File

@@ -113,7 +113,7 @@ export default function BoardIndex() {
<Link to={`/forum/${node.id}`} className="bb-board-link">
{node.name}
</Link>
<div className="bb-board-desc">{node.description || t('forum.no_description')}</div>
<div className="bb-board-desc">{node.description || ''}</div>
{node.children?.length > 0 && (
<div className="bb-board-subforums">
{t('forum.children')}:{' '}
@@ -130,10 +130,28 @@ export default function BoardIndex() {
</div>
</div>
</div>
<div className="bb-board-cell bb-board-cell--topics"></div>
<div className="bb-board-cell bb-board-cell--posts"></div>
<div className="bb-board-cell bb-board-cell--topics">{node.threads_count ?? 0}</div>
<div className="bb-board-cell bb-board-cell--posts">{node.views_count ?? 0}</div>
<div className="bb-board-cell bb-board-cell--last">
<span className="bb-muted">{t('thread.no_replies')}</span>
{node.last_post_at ? (
<div className="bb-board-last">
<span className="bb-board-last-by">
{t('thread.by')}{' '}
{node.last_post_user_id ? (
<Link to={`/profile/${node.last_post_user_id}`} className="bb-board-last-link">
{node.last_post_user_name || t('thread.anonymous')}
</Link>
) : (
<span>{node.last_post_user_name || t('thread.anonymous')}</span>
)}
</span>
<span className="bb-board-last-date">
{node.last_post_at.slice(0, 10)}
</span>
</div>
) : (
<span className="bb-muted">{t('thread.no_replies')}</span>
)}
</div>
</div>
))

View File

@@ -31,14 +31,30 @@ export default function ForumView() {
<Link to={`/forum/${node.id}`} className="bb-board-link">
{node.name}
</Link>
<div className="bb-board-desc">{node.description || t('forum.no_description')}</div>
<div className="bb-board-desc">{node.description || ''}</div>
</div>
</div>
</div>
<div className="bb-board-cell bb-board-cell--topics"></div>
<div className="bb-board-cell bb-board-cell--posts"></div>
<div className="bb-board-cell bb-board-cell--topics">{node.threads_count ?? 0}</div>
<div className="bb-board-cell bb-board-cell--posts">{node.views_count ?? 0}</div>
<div className="bb-board-cell bb-board-cell--last">
<span className="bb-muted">{t('thread.no_replies')}</span>
{node.last_post_at ? (
<div className="bb-board-last">
<span className="bb-board-last-by">
{t('thread.by')}{' '}
{node.last_post_user_id ? (
<Link to={`/profile/${node.last_post_user_id}`} className="bb-board-last-link">
{node.last_post_user_name || t('thread.anonymous')}
</Link>
) : (
<span>{node.last_post_user_name || t('thread.anonymous')}</span>
)}
</span>
<span className="bb-board-last-date">{node.last_post_at.slice(0, 10)}</span>
</div>
) : (
<span className="bb-muted">{t('thread.no_replies')}</span>
)}
</div>
</div>
))
@@ -190,18 +206,33 @@ export default function ForumView() {
</div>
</div>
</div>
<div className="bb-topic-cell bb-topic-cell--replies">0</div>
<div className="bb-topic-cell bb-topic-cell--views"></div>
<div className="bb-topic-cell bb-topic-cell--replies">
{thread.posts_count ?? 0}
</div>
<div className="bb-topic-cell bb-topic-cell--views">
{thread.views_count ?? 0}
</div>
<div className="bb-topic-cell bb-topic-cell--last">
<div className="bb-topic-last">
<span className="bb-topic-last-by">
{t('thread.by')}{' '}
<span className="bb-topic-author">
{thread.user_name || t('thread.anonymous')}
</span>
{thread.last_post_user_id ? (
<Link
to={`/profile/${thread.last_post_user_id}`}
className="bb-topic-author"
>
{thread.last_post_user_name || t('thread.anonymous')}
</Link>
) : (
<span className="bb-topic-author">
{thread.last_post_user_name || t('thread.anonymous')}
</span>
)}
</span>
{thread.created_at && (
<span className="bb-topic-date">{thread.created_at.slice(0, 10)}</span>
{thread.last_post_at && (
<span className="bb-topic-date">
{thread.last_post_at.slice(0, 10)}
</span>
)}
</div>
</div>

View File

@@ -1,16 +1,18 @@
import { useEffect, useMemo, useState } from 'react'
import { Badge, Container } from 'react-bootstrap'
import { Container } from 'react-bootstrap'
import { Link } from 'react-router-dom'
import { getCurrentUser, listAllForums, listThreads } from '../api/client'
import { fetchStats, getCurrentUser, listAllForums, listThreads } from '../api/client'
import { useTranslation } from 'react-i18next'
import { useAuth } from '../context/AuthContext'
export default function Home() {
const [forums, setForums] = useState([])
const [threads, setThreads] = useState([])
const [stats, setStats] = useState({ threads: 0, posts: 0, users: 0 })
const [error, setError] = useState('')
const [loadingForums, setLoadingForums] = useState(true)
const [loadingThreads, setLoadingThreads] = useState(true)
const [loadingStats, setLoadingStats] = useState(true)
const [profile, setProfile] = useState(null)
const { token, roles, email } = useAuth()
const { t } = useTranslation()
@@ -29,6 +31,21 @@ export default function Home() {
.finally(() => setLoadingThreads(false))
}, [])
useEffect(() => {
fetchStats()
.then((data) => {
setStats({
threads: data?.threads ?? 0,
posts: data?.posts ?? 0,
users: data?.users ?? 0,
})
})
.catch(() => {
setStats({ threads: 0, posts: 0, users: 0 })
})
.finally(() => setLoadingStats(false))
}, [])
useEffect(() => {
if (!token) {
setProfile(null)
@@ -110,6 +127,19 @@ export default function Home() {
return t('portal.user_role_member')
}, [roles, t])
const formatDateTime = (value) => {
if (!value) return '—'
const date = new Date(value)
if (Number.isNaN(date.getTime())) return '—'
const day = String(date.getDate()).padStart(2, '0')
const month = String(date.getMonth() + 1).padStart(2, '0')
const year = String(date.getFullYear())
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
const seconds = String(date.getSeconds()).padStart(2, '0')
return `${day}.${month}.${year} ${hours}:${minutes}:${seconds}`
}
const resolveForumName = (thread) => {
if (!thread?.forum) return t('portal.unknown_forum')
const parts = thread.forum.split('/')
@@ -138,7 +168,7 @@ export default function Home() {
<Link to={`/forum/${node.id}`} className="bb-forum-link fw-semibold">
{node.name}
</Link>
<div className="bb-muted">{node.description || t('forum.no_description')}</div>
<div className="bb-muted">{node.description || ''}</div>
</div>
</div>
</div>
@@ -165,11 +195,15 @@ export default function Home() {
<div className="bb-portal-card-title">{t('portal.stats')}</div>
<div className="bb-portal-stat">
<span>{t('portal.stat_threads')}</span>
<strong>{threads.length}</strong>
<strong>{loadingStats ? '—' : stats.threads}</strong>
</div>
<div className="bb-portal-stat">
<span>{t('portal.stat_forums')}</span>
<strong>{forums.length}</strong>
<span>{t('portal.stat_users')}</span>
<strong>{loadingStats ? '—' : stats.users}</strong>
</div>
<div className="bb-portal-stat">
<span>{t('portal.stat_posts')}</span>
<strong>{loadingStats ? '—' : stats.posts}</strong>
</div>
</div>
</aside>
@@ -201,9 +235,18 @@ export default function Home() {
</Link>
<div className="bb-portal-topic-meta">
<span>{t('thread.by')}</span>
<Badge bg="secondary">
{thread.user_name || t('thread.anonymous')}
</Badge>
{thread.user_id ? (
<Link
to={`/profile/${thread.user_id}`}
className="bb-portal-topic-author"
>
{thread.user_name || t('thread.anonymous')}
</Link>
) : (
<span className="bb-portal-topic-author">
{thread.user_name || t('thread.anonymous')}
</span>
)}
<span className="bb-portal-topic-forum">
{t('portal.forum_label')}{' '}
{resolveForumId(thread) ? (
@@ -220,10 +263,30 @@ export default function Home() {
</div>
</div>
</div>
<div className="bb-portal-topic-cell">0</div>
<div className="bb-portal-topic-cell"></div>
<div className="bb-portal-topic-cell">{thread.posts_count ?? 0}</div>
<div className="bb-portal-topic-cell">{thread.views_count ?? 0}</div>
<div className="bb-portal-topic-cell">
{thread.created_at?.slice(0, 10) || '—'}
<div className="bb-portal-last">
<span className="bb-portal-last-by">
{t('thread.by')}{' '}
{thread.last_post_user_id ? (
<Link
to={`/profile/${thread.last_post_user_id}`}
className="bb-portal-last-link"
>
{thread.last_post_user_name || t('thread.anonymous')}
<i className="bi bi-box-arrow-up-right" aria-hidden="true" />
</Link>
) : (
<span className="bb-portal-last-link">
{thread.last_post_user_name || t('thread.anonymous')}
</span>
)}
</span>
<span className="bb-portal-last-date">
{formatDateTime(thread.last_post_at || thread.created_at)}
</span>
</div>
</div>
</div>
))}

View File

@@ -64,6 +64,7 @@ export default function ThreadView() {
user_avatar_url: thread.user_avatar_url,
user_posts_count: thread.user_posts_count,
user_created_at: thread.user_created_at,
user_location: thread.user_location,
user_rank_name: thread.user_rank_name,
user_rank_badge_type: thread.user_rank_badge_type,
user_rank_badge_text: thread.user_rank_badge_text,
@@ -171,8 +172,10 @@ export default function ThreadView() {
</span>
</div>
<div className="bb-post-author-stat">
<span className="bb-post-author-label">Location:</span>
<span className="bb-post-author-value">Kollmar</span>
<span className="bb-post-author-label">{t('thread.location')}:</span>
<span className="bb-post-author-value">
{post.user_location || '-'}
</span>
</div>
<div className="bb-post-author-stat">
<span className="bb-post-author-label">Thanks given:</span>

View File

@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { Container, Form, Row, Col } from 'react-bootstrap'
import { getCurrentUser, uploadAvatar } from '../api/client'
import { Container, Form, Row, Col, Button } from 'react-bootstrap'
import { getCurrentUser, updateCurrentUser, uploadAvatar } from '../api/client'
import { useAuth } from '../context/AuthContext'
import { useTranslation } from 'react-i18next'
@@ -11,6 +11,10 @@ export default function Ucp({ theme, setTheme, accentOverride, setAccentOverride
const [avatarError, setAvatarError] = useState('')
const [avatarUploading, setAvatarUploading] = useState(false)
const [avatarPreview, setAvatarPreview] = useState('')
const [location, setLocation] = useState('')
const [profileError, setProfileError] = useState('')
const [profileSaving, setProfileSaving] = useState(false)
const [profileSaved, setProfileSaved] = useState(false)
useEffect(() => {
if (!token) return
@@ -20,6 +24,7 @@ export default function Ucp({ theme, setTheme, accentOverride, setAccentOverride
.then((data) => {
if (!active) return
setAvatarPreview(data?.avatar_url || '')
setLocation(data?.location || '')
})
.catch(() => {
if (active) setAvatarPreview('')
@@ -76,6 +81,43 @@ export default function Ucp({ theme, setTheme, accentOverride, setAccentOverride
/>
<Form.Text className="bb-muted">{t('ucp.avatar_hint')}</Form.Text>
</Form.Group>
<Form.Group className="mt-3">
<Form.Label>{t('ucp.location_label')}</Form.Label>
<Form.Control
type="text"
value={location}
disabled={!token || profileSaving}
onChange={(event) => {
setLocation(event.target.value)
setProfileSaved(false)
}}
/>
<Form.Text className="bb-muted">{t('ucp.location_hint')}</Form.Text>
</Form.Group>
{profileError && <p className="text-danger mt-2 mb-0">{profileError}</p>}
{profileSaved && <p className="text-success mt-2 mb-0">{t('ucp.profile_saved')}</p>}
<Button
type="button"
variant="outline-light"
className="mt-3"
disabled={!token || profileSaving}
onClick={async () => {
setProfileError('')
setProfileSaved(false)
setProfileSaving(true)
try {
const response = await updateCurrentUser({ location })
setLocation(response?.location || '')
setProfileSaved(true)
} catch (err) {
setProfileError(err.message)
} finally {
setProfileSaving(false)
}
}}
>
{profileSaving ? t('form.saving') : t('ucp.save_profile')}
</Button>
</Col>
</Row>
</div>

View File

@@ -90,8 +90,7 @@
"forum.empty_threads": "Noch keine Threads vorhanden. Starte unten einen.",
"forum.loading": "Forum wird geladen...",
"forum.login_hint": "Melde dich an, um einen neuen Thread zu erstellen.",
"forum.no_description": "Noch keine Beschreibung vorhanden.",
"forum.only_forums": "Threads können nur in Foren erstellt werden.",
"forum.only_forums": "Threads können nur in Foren erstellt werden.",
"forum.open": "Forum öffnen",
"forum.collapse_category": "Kategorie einklappen",
"forum.expand_category": "Kategorie ausklappen",
@@ -155,7 +154,8 @@
"portal.menu_rules": "Forenregeln",
"portal.stats": "Statistik",
"portal.stat_threads": "Themen",
"portal.stat_forums": "Foren",
"portal.stat_users": "Benutzer",
"portal.stat_posts": "Beiträge",
"portal.latest_posts": "Aktuelle Beiträge",
"portal.empty_posts": "Noch keine Beiträge.",
"portal.topic": "Themen",
@@ -179,6 +179,10 @@
"ucp.profile_hint": "Aktualisiere den Avatar neben deinen Beitragen.",
"ucp.avatar_label": "Profilbild",
"ucp.avatar_hint": "Lade ein Bild hoch (max. 150x150px, Du kannst jpg, png, gif oder webp verwenden).",
"ucp.location_label": "Wohnort",
"ucp.location_hint": "Wird neben Deinen Beiträgen und im Profil angezeigt.",
"ucp.save_profile": "Profil speichern",
"ucp.profile_saved": "Profil gespeichert.",
"ucp.system_default": "Systemstandard",
"ucp.accent_override": "Akzentfarbe überschreiben",
"ucp.accent_override_hint": "Wähle eine eigene Akzentfarbe für die Oberfläche.",
@@ -191,6 +195,7 @@
"thread.loading": "Thread wird geladen...",
"thread.login_hint": "Melde dich an, um auf diesen Thread zu antworten.",
"thread.posts": "Beiträge",
"thread.location": "Wohnort",
"thread.reply_prefix": "Aw:",
"thread.registered": "Registriert",
"thread.replies": "Antworten",

View File

@@ -90,7 +90,6 @@
"forum.empty_threads": "No threads here yet. Start one below.",
"forum.loading": "Loading forum...",
"forum.login_hint": "Log in to create a new thread.",
"forum.no_description": "No description added yet.",
"forum.only_forums": "Threads can only be created in forums.",
"forum.open": "Open forum",
"forum.collapse_category": "Collapse category",
@@ -155,7 +154,8 @@
"portal.menu_rules": "Forum rules",
"portal.stats": "Statistics",
"portal.stat_threads": "Threads",
"portal.stat_forums": "Forums",
"portal.stat_users": "Users",
"portal.stat_posts": "Posts",
"portal.latest_posts": "Latest posts",
"portal.empty_posts": "No posts yet.",
"portal.topic": "Topics",
@@ -179,6 +179,10 @@
"ucp.profile_hint": "Update the avatar shown next to your posts.",
"ucp.avatar_label": "Profile image",
"ucp.avatar_hint": "Upload an image (max 150x150px, you can use jpg, png, gif, or webp).",
"ucp.location_label": "Location",
"ucp.location_hint": "Shown next to your posts and profile.",
"ucp.save_profile": "Save profile",
"ucp.profile_saved": "Profile saved.",
"ucp.system_default": "System default",
"ucp.accent_override": "Accent color override",
"ucp.accent_override_hint": "Choose a custom accent color for your UI.",
@@ -191,6 +195,7 @@
"thread.loading": "Loading thread...",
"thread.login_hint": "Log in to reply to this thread.",
"thread.posts": "Posts",
"thread.location": "Location",
"thread.reply_prefix": "Re:",
"thread.registered": "Registered",
"thread.replies": "Replies",