@commonpub/layer 0.10.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/components/EventCard.vue +121 -0
  2. package/components/PollDisplay.vue +108 -0
  3. package/components/PostVoteButtons.vue +108 -0
  4. package/components/contest/ContestJudgeManager.vue +110 -0
  5. package/components/homepage/ContentGridSection.vue +133 -0
  6. package/components/homepage/ContestsSection.vue +39 -0
  7. package/components/homepage/CustomHtmlSection.vue +20 -0
  8. package/components/homepage/EditorialSection.vue +32 -0
  9. package/components/homepage/HeroSection.vue +73 -0
  10. package/components/homepage/HomepageSectionRenderer.vue +64 -0
  11. package/components/homepage/HubsSection.vue +66 -0
  12. package/components/homepage/StatsSection.vue +38 -0
  13. package/components/nav/MobileNavRenderer.vue +94 -0
  14. package/components/nav/NavDropdown.vue +101 -0
  15. package/components/nav/NavLink.vue +40 -0
  16. package/components/nav/NavRenderer.vue +51 -0
  17. package/composables/useFeatures.ts +2 -0
  18. package/layouts/admin.vue +3 -0
  19. package/layouts/default.vue +22 -86
  20. package/middleware/feature-gate.global.ts +1 -0
  21. package/package.json +6 -6
  22. package/pages/admin/features.vue +338 -0
  23. package/pages/admin/homepage.vue +292 -0
  24. package/pages/admin/navigation.vue +350 -0
  25. package/pages/events/[slug]/edit.vue +182 -0
  26. package/pages/events/[slug]/index.vue +249 -0
  27. package/pages/events/create.vue +140 -0
  28. package/pages/events/index.vue +47 -0
  29. package/pages/index.vue +34 -1
  30. package/server/api/admin/features/index.get.ts +32 -0
  31. package/server/api/admin/features/index.put.ts +56 -0
  32. package/server/api/admin/homepage/sections.get.ts +11 -0
  33. package/server/api/admin/homepage/sections.put.ts +52 -0
  34. package/server/api/admin/navigation/items.get.ts +11 -0
  35. package/server/api/admin/navigation/items.put.ts +51 -0
  36. package/server/api/contests/[slug]/entries/[entryId]/vote.delete.ts +20 -0
  37. package/server/api/contests/[slug]/entries/[entryId]/vote.post.ts +20 -0
  38. package/server/api/contests/[slug]/judge.post.ts +5 -7
  39. package/server/api/contests/[slug]/judges/[userId].delete.ts +26 -0
  40. package/server/api/contests/[slug]/judges/accept.post.ts +21 -0
  41. package/server/api/contests/[slug]/judges/index.get.ts +17 -0
  42. package/server/api/contests/[slug]/judges/index.post.ts +36 -0
  43. package/server/api/events/[slug]/attendees.get.ts +23 -0
  44. package/server/api/events/[slug]/rsvp.delete.ts +23 -0
  45. package/server/api/events/[slug]/rsvp.post.ts +23 -0
  46. package/server/api/events/[slug].delete.ts +22 -0
  47. package/server/api/events/[slug].get.ts +17 -0
  48. package/server/api/events/[slug].put.ts +38 -0
  49. package/server/api/events/index.get.ts +21 -0
  50. package/server/api/events/index.post.ts +40 -0
  51. package/server/api/features.get.ts +9 -0
  52. package/server/api/homepage/sections.get.ts +10 -0
  53. package/server/api/hubs/[slug]/posts/[postId]/poll-options.get.ts +18 -0
  54. package/server/api/hubs/[slug]/posts/[postId]/poll-vote.post.ts +27 -0
  55. package/server/api/hubs/[slug]/posts/[postId]/vote.post.ts +21 -0
  56. package/server/api/navigation/items.get.ts +10 -0
  57. package/server/middleware/features.ts +1 -0
@@ -0,0 +1,121 @@
1
+ <script setup lang="ts">
2
+ import type { EventListItem } from '@commonpub/server';
3
+
4
+ const props = defineProps<{
5
+ event: EventListItem;
6
+ }>();
7
+
8
+ const statusClass = computed(() => {
9
+ const map: Record<string, string> = {
10
+ published: 'cpub-badge-accent',
11
+ active: 'cpub-badge-green',
12
+ completed: 'cpub-badge-dim',
13
+ cancelled: 'cpub-badge-red',
14
+ draft: 'cpub-badge-yellow',
15
+ };
16
+ return map[props.event.status] ?? 'cpub-badge-dim';
17
+ });
18
+
19
+ const typeIcon = computed(() => {
20
+ const map: Record<string, string> = {
21
+ 'in-person': 'fa-solid fa-location-dot',
22
+ 'online': 'fa-solid fa-video',
23
+ 'hybrid': 'fa-solid fa-arrows-split-up-and-left',
24
+ };
25
+ return map[props.event.eventType] ?? 'fa-solid fa-calendar';
26
+ });
27
+
28
+ function formatDate(date: string | Date): string {
29
+ return new Date(date).toLocaleDateString('en-US', {
30
+ month: 'short',
31
+ day: 'numeric',
32
+ year: 'numeric',
33
+ });
34
+ }
35
+
36
+ function formatTime(date: string | Date): string {
37
+ return new Date(date).toLocaleTimeString('en-US', {
38
+ hour: 'numeric',
39
+ minute: '2-digit',
40
+ });
41
+ }
42
+ </script>
43
+
44
+ <template>
45
+ <NuxtLink :to="`/events/${event.slug}`" class="cpub-event-card">
46
+ <div v-if="event.coverImage" class="cpub-event-cover">
47
+ <img :src="event.coverImage" :alt="event.title" />
48
+ </div>
49
+ <div class="cpub-event-body">
50
+ <div class="cpub-event-header">
51
+ <span class="cpub-badge" :class="statusClass">{{ event.status }}</span>
52
+ <span v-if="event.isFeatured" class="cpub-badge cpub-badge-accent"><i class="fa-solid fa-star"></i> Featured</span>
53
+ </div>
54
+ <div class="cpub-event-date">
55
+ <i class="fa-solid fa-calendar"></i>
56
+ {{ formatDate(event.startDate) }} at {{ formatTime(event.startDate) }}
57
+ </div>
58
+ <h3 class="cpub-event-title">{{ event.title }}</h3>
59
+ <p v-if="event.description" class="cpub-event-desc">{{ event.description }}</p>
60
+ <div class="cpub-event-meta">
61
+ <span><i :class="typeIcon"></i> {{ event.eventType }}</span>
62
+ <span v-if="event.location"><i class="fa-solid fa-map-pin"></i> {{ event.location }}</span>
63
+ <span><i class="fa-solid fa-users"></i> {{ event.attendeeCount }}{{ event.capacity ? ` / ${event.capacity}` : '' }}</span>
64
+ </div>
65
+ </div>
66
+ </NuxtLink>
67
+ </template>
68
+
69
+ <style scoped>
70
+ .cpub-event-card {
71
+ display: flex;
72
+ flex-direction: column;
73
+ border: var(--border-width-default) solid var(--border);
74
+ background: var(--surface);
75
+ text-decoration: none;
76
+ color: var(--text);
77
+ transition: box-shadow 0.15s, transform 0.15s;
78
+ box-shadow: var(--shadow-md);
79
+ overflow: hidden;
80
+ }
81
+ .cpub-event-card:hover { box-shadow: var(--shadow-lg); transform: translate(-1px, -1px); }
82
+
83
+ .cpub-event-cover { height: 140px; overflow: hidden; }
84
+ .cpub-event-cover img { width: 100%; height: 100%; object-fit: cover; }
85
+
86
+ .cpub-event-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
87
+
88
+ .cpub-event-header { display: flex; gap: 6px; flex-wrap: wrap; }
89
+
90
+ .cpub-event-date {
91
+ font-family: var(--font-mono);
92
+ font-size: 11px;
93
+ color: var(--accent);
94
+ display: flex;
95
+ align-items: center;
96
+ gap: 6px;
97
+ }
98
+ .cpub-event-date i { font-size: 10px; }
99
+
100
+ .cpub-event-title { font-size: 15px; font-weight: 600; margin: 0; }
101
+
102
+ .cpub-event-desc {
103
+ font-size: 12px;
104
+ color: var(--text-dim);
105
+ display: -webkit-box;
106
+ -webkit-line-clamp: 2;
107
+ -webkit-box-orient: vertical;
108
+ overflow: hidden;
109
+ }
110
+
111
+ .cpub-event-meta {
112
+ display: flex;
113
+ flex-wrap: wrap;
114
+ gap: 12px;
115
+ font-size: 11px;
116
+ color: var(--text-faint);
117
+ font-family: var(--font-mono);
118
+ margin-top: 4px;
119
+ }
120
+ .cpub-event-meta i { font-size: 10px; margin-right: 3px; }
121
+ </style>
@@ -0,0 +1,108 @@
1
+ <script setup lang="ts">
2
+ import type { PollOptionResult } from '@commonpub/server';
3
+
4
+ const props = defineProps<{
5
+ hubSlug: string;
6
+ postId: string;
7
+ }>();
8
+
9
+ const { isAuthenticated } = useAuth();
10
+ const toast = useToast();
11
+ const loading = ref(false);
12
+
13
+ const { data, refresh } = await useFetch<{ options: PollOptionResult[]; userVote: string | null }>(
14
+ `/api/hubs/${props.hubSlug}/posts/${props.postId}/poll-options`,
15
+ );
16
+
17
+ const totalVotes = computed(() => {
18
+ if (!data.value) return 0;
19
+ return data.value.options.reduce((sum, opt) => sum + opt.voteCount, 0);
20
+ });
21
+
22
+ const hasVoted = computed(() => !!data.value?.userVote);
23
+
24
+ function percentage(count: number): number {
25
+ if (totalVotes.value === 0) return 0;
26
+ return Math.round((count / totalVotes.value) * 100);
27
+ }
28
+
29
+ async function vote(optionId: string): Promise<void> {
30
+ if (!isAuthenticated.value || loading.value || hasVoted.value) return;
31
+ loading.value = true;
32
+ try {
33
+ await $fetch(`/api/hubs/${props.hubSlug}/posts/${props.postId}/poll-vote`, {
34
+ method: 'POST',
35
+ body: { optionId },
36
+ });
37
+ await refresh();
38
+ } catch {
39
+ toast.error('Failed to submit vote');
40
+ } finally {
41
+ loading.value = false;
42
+ }
43
+ }
44
+ </script>
45
+
46
+ <template>
47
+ <div v-if="data?.options?.length" class="cpub-poll" role="group" aria-label="Poll">
48
+ <button
49
+ v-for="option in data.options"
50
+ :key="option.id"
51
+ type="button"
52
+ class="cpub-poll-option"
53
+ :class="{ voted: data.userVote === option.id, clickable: !hasVoted && isAuthenticated }"
54
+ :disabled="hasVoted || !isAuthenticated"
55
+ :aria-pressed="data.userVote === option.id"
56
+ :aria-label="`${option.label}${hasVoted ? ` — ${percentage(option.voteCount)}%` : ''}`"
57
+ @click="vote(option.id)"
58
+ >
59
+ <div class="cpub-poll-bar" :style="{ width: hasVoted || !isAuthenticated ? `${percentage(option.voteCount)}%` : '0%' }" />
60
+ <span class="cpub-poll-label">{{ option.label }}</span>
61
+ <span v-if="hasVoted || !isAuthenticated" class="cpub-poll-pct">{{ percentage(option.voteCount) }}%</span>
62
+ </button>
63
+ <div class="cpub-poll-meta">
64
+ {{ totalVotes }} vote{{ totalVotes !== 1 ? 's' : '' }}
65
+ </div>
66
+ </div>
67
+ </template>
68
+
69
+ <style scoped>
70
+ .cpub-poll { display: flex; flex-direction: column; gap: 6px; }
71
+
72
+ .cpub-poll-option {
73
+ position: relative;
74
+ padding: 8px 12px;
75
+ border: var(--border-width-default) solid var(--border);
76
+ background: transparent;
77
+ font-size: 13px;
78
+ font-family: inherit;
79
+ color: var(--text);
80
+ display: flex;
81
+ align-items: center;
82
+ gap: 8px;
83
+ overflow: hidden;
84
+ transition: border-color 0.12s;
85
+ text-align: left;
86
+ width: 100%;
87
+ }
88
+ .cpub-poll-option.clickable { cursor: pointer; }
89
+ .cpub-poll-option.clickable:hover { border-color: var(--accent); }
90
+ .cpub-poll-option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
91
+ .cpub-poll-option.voted { border-color: var(--accent); font-weight: 600; }
92
+ .cpub-poll-option:disabled:not(.voted) { opacity: 0.7; cursor: default; }
93
+
94
+ .cpub-poll-bar {
95
+ position: absolute;
96
+ left: 0;
97
+ top: 0;
98
+ bottom: 0;
99
+ background: var(--accent-bg);
100
+ transition: width 0.3s ease;
101
+ z-index: 0;
102
+ }
103
+
104
+ .cpub-poll-label { position: relative; z-index: 1; flex: 1; }
105
+ .cpub-poll-pct { position: relative; z-index: 1; font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }
106
+
107
+ .cpub-poll-meta { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); margin-top: 2px; }
108
+ </style>
@@ -0,0 +1,108 @@
1
+ <script setup lang="ts">
2
+ import type { VoteDirection } from '@commonpub/server';
3
+
4
+ const props = defineProps<{
5
+ hubSlug: string;
6
+ postId: string;
7
+ voteScore: number;
8
+ userVote?: VoteDirection | null;
9
+ }>();
10
+
11
+ const emit = defineEmits<{
12
+ voted: [result: { voteScore: number; direction: VoteDirection | null }];
13
+ }>();
14
+
15
+ const { isAuthenticated } = useAuth();
16
+ const toast = useToast();
17
+ const loading = ref(false);
18
+ const currentScore = ref(props.voteScore);
19
+ const currentVote = ref<VoteDirection | null>(props.userVote ?? null);
20
+
21
+ watch(() => props.voteScore, (v) => { currentScore.value = v; });
22
+ watch(() => props.userVote, (v) => { currentVote.value = v ?? null; });
23
+
24
+ async function vote(direction: VoteDirection): Promise<void> {
25
+ if (!isAuthenticated.value || loading.value) return;
26
+ loading.value = true;
27
+ try {
28
+ const result = await $fetch<{ voted: boolean; direction: VoteDirection | null; voteScore: number }>(
29
+ `/api/hubs/${props.hubSlug}/posts/${props.postId}/vote`,
30
+ { method: 'POST', body: { direction } },
31
+ );
32
+ currentScore.value = result.voteScore;
33
+ currentVote.value = result.direction;
34
+ emit('voted', { voteScore: result.voteScore, direction: result.direction });
35
+ } catch {
36
+ toast.error('Vote failed');
37
+ } finally {
38
+ loading.value = false;
39
+ }
40
+ }
41
+ </script>
42
+
43
+ <template>
44
+ <div class="cpub-vote-buttons">
45
+ <button
46
+ class="cpub-vote-btn cpub-vote-up"
47
+ :class="{ active: currentVote === 'up' }"
48
+ :disabled="!isAuthenticated || loading"
49
+ :aria-pressed="currentVote === 'up'"
50
+ aria-label="Upvote"
51
+ @click="vote('up')"
52
+ >
53
+ <i class="fa-solid fa-chevron-up"></i>
54
+ </button>
55
+ <span class="cpub-vote-score" :class="{ positive: currentScore > 0, negative: currentScore < 0 }">
56
+ {{ currentScore }}
57
+ </span>
58
+ <button
59
+ class="cpub-vote-btn cpub-vote-down"
60
+ :class="{ active: currentVote === 'down' }"
61
+ :disabled="!isAuthenticated || loading"
62
+ :aria-pressed="currentVote === 'down'"
63
+ aria-label="Downvote"
64
+ @click="vote('down')"
65
+ >
66
+ <i class="fa-solid fa-chevron-down"></i>
67
+ </button>
68
+ </div>
69
+ </template>
70
+
71
+ <style scoped>
72
+ .cpub-vote-buttons {
73
+ display: flex;
74
+ flex-direction: column;
75
+ align-items: center;
76
+ gap: 2px;
77
+ }
78
+
79
+ .cpub-vote-btn {
80
+ width: 28px;
81
+ height: 24px;
82
+ display: flex;
83
+ align-items: center;
84
+ justify-content: center;
85
+ background: none;
86
+ border: var(--border-width-default) solid transparent;
87
+ color: var(--text-faint);
88
+ font-size: 11px;
89
+ cursor: pointer;
90
+ transition: all 0.12s;
91
+ }
92
+ .cpub-vote-btn:hover:not(:disabled) { color: var(--text); background: var(--surface2); }
93
+ .cpub-vote-btn:disabled { opacity: 0.3; cursor: default; }
94
+ .cpub-vote-btn.active { color: var(--accent); }
95
+ .cpub-vote-up.active { color: var(--green, var(--accent)); }
96
+ .cpub-vote-down.active { color: var(--red, var(--accent)); }
97
+
98
+ .cpub-vote-score {
99
+ font-family: var(--font-mono);
100
+ font-size: 12px;
101
+ font-weight: 700;
102
+ color: var(--text-dim);
103
+ min-width: 20px;
104
+ text-align: center;
105
+ }
106
+ .cpub-vote-score.positive { color: var(--green, var(--accent)); }
107
+ .cpub-vote-score.negative { color: var(--red); }
108
+ </style>
@@ -0,0 +1,110 @@
1
+ <script setup lang="ts">
2
+ import type { ContestJudgeItem } from '@commonpub/server';
3
+
4
+ const props = defineProps<{
5
+ contestSlug: string;
6
+ isOwner: boolean;
7
+ }>();
8
+
9
+ const toast = useToast();
10
+ const { data: judges, refresh } = await useFetch<ContestJudgeItem[]>(
11
+ `/api/contests/${props.contestSlug}/judges`,
12
+ );
13
+
14
+ const newJudgeId = ref('');
15
+ const newJudgeRole = ref<'lead' | 'judge' | 'guest'>('judge');
16
+ const adding = ref(false);
17
+
18
+ async function addJudge(): Promise<void> {
19
+ if (!newJudgeId.value) return;
20
+ adding.value = true;
21
+ try {
22
+ await $fetch(`/api/contests/${props.contestSlug}/judges`, {
23
+ method: 'POST',
24
+ body: { userId: newJudgeId.value, role: newJudgeRole.value },
25
+ });
26
+ toast.success('Judge added');
27
+ newJudgeId.value = '';
28
+ await refresh();
29
+ } catch {
30
+ toast.error('Failed to add judge');
31
+ } finally {
32
+ adding.value = false;
33
+ }
34
+ }
35
+
36
+ async function removeJudge(userId: string): Promise<void> {
37
+ if (!confirm('Remove this judge?')) return;
38
+ try {
39
+ await $fetch(`/api/contests/${props.contestSlug}/judges/${userId}`, { method: 'DELETE' });
40
+ toast.success('Judge removed');
41
+ await refresh();
42
+ } catch {
43
+ toast.error('Failed to remove judge');
44
+ }
45
+ }
46
+
47
+ const roleLabels: Record<string, string> = {
48
+ lead: 'Lead Judge',
49
+ judge: 'Judge',
50
+ guest: 'Guest Judge',
51
+ };
52
+ </script>
53
+
54
+ <template>
55
+ <div class="cpub-contest-judges">
56
+ <h3 class="cpub-judges-title">Judges</h3>
57
+
58
+ <div v-if="judges?.length" class="cpub-judges-list">
59
+ <div v-for="judge in judges" :key="judge.id" class="cpub-judge-row">
60
+ <NuxtLink :to="`/u/${judge.userUsername}`" class="cpub-judge-link">
61
+ <span class="cpub-judge-avatar">
62
+ <img v-if="judge.userAvatar" :src="judge.userAvatar" :alt="judge.userName" />
63
+ <span v-else>{{ judge.userName.charAt(0) }}</span>
64
+ </span>
65
+ <span class="cpub-judge-name">{{ judge.userName }}</span>
66
+ </NuxtLink>
67
+ <span class="cpub-judge-role">{{ roleLabels[judge.role] || judge.role }}</span>
68
+ <span v-if="!judge.acceptedAt" class="cpub-judge-pending">Pending</span>
69
+ <button v-if="isOwner" class="cpub-judge-remove" :aria-label="`Remove ${judge.userName} from judges`" @click="removeJudge(judge.userId)">
70
+ <i class="fa-solid fa-xmark"></i>
71
+ </button>
72
+ </div>
73
+ </div>
74
+ <p v-else class="cpub-judges-empty">No judges assigned yet.</p>
75
+
76
+ <div v-if="isOwner" class="cpub-judges-add">
77
+ <input v-model="newJudgeId" class="cpub-judges-input" placeholder="User ID" />
78
+ <select v-model="newJudgeRole" class="cpub-judges-input cpub-judges-select">
79
+ <option value="lead">Lead</option>
80
+ <option value="judge">Judge</option>
81
+ <option value="guest">Guest</option>
82
+ </select>
83
+ <button class="cpub-btn cpub-btn-sm" :disabled="adding || !newJudgeId" @click="addJudge">
84
+ <i class="fa-solid fa-plus"></i> Add
85
+ </button>
86
+ </div>
87
+ </div>
88
+ </template>
89
+
90
+ <style scoped>
91
+ .cpub-judges-title { font-family: var(--font-mono); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-faint); margin: 0 0 12px; }
92
+
93
+ .cpub-judges-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
94
+ .cpub-judge-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
95
+ .cpub-judge-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); flex: 1; min-width: 0; }
96
+ .cpub-judge-avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--surface2); border: var(--border-width-default) solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; overflow: hidden; flex-shrink: 0; }
97
+ .cpub-judge-avatar img { width: 100%; height: 100%; object-fit: cover; }
98
+ .cpub-judge-name { font-size: 12px; font-weight: 600; }
99
+ .cpub-judge-role { font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; color: var(--text-faint); }
100
+ .cpub-judge-pending { font-family: var(--font-mono); font-size: 9px; color: var(--yellow, var(--text-faint)); }
101
+ .cpub-judge-remove { background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 10px; padding: 4px; }
102
+ .cpub-judge-remove:hover { color: var(--red); }
103
+
104
+ .cpub-judges-empty { font-size: 12px; color: var(--text-faint); font-style: italic; margin-bottom: 12px; }
105
+
106
+ .cpub-judges-add { display: flex; gap: 6px; align-items: center; }
107
+ .cpub-judges-input { font-size: 12px; padding: 4px 8px; border: var(--border-width-default) solid var(--border); background: var(--bg); color: var(--text); outline: none; }
108
+ .cpub-judges-input:focus { border-color: var(--accent); }
109
+ .cpub-judges-select { max-width: 100px; }
110
+ </style>
@@ -0,0 +1,133 @@
1
+ <script setup lang="ts">
2
+ import type { Serialized, ContentListItem, PaginatedResponse } from '@commonpub/server';
3
+ import type { HomepageSectionConfig } from '@commonpub/server';
4
+
5
+ const props = defineProps<{
6
+ config: HomepageSectionConfig;
7
+ title?: string;
8
+ }>();
9
+
10
+ const { user: authUser } = useAuth();
11
+ const { enabledTypeMeta } = useContentTypes();
12
+ const toast = useToast();
13
+
14
+ const activeTab = ref(authUser.value ? 'foryou' : 'latest');
15
+ const tabs = computed(() => [
16
+ { value: 'foryou', label: 'For You', icon: 'fa-solid fa-sparkles' },
17
+ { value: 'latest', label: 'Latest', icon: 'fa-solid fa-clock' },
18
+ { value: 'following', label: 'Following', icon: 'fa-solid fa-user-group' },
19
+ ...enabledTypeMeta.value.map(ct => ({ value: ct.type, label: ct.plural, icon: ct.icon })),
20
+ ]);
21
+
22
+ const limit = computed(() => props.config.limit ?? 12);
23
+
24
+ const contentQuery = computed(() => ({
25
+ status: 'published',
26
+ type: ['foryou', 'latest', 'following'].includes(activeTab.value)
27
+ ? (props.config.contentType || undefined)
28
+ : activeTab.value,
29
+ sort: activeTab.value === 'latest' ? 'recent' : activeTab.value === 'following' ? 'recent' : (props.config.sort ?? 'popular'),
30
+ ...(activeTab.value === 'following' && authUser.value?.id ? { followedBy: authUser.value.id } : {}),
31
+ ...(props.config.categorySlug ? { categorySlug: props.config.categorySlug } : {}),
32
+ limit: limit.value,
33
+ }));
34
+
35
+ const { data: feed, pending: feedPending } = await useFetch<PaginatedResponse<Serialized<ContentListItem>>>('/api/content', {
36
+ query: contentQuery,
37
+ watch: [contentQuery],
38
+ });
39
+
40
+ const loadingMore = ref(false);
41
+ const allLoaded = ref(false);
42
+
43
+ watch(activeTab, () => { allLoaded.value = false; });
44
+
45
+ async function loadMore(): Promise<void> {
46
+ loadingMore.value = true;
47
+ try {
48
+ const nextOffset = (feed.value?.items?.length ?? 0);
49
+ const more = await $fetch<PaginatedResponse<Serialized<ContentListItem>>>('/api/content', {
50
+ query: { ...contentQuery.value, offset: nextOffset },
51
+ });
52
+ if (more.items?.length && feed.value?.items) {
53
+ feed.value.items.push(...more.items);
54
+ }
55
+ if (!more.items?.length || more.items.length < limit.value) {
56
+ allLoaded.value = true;
57
+ }
58
+ } catch {
59
+ toast.error('Failed to load more');
60
+ } finally {
61
+ loadingMore.value = false;
62
+ }
63
+ }
64
+
65
+ const isAuthenticated = computed(() => !!authUser.value);
66
+ const columns = computed(() => props.config.columns ?? 2);
67
+ </script>
68
+
69
+ <template>
70
+ <div>
71
+ <!-- Tabs -->
72
+ <div class="cpub-tabs-bar">
73
+ <div class="cpub-tabs-inner">
74
+ <button
75
+ v-for="tab in tabs"
76
+ :key="tab.value"
77
+ class="cpub-tab"
78
+ :class="{ active: activeTab === tab.value }"
79
+ @click="activeTab = tab.value"
80
+ >
81
+ {{ tab.label }}
82
+ </button>
83
+ </div>
84
+ </div>
85
+
86
+ <!-- Grid -->
87
+ <div v-if="feedPending" class="cpub-loading-state">
88
+ <i class="fa-solid fa-circle-notch fa-spin"></i> Loading content...
89
+ </div>
90
+ <div v-else-if="feed?.items?.length" class="cpub-content-grid" :style="{ '--grid-cols': columns }">
91
+ <ContentCard v-for="item in feed.items" :key="item.id" :item="item" />
92
+ </div>
93
+ <div v-else class="cpub-empty-state">
94
+ <div class="cpub-empty-state-icon"><i :class="activeTab === 'following' ? 'fa-solid fa-user-group' : 'fa-solid fa-inbox'"></i></div>
95
+ <template v-if="activeTab === 'following' && !isAuthenticated">
96
+ <p class="cpub-empty-state-title">Sign in to see your feed</p>
97
+ <p class="cpub-empty-state-desc">Follow creators to see their content here.</p>
98
+ <NuxtLink to="/auth/login" class="cpub-btn cpub-btn-primary" style="margin-top: 12px;">Sign In</NuxtLink>
99
+ </template>
100
+ <template v-else-if="activeTab === 'following'">
101
+ <p class="cpub-empty-state-title">No posts from people you follow</p>
102
+ <NuxtLink to="/explore" class="cpub-btn" style="margin-top: 12px;"><i class="fa-solid fa-compass"></i> Explore</NuxtLink>
103
+ </template>
104
+ <template v-else>
105
+ <p class="cpub-empty-state-title">No content yet</p>
106
+ <p class="cpub-empty-state-desc">Be the first to create something!</p>
107
+ </template>
108
+ </div>
109
+
110
+ <div v-if="!allLoaded && feed?.items?.length" class="cpub-load-more-row">
111
+ <button class="cpub-btn-load-more" :disabled="loadingMore" @click="loadMore">
112
+ <i :class="loadingMore ? 'fa-solid fa-circle-notch fa-spin' : 'fa-solid fa-rotate'"></i>
113
+ {{ loadingMore ? 'Loading...' : 'Load more' }}
114
+ </button>
115
+ </div>
116
+ </div>
117
+ </template>
118
+
119
+ <style scoped>
120
+ .cpub-tabs-bar { border-bottom: var(--border-width-default) solid var(--border); margin-bottom: 0; }
121
+ .cpub-tabs-inner { display: flex; max-width: var(--content-max-width, 1280px); margin: 0 auto; padding: 0 var(--space-4); overflow-x: auto; }
122
+ .cpub-tab { padding: 10px 16px; font-family: var(--font-mono); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); background: none; border: none; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
123
+ .cpub-tab:hover { color: var(--text); }
124
+ .cpub-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
125
+
126
+ .cpub-content-grid { display: grid; grid-template-columns: repeat(var(--grid-cols, 2), 1fr); gap: 16px; }
127
+
128
+ .cpub-load-more-row { text-align: center; padding: 24px 0; }
129
+ .cpub-btn-load-more { font-family: var(--font-mono); font-size: 11px; padding: 8px 20px; border: var(--border-width-default) solid var(--border); background: var(--surface); color: var(--text-dim); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
130
+ .cpub-btn-load-more:hover { border-color: var(--accent); color: var(--accent); }
131
+
132
+ @media (max-width: 768px) { .cpub-content-grid { grid-template-columns: 1fr; } }
133
+ </style>
@@ -0,0 +1,39 @@
1
+ <script setup lang="ts">
2
+ import type { HomepageSectionConfig } from '@commonpub/server';
3
+
4
+ const props = defineProps<{ config: HomepageSectionConfig }>();
5
+
6
+ const limit = computed(() => props.config.limit ?? 3);
7
+ const { data: contests } = await useFetch('/api/contests', { query: { limit }, lazy: true });
8
+ </script>
9
+
10
+ <template>
11
+ <div v-if="contests?.items?.length" class="cpub-sb-card">
12
+ <div class="cpub-sb-head">Active Contests <NuxtLink to="/contests">View all</NuxtLink></div>
13
+ <div v-for="c in contests.items" :key="c.id" class="cpub-contest-item">
14
+ <NuxtLink :to="`/contests/${c.slug}`" class="cpub-contest-name">{{ c.title }}</NuxtLink>
15
+ <div class="cpub-contest-row">
16
+ <span class="cpub-contest-entries">{{ c.entryCount ?? 0 }} entries</span>
17
+ <span v-if="c.endDate" class="cpub-contest-deadline">
18
+ <i class="fa-regular fa-clock"></i> {{ Math.max(0, Math.ceil((new Date(c.endDate).getTime() - Date.now()) / 86400000)) }}d left
19
+ </span>
20
+ </div>
21
+ <NuxtLink :to="`/contests/${c.slug}`" class="cpub-btn-enter">Enter Contest</NuxtLink>
22
+ </div>
23
+ </div>
24
+ </template>
25
+
26
+ <style scoped>
27
+ .cpub-sb-card { background: var(--surface); border: var(--border-width-default) solid var(--border); padding: 16px; margin-bottom: 16px; }
28
+ .cpub-sb-head { font-family: var(--font-mono); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); padding-bottom: 10px; border-bottom: var(--border-width-default) solid var(--border2); margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
29
+ .cpub-sb-head a { color: var(--accent); text-decoration: none; font-size: 10px; }
30
+ .cpub-contest-item { padding: 8px 0; border-bottom: var(--border-width-default) solid var(--border2); }
31
+ .cpub-contest-item:last-child { border-bottom: none; }
32
+ .cpub-contest-name { font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none; display: block; margin-bottom: 4px; }
33
+ .cpub-contest-name:hover { color: var(--accent); }
34
+ .cpub-contest-row { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
35
+ .cpub-contest-entries { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); }
36
+ .cpub-contest-deadline { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); display: flex; align-items: center; gap: 4px; }
37
+ .cpub-btn-enter { font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; padding: 4px 10px; border: var(--border-width-default) solid var(--accent); color: var(--accent); text-decoration: none; display: inline-block; }
38
+ .cpub-btn-enter:hover { background: var(--accent-bg); }
39
+ </style>
@@ -0,0 +1,20 @@
1
+ <script setup lang="ts">
2
+ import type { HomepageSectionConfig } from '@commonpub/server';
3
+
4
+ const props = defineProps<{
5
+ config: HomepageSectionConfig;
6
+ title?: string;
7
+ }>();
8
+ </script>
9
+
10
+ <template>
11
+ <section v-if="config.html" class="cpub-custom-section">
12
+ <h2 v-if="title" class="cpub-custom-title">{{ title }}</h2>
13
+ <div class="cpub-custom-content" v-html="config.html" />
14
+ </section>
15
+ </template>
16
+
17
+ <style scoped>
18
+ .cpub-custom-section { margin-bottom: 24px; }
19
+ .cpub-custom-title { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 12px; }
20
+ </style>
@@ -0,0 +1,32 @@
1
+ <script setup lang="ts">
2
+ import type { Serialized, ContentListItem, PaginatedResponse } from '@commonpub/server';
3
+ import type { HomepageSectionConfig } from '@commonpub/server';
4
+
5
+ const props = defineProps<{ config: HomepageSectionConfig }>();
6
+
7
+ const limit = computed(() => props.config.limit ?? 3);
8
+ const { data: editorialPicks } = await useFetch<PaginatedResponse<Serialized<ContentListItem>>>('/api/content', {
9
+ query: { status: 'published', editorial: true, sort: 'editorial', limit },
10
+ });
11
+ </script>
12
+
13
+ <template>
14
+ <section v-if="editorialPicks?.items?.length" class="cpub-editorial-section">
15
+ <div class="cpub-editorial-header">
16
+ <h2 class="cpub-editorial-heading"><i class="fa-solid fa-pen-fancy"></i> Staff Picks</h2>
17
+ </div>
18
+ <div class="cpub-editorial-grid" :class="{ 'cpub-editorial-single': editorialPicks.items.length === 1 }">
19
+ <ContentCard v-for="item in editorialPicks.items" :key="item.id" :item="item" />
20
+ </div>
21
+ </section>
22
+ </template>
23
+
24
+ <style scoped>
25
+ .cpub-editorial-section { margin-bottom: 24px; }
26
+ .cpub-editorial-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
27
+ .cpub-editorial-heading { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--teal); display: flex; align-items: center; gap: 6px; }
28
+ .cpub-editorial-heading i { font-size: 10px; }
29
+ .cpub-editorial-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
30
+ .cpub-editorial-single { grid-template-columns: 1fr; max-width: 400px; }
31
+ @media (max-width: 768px) { .cpub-editorial-grid { grid-template-columns: 1fr; } }
32
+ </style>