mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-01 20:55:16 +09:00
feat(ui): compact Notifications filters on phone and tablet
One row with All/Unread plus a funnel button (count badge) that opens a bottom sheet with Category and Severity chips and Reset. Desktop keeps the chips inline on a single row.
This commit is contained in:
1 parent
f628951c3a
commit
f76218b243
3 files changed
+111
-50
No files matched your search
@@ -4153,18 +4153,21 @@
|
||||
"allCaughtUp": "All caught up",
|
||||
"any": "Any",
|
||||
"apps": "Services",
|
||||
"category": "Category",
|
||||
"critical": "Critical",
|
||||
"deliveryLog": "Delivery log",
|
||||
"dismiss": "Dismiss {{title}}",
|
||||
"filterByCategory": "Filter by category",
|
||||
"filterBySeverity": "Filter by severity",
|
||||
"filterNotifications": "Filter notifications",
|
||||
"filters": "Filters",
|
||||
"loadMore": "Load more",
|
||||
"markAllRead": "Mark all read",
|
||||
"markCategoryRead": "Mark {{category}} read",
|
||||
"noNotificationsYet": "No notifications yet.",
|
||||
"noUnreadNotifications": "No unread notifications.",
|
||||
"notifications": "Notifications",
|
||||
"reset": "Reset",
|
||||
"success": "Success",
|
||||
"unread": "Unread",
|
||||
"unreadCount": "{{count}} unread"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Bell, CheckCheck, ScrollText, X } from 'lucide-react';
|
||||
import { Bell, CheckCheck, Filter, ScrollText, X } from 'lucide-react';
|
||||
import api from '../services/api';
|
||||
import PageLayout from '../layouts/PageLayout';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -8,6 +8,8 @@ import { useAuth } from '../contexts/useAuth.js';
|
||||
import { useNotifications } from '../contexts/useNotifications.js';
|
||||
import { timeAgo } from '../utils/time';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Sheet, SheetTrigger, SheetContent, SheetTitle } from '@/components/ui/sheet';
|
||||
import useMediaQuery from '../hooks/useMediaQuery';
|
||||
|
||||
const SEVERITY_DOT = {
|
||||
critical: '#fb6f6f',
|
||||
@@ -46,6 +48,8 @@ export default function Notifications() {
|
||||
const [unreadCount, setUnreadCount] = useState(0);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [hasMore, setHasMore] = useState(false);
|
||||
const compact = useMediaQuery('(max-width: 768px)');
|
||||
const activeFilters = (category ? 1 : 0) + (severity ? 1 : 0);
|
||||
|
||||
const fetchPage = useCallback(async (startOffset, replace) => {
|
||||
setLoading(true);
|
||||
@@ -89,6 +93,36 @@ export default function Notifications() {
|
||||
fetchPage(0, true);
|
||||
};
|
||||
|
||||
const categoryChips = (
|
||||
<div className="sk-notif-chipset" aria-label={t('app.notifications.filterByCategory', 'Filter by category')}>
|
||||
{CATEGORY_CHIPS.map((c) => (
|
||||
<Button variant="unstyled"
|
||||
type="button"
|
||||
key={c.key || 'all'}
|
||||
className={`sk-notif-chip${category === c.key ? ' is-active' : ''}`}
|
||||
onClick={() => setCategory(c.key)}
|
||||
>
|
||||
{c.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
const severityChips = (
|
||||
<div className="sk-notif-chipset" aria-label={t('app.notifications.filterBySeverity', 'Filter by severity')}>
|
||||
{SEVERITY_CHIPS.map((s) => (
|
||||
<Button variant="unstyled"
|
||||
type="button"
|
||||
key={s.key || 'any'}
|
||||
className={`sk-notif-chip sk-notif-chip--sev${severity === s.key ? ' is-active' : ''}`}
|
||||
onClick={() => setSeverity(s.key)}
|
||||
>
|
||||
{s.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
const chipsets = <>{categoryChips}{severityChips}</>;
|
||||
|
||||
// Live system notices (admin config hints) come from the shared context so they
|
||||
// surface here too, above the bus history.
|
||||
const noticeItems = (ctxItems || []).filter((it) => it.kind === 'notice');
|
||||
@@ -112,52 +146,51 @@ export default function Notifications() {
|
||||
)}
|
||||
>
|
||||
<div className="sk-notif-page">
|
||||
<div className="sk-notif-page__filters" role="tablist" aria-label={t('app.notifications.filterNotifications', 'Filter notifications')}>
|
||||
<Button variant="unstyled"
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={!unreadOnly}
|
||||
className={!unreadOnly ? 'is-active' : ''}
|
||||
onClick={() => setUnreadOnly(false)}
|
||||
>
|
||||
{t('common.labels.all', 'All')}
|
||||
</Button>
|
||||
<Button variant="unstyled"
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={unreadOnly}
|
||||
className={unreadOnly ? 'is-active' : ''}
|
||||
onClick={() => setUnreadOnly(true)}
|
||||
>
|
||||
{t('app.notifications.unread', 'Unread')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="sk-notif-page__chips">
|
||||
<div className="sk-notif-chipset" aria-label={t('app.notifications.filterByCategory', 'Filter by category')}>
|
||||
{CATEGORY_CHIPS.map((c) => (
|
||||
<Button variant="unstyled"
|
||||
type="button"
|
||||
key={c.key || 'all'}
|
||||
className={`sk-notif-chip${category === c.key ? ' is-active' : ''}`}
|
||||
onClick={() => setCategory(c.key)}
|
||||
>
|
||||
{c.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
<div className="sk-notif-chipset" aria-label={t('app.notifications.filterBySeverity', 'Filter by severity')}>
|
||||
{SEVERITY_CHIPS.map((s) => (
|
||||
<Button variant="unstyled"
|
||||
type="button"
|
||||
key={s.key || 'any'}
|
||||
className={`sk-notif-chip sk-notif-chip--sev${severity === s.key ? ' is-active' : ''}`}
|
||||
onClick={() => setSeverity(s.key)}
|
||||
>
|
||||
{s.label}
|
||||
</Button>
|
||||
))}
|
||||
<div className="sk-notif-page__toolbar">
|
||||
<div className="sk-notif-page__filters" role="tablist" aria-label={t('app.notifications.filterNotifications', 'Filter notifications')}>
|
||||
<Button variant="unstyled"
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={!unreadOnly}
|
||||
className={!unreadOnly ? 'is-active' : ''}
|
||||
onClick={() => setUnreadOnly(false)}
|
||||
>
|
||||
{t('common.labels.all', 'All')}
|
||||
</Button>
|
||||
<Button variant="unstyled"
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={unreadOnly}
|
||||
className={unreadOnly ? 'is-active' : ''}
|
||||
onClick={() => setUnreadOnly(true)}
|
||||
>
|
||||
{t('app.notifications.unread', 'Unread')}
|
||||
</Button>
|
||||
</div>
|
||||
{compact ? (
|
||||
<Sheet>
|
||||
<SheetTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="sk-notif-page__filter-btn" aria-label={t('app.notifications.filters', 'Filters')}>
|
||||
<Filter size={15} aria-hidden="true" />
|
||||
{activeFilters > 0 && <span className="sk-notif-page__filter-count">{activeFilters}</span>}
|
||||
</Button>
|
||||
</SheetTrigger>
|
||||
<SheetContent side="bottom" className="info-tip__sheet" overlayClassName="info-tip__overlay" aria-describedby={undefined}>
|
||||
<SheetTitle className="info-tip__sheet-title">{t('app.notifications.filters', 'Filters')}</SheetTitle>
|
||||
<div className="sk-notif-page__sheet">
|
||||
<span className="sk-notif-page__sheet-label">{t('app.notifications.category', 'Category')}</span>
|
||||
{categoryChips}
|
||||
<span className="sk-notif-page__sheet-label">{t('common.labels.severity', 'Severity')}</span>
|
||||
{severityChips}
|
||||
<Button variant="ghost" size="sm" disabled={!activeFilters} onClick={() => { setCategory(''); setSeverity(''); }}>
|
||||
{t('app.notifications.reset', 'Reset')}
|
||||
</Button>
|
||||
</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
) : (
|
||||
<div className="sk-notif-page__chips">{chipsets}</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{loading && items.length === 0 && noticeItems.length === 0 ? (
|
||||
|
||||
@@ -3,10 +3,36 @@
|
||||
.sk-notif-page {
|
||||
// Width and gutter come from the page shell, as on every page.
|
||||
|
||||
&__toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: $space-3;
|
||||
margin-bottom: $space-4;
|
||||
}
|
||||
|
||||
&__filter-btn { position: relative; margin-inline-start: auto; }
|
||||
|
||||
&__filter-count {
|
||||
margin-inline-start: $space-1;
|
||||
font-size: $text-xs;
|
||||
color: $accent-primary;
|
||||
}
|
||||
|
||||
&__sheet {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: $space-3;
|
||||
}
|
||||
|
||||
&__sheet-label {
|
||||
font-size: $text-xs;
|
||||
color: $text-secondary;
|
||||
}
|
||||
|
||||
&__filters {
|
||||
display: inline-flex;
|
||||
gap: $space-1;
|
||||
margin-bottom: $space-4;
|
||||
background: $bg-card;
|
||||
border: 1px solid $border-subtle;
|
||||
border-radius: $radius-card;
|
||||
@@ -334,9 +360,8 @@
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: $space-4;
|
||||
padding: 0 0 $space-3;
|
||||
margin-bottom: $space-2;
|
||||
border-bottom: 1px solid $border-subtle;
|
||||
padding-inline-start: $space-4;
|
||||
border-inline-start: 1px solid $border-subtle;
|
||||
}
|
||||
|
||||
.sk-notif-chipset {
|
||||
|
||||
Reference in new issue
Block a user