Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import i18n from '@/i18n';
import { useAuth } from '@/contexts/AuthContext';
import { useMyEventsViewModel, type MyEventsTab } from '@/viewmodels/event/useMyEventsViewModel';
import type { EventSummary } from '@/models/profile';
import { EventCoverImage } from '@/components/EventCoverImage';
import { RatingWithCount } from '@/components/RatingWithCount';
import { getEventCategoryPresentation } from '@/utils/eventCategoryPresentation';
import { getEventCardBadgePresentation } from '@/utils/eventStatus';
import { useTheme } from '@/contexts/ThemeContext';
import '@/styles/my-events.css';
import '@/styles/discover.css';
function formatDate(iso: string): string {
const d = new Date(iso);
return d.toLocaleDateString(i18n.resolvedLanguage, {
weekday: 'short',
month: 'short',
day: 'numeric',
});
}
function formatTime(iso: string): string {
const d = new Date(iso);
return d.toLocaleTimeString(i18n.resolvedLanguage, {
hour: '2-digit',
minute: '2-digit',
hour12: false,
});
}
function EventCard({ event }: { event: EventSummary }) {
const { t } = useTranslation();
const { theme } = useTheme();
const badge = getEventCardBadgePresentation(event.status);
const categoryPresentation = getEventCategoryPresentation(event.category_name ?? event.category ?? 'Event', theme === 'dark');
const participantCount = event.approved_participant_count ?? event.participants_count ?? 0;
return (
<Link to={`/events/${event.id}`} className="dc-card">
<div className="dc-card-image-wrapper">
<EventCoverImage
src={event.image_url}
alt={event.title}
imgClassName="dc-card-image"
variant="card"
/>
{badge && (
<span
className={`dc-lifecycle-badge ${
badge.variant === 'upcoming'
? 'dc-lifecycle-upcoming'
: badge.variant === 'in_progress'
? 'dc-lifecycle-in-progress'
: badge.variant === 'canceled'
? 'dc-lifecycle-canceled'
: 'dc-lifecycle-completed'
}`}
>
{badge.label}
</span>
)}
{event.privacy_level && event.privacy_level !== 'PRIVATE' && (
<span className={`dc-privacy-badge dc-privacy-${event.privacy_level.toLowerCase()}`}>
{t(`events.privacy.${event.privacy_level}`)}
</span>
)}
</div>
<div className="dc-card-body">
<div className="dc-card-meta">
<span className="dc-card-category">{categoryPresentation.label}</span>
<span className="dc-card-date">
{formatDate(event.start_time)} · {formatTime(event.start_time)}
</span>
</div>
<h3 className="dc-card-title">{event.title}</h3>
{event.location_address && (
<p className="dc-card-location">{event.location_address}</p>
)}
<div className="dc-card-footer">
<span className="dc-card-participants">
{t('events.my_events.participants', { count: participantCount })}
</span>
{event.host_score && (
<RatingWithCount
score={event.host_score.final_score}
count={event.host_score.hosted_event_rating_count}
className="dc-card-score"
/>
)}
</div>
</div>
</Link>
);
}
function EventList({ events, emptyMessage }: { events: EventSummary[]; emptyMessage: string }) {
if (events.length === 0) {
return (
<div className="me-empty">
<p>{emptyMessage}</p>
</div>
);
}
return (
<div className="me-grid">
{events.map((event) => (
<EventCard key={event.id} event={event} />
))}
</div>
);
}
export default function MyEventsPage() {
const { t } = useTranslation();
const { token } = useAuth();
const vm = useMyEventsViewModel(token);
const tabs: { key: MyEventsTab; label: string }[] = [
{ key: 'active', label: t('events.my_events.tab_active') },
{ key: 'upcoming', label: t('events.my_events.tab_upcoming') },
{ key: 'organized', label: t('events.my_events.tab_hosted') },
{ key: 'past', label: t('events.my_events.tab_past') },
{ key: 'canceled', label: t('events.my_events.tab_canceled') },
];
const counts: Record<MyEventsTab, number> = {
organized: vm.organized.length,
upcoming: vm.upcoming.length,
active: vm.active.length,
past: vm.past.length,
canceled: vm.canceled.length,
};
return (
<div className="me-page">
<h1 className="me-title">{t('events.my_events.title')}</h1>
<p className="me-subtitle">{t('events.my_events.subtitle')}</p>
{/* Tabs */}
<div className="me-tabs">
{tabs.map((tab) => (
<button
key={tab.key}
type="button"
className={`me-tab ${vm.activeTab === tab.key ? 'active' : ''}`}
onClick={() => vm.setActiveTab(tab.key)}
>
{tab.label}
{!vm.isLoading && (
<span className="me-tab-count">{counts[tab.key]}</span>
)}
</button>
))}
</div>
{/* Loading */}
{vm.isLoading && (
<div className="me-loading">
<span className="spinner" />
<p>{t('events.my_events.loading')}</p>
</div>
)}
{/* Error */}
{vm.error && (
<div className="me-error">
<p>{vm.error}</p>
<button type="button" className="me-retry-btn" onClick={vm.retry}>
Retry
</button>
</div>
)}
{/* Content */}
{!vm.isLoading && !vm.error && (
<>
{vm.activeTab === 'active' && (
<EventList
events={vm.active}
emptyMessage={t('events.my_events.empty_active')}
/>
)}
{vm.activeTab === 'upcoming' && (
<EventList
events={vm.upcoming}
emptyMessage={t('events.my_events.empty_upcoming')}
/>
)}
{vm.activeTab === 'organized' && (
<EventList
events={vm.organized}
emptyMessage={t('events.my_events.empty_hosted')}
/>
)}
{vm.activeTab === 'past' && (
<EventList
events={vm.past}
emptyMessage={t('events.my_events.empty_past')}
/>
)}
{vm.activeTab === 'canceled' && (
<EventList
events={vm.canceled}
emptyMessage={t('events.my_events.empty_canceled')}
/>
)}
</>
)}
</div>
);
}
|