@open-commune/web 0.2.15 → 0.2.17

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.
@@ -0,0 +1,29 @@
1
+ <template>
2
+ <ul class="space-y-1 text-sm">
3
+ <li v-for="row in rows" :key="row.name" class="relative flex h-7 items-center justify-between gap-3 px-2">
4
+ <span
5
+ class="absolute inset-y-0 left-0 rounded-md bg-primary/10"
6
+ :style="{ width: `${Math.max(2, (row.value / max) * 100)}%` }"
7
+ aria-hidden="true"
8
+ />
9
+ <NuxtLink v-if="row.link" :to="row.link" class="relative truncate text-default hover:text-highlighted hover:underline">
10
+ {{ row.name }}
11
+ </NuxtLink>
12
+ <span v-else class="relative truncate text-default">{{ row.name }}</span>
13
+ <span class="relative shrink-0 tabular-nums text-muted">{{ row.label ?? row.value }}</span>
14
+ </li>
15
+ </ul>
16
+ </template>
17
+
18
+ <script setup lang="ts">
19
+ /**
20
+ * A bar list: one row per item, a bar behind it as long as its share of the
21
+ * longest row, the value on the right. The panels' sources, devices, reading
22
+ * depth, most read pages and campaigns.
23
+ */
24
+ const props = defineProps<{
25
+ rows: { name: string; value: number; label?: string; link?: string }[];
26
+ }>();
27
+
28
+ const max = computed(() => Math.max(1, ...props.rows.map((row) => row.value)));
29
+ </script>
@@ -0,0 +1,233 @@
1
+ <template>
2
+ <section v-if="visible && state !== 'hidden'" class="rounded-xl border border-default bg-default p-5" aria-label="Fréquentation">
3
+ <header class="mb-4 flex flex-wrap items-center justify-between gap-2">
4
+ <span class="text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">
5
+ {{ heading }}
6
+ </span>
7
+ <span class="flex gap-1" role="group" aria-label="Période">
8
+ <button
9
+ v-for="option in PERIODS"
10
+ :key="option"
11
+ type="button"
12
+ class="border-b-2 px-1.5 py-0.5 text-xs"
13
+ :class="option === period ? 'border-primary font-semibold text-highlighted' : 'border-transparent text-dimmed hover:text-highlighted'"
14
+ :aria-pressed="option === period"
15
+ @click="period = option"
16
+ >
17
+ {{ option }} jours
18
+ </button>
19
+ </span>
20
+ </header>
21
+
22
+ <div v-if="state === 'loading' && !audience" class="space-y-3">
23
+ <USkeleton class="h-10 w-2/3" />
24
+ <USkeleton class="h-24 w-full" />
25
+ </div>
26
+
27
+ <template v-else-if="audience">
28
+ <div class="flex flex-wrap items-baseline gap-x-6 gap-y-2">
29
+ <div>
30
+ <span class="font-serif text-3xl font-semibold text-highlighted">{{ count(audience.visits) }}</span>
31
+ <span class="ml-1 text-xs text-dimmed">{{ collection ? 'pages vues' : 'visites' }}</span>
32
+ <span v-if="trend" class="ml-2 text-xs font-medium" :class="trend.up ? 'text-success' : 'text-error'">{{ trend.label }}</span>
33
+ </div>
34
+ <div v-if="audience.visitors != null">
35
+ <span class="font-serif text-lg text-highlighted">{{ count(audience.visitors) }}</span>
36
+ <span class="ml-1 text-xs text-dimmed">visiteurs</span>
37
+ </div>
38
+ <div v-if="audience.viewsPerVisit != null">
39
+ <span class="font-serif text-lg text-highlighted">{{ decimal(audience.viewsPerVisit) }}</span>
40
+ <span class="ml-1 text-xs text-dimmed">pages / visite</span>
41
+ </div>
42
+ <div v-if="audience.readingMs != null">
43
+ <span class="font-serif text-lg text-highlighted">{{ duration(audience.readingMs) }}</span>
44
+ <span class="ml-1 text-xs text-dimmed">durée moyenne</span>
45
+ </div>
46
+ <div v-if="audience.rightNow != null" class="ml-auto text-xs text-muted">
47
+ <span class="mr-1.5 inline-block size-1.5 rounded-full bg-success align-middle" aria-hidden="true" />
48
+ <b class="text-highlighted">{{ audience.rightNow }}</b>
49
+ {{ audience.rightNow > 1 ? 'visiteurs' : 'visiteur' }} en ce moment
50
+ </div>
51
+ </div>
52
+
53
+ <div
54
+ class="mt-4"
55
+ role="img"
56
+ :aria-label="`${collection ? 'Pages vues' : 'Visites'} par jour, du ${day(audience.period.from)} au ${day(audience.period.to)}`"
57
+ >
58
+ <AreaChart
59
+ :data="audience.daily"
60
+ :categories="series"
61
+ :height="140"
62
+ x-axis="day"
63
+ :x-formatter="dayTick"
64
+ :x-num-ticks="4"
65
+ :y-num-ticks="3"
66
+ :y-axes="{ 0: { formatter: (value: number) => count(value) } }"
67
+ :tooltip-title-formatter="(row: { day: string }) => day(row.day)"
68
+ curve-type="monotoneX"
69
+ :padding="{ top: 4, right: 24, bottom: 0, left: 0 }"
70
+ :gradient-stops="[
71
+ { offset: '0%', stopOpacity: 0.12 },
72
+ { offset: '100%', stopOpacity: 0 },
73
+ ]"
74
+ hide-legend
75
+ />
76
+ </div>
77
+
78
+ <div v-if="open" class="mt-5 grid gap-6 border-t border-default pt-5 sm:grid-cols-3">
79
+ <div v-if="audience.sources?.length">
80
+ <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Sources</h3>
81
+ <audience-bar-list :rows="shares(audience.sources)" />
82
+ </div>
83
+ <div v-if="audience.depth">
84
+ <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Lecture</h3>
85
+ <audience-bar-list :rows="shares(depth)" />
86
+ </div>
87
+ <div v-else-if="!entry && audience.top.length">
88
+ <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Pages les plus vues</h3>
89
+ <audience-bar-list :rows="topPages" />
90
+ </div>
91
+ <div v-if="audience.devices?.length">
92
+ <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Appareils</h3>
93
+ <audience-bar-list :rows="shares(devices)" />
94
+ </div>
95
+ <div v-if="audience.campaigns?.length">
96
+ <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Campagnes (UTM)</h3>
97
+ <audience-bar-list :rows="campaigns" />
98
+ </div>
99
+ <p class="flex gap-2 rounded-lg bg-elevated/50 p-3 text-xs leading-relaxed text-muted sm:col-span-3">
100
+ <svg class="mt-0.5 size-4 shrink-0 text-success" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" /><path d="m9 12 2 2 4-4" /></svg>
101
+ <span><b class="text-default">Conforme RGPD</b> — mesure anonyme et agrégée, sans cookie ni bandeau de consentement.</span>
102
+ </p>
103
+ </div>
104
+
105
+ <div class="mt-3 text-center">
106
+ <button type="button" class="text-xs text-dimmed hover:text-highlighted" :aria-expanded="open" @click="open = !open">
107
+ {{ open ? 'Replier ⌃' : 'Plus de détails ⌄' }}
108
+ </button>
109
+ </div>
110
+ </template>
111
+ </section>
112
+ </template>
113
+
114
+ <script setup lang="ts">
115
+ /**
116
+ * An audience panel: the site's, a collection's or an entry's, read from the
117
+ * instance's `audience.summary`, which asks the configured audience source.
118
+ * The session says first whether this user may see it (`useAudience().visible`):
119
+ * if not, nothing renders and nothing is asked. A refusal still means no
120
+ * source is configured, this user is not among its viewers, or the source did
121
+ * not answer: the panel then renders nothing at all. Every block the source
122
+ * leaves out is left out here too.
123
+ */
124
+ import { AUDIENCE_PERIODS } from '@open-commune/core/dtos';
125
+ import AudienceBarList from './audience-bar-list.vue';
126
+
127
+ type Share = { name: string; share: number };
128
+
129
+ /**
130
+ * Without props, the site's panel; with `collection`, that collection's; with
131
+ * `collection` and `entry` (the entry's id), that entry's.
132
+ */
133
+ const props = defineProps<{ collection?: { id: string; slug: string }; entry?: string }>();
134
+
135
+ const heading = computed(() =>
136
+ props.entry
137
+ ? 'Fréquentation de la fiche'
138
+ : props.collection
139
+ ? 'Fréquentation de la collection'
140
+ : 'Fréquentation du site',
141
+ );
142
+
143
+ const PERIODS = AUDIENCE_PERIODS;
144
+ const DEVICES: Record<string, string> = {
145
+ phone: 'Téléphone',
146
+ computer: 'Ordinateur',
147
+ tablet: 'Tablette',
148
+ };
149
+
150
+ const period = ref<(typeof PERIODS)[number]>(30);
151
+ const open = ref(false);
152
+ const { visible, summary } = useAudience();
153
+ const { data, isPending, isError } = summary(
154
+ computed(() => ({
155
+ period: period.value,
156
+ collection: props.collection?.slug,
157
+ entry: props.collection ? props.entry : undefined,
158
+ })),
159
+ );
160
+ const audience = computed(() => (isError.value ? null : (data.value ?? null)));
161
+ const state = computed(() =>
162
+ isError.value ? 'hidden' : isPending.value && !data.value ? 'loading' : 'ready',
163
+ );
164
+
165
+ const trend = computed(() => {
166
+ const a = audience.value;
167
+ if (!a?.visitsPrevious) return null;
168
+ const change = Math.round(((a.visits - a.visitsPrevious) / a.visitsPrevious) * 100);
169
+ return { up: change >= 0, label: `${change >= 0 ? '+' : '−'}${Math.abs(change)} %` };
170
+ });
171
+
172
+ /** How far the readers of an entry went down the page. */
173
+ const depth = computed(() => {
174
+ const d = audience.value?.depth;
175
+ if (!d) return [];
176
+ return [
177
+ { name: 'Un quart', share: d.reached25 },
178
+ { name: 'La moitié', share: d.reached50 },
179
+ { name: "Jusqu'au bout", share: d.reachedEnd },
180
+ ];
181
+ });
182
+
183
+ const devices = computed(() =>
184
+ (audience.value?.devices ?? []).map((row) => ({ ...row, name: DEVICES[row.name] ?? row.name })),
185
+ );
186
+
187
+ /** The daily curve's one series, named the way the headline counts. */
188
+ const series = computed(() => ({
189
+ visits: { name: props.collection ? 'Pages vues' : 'Visites', color: 'var(--ui-text-highlighted)' },
190
+ }));
191
+
192
+ /** The most read pages, named after their entry and opening it in the admin. */
193
+ const topPages = computed(() =>
194
+ (audience.value?.top ?? []).map((page) => {
195
+ const slug = page.collection ?? props.collection?.slug;
196
+ return {
197
+ name: page.title,
198
+ value: page.visits,
199
+ label: count(page.visits),
200
+ link: slug ? (page.entryId ? `/${slug}/${page.entryId}` : `/${slug}`) : undefined,
201
+ };
202
+ }),
203
+ );
204
+
205
+ const campaigns = computed(() =>
206
+ (audience.value?.campaigns ?? []).map((campaign) => ({
207
+ name: campaign.name,
208
+ value: campaign.visits,
209
+ label: `${count(campaign.visits)} visites`,
210
+ })),
211
+ );
212
+
213
+ /** Shares, as rows of a bar list. */
214
+ const shares = (rows: Share[]) =>
215
+ rows.map((row) => ({ name: row.name, value: row.share, label: `${row.share} %` }));
216
+
217
+ const count = (value: number) => value.toLocaleString('fr-FR');
218
+ const decimal = (value: number) => value.toLocaleString('fr-FR', { maximumFractionDigits: 1 });
219
+ const duration = (ms: number) => {
220
+ const seconds = Math.round(ms / 1000);
221
+ return seconds < 60
222
+ ? `${seconds} s`
223
+ : `${Math.floor(seconds / 60)} min ${String(seconds % 60).padStart(2, '0')}`;
224
+ };
225
+ const day = (iso: string) =>
226
+ new Date(`${iso}T12:00:00Z`).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' });
227
+ /** An x tick of the curve: an index into the days, or the day itself. */
228
+ const dayTick = (tick: number | Date) => {
229
+ const iso = typeof tick === 'number' ? audience.value?.daily[tick]?.day : String(tick);
230
+ return iso ? day(iso) : '';
231
+ };
232
+
233
+ </script>
@@ -0,0 +1,36 @@
1
+ import type { AudienceAsk } from '@open-commune/core/dtos'
2
+ import { keepPreviousData, useQuery } from '@tanstack/vue-query'
3
+ import { computed, toValue, type MaybeRefOrGetter } from 'vue'
4
+
5
+ /**
6
+ * The audience panels' data surface. The instance asks its configured source
7
+ * and keeps the answer a minute itself, so the cache here only spares a
8
+ * screen that comes back. A refusal is final: the panel hides, no retry.
9
+ *
10
+ * `visible` is the session's own answer, decided by the server at auth.me:
11
+ * a source is configured and this user is among its viewers. It is read from
12
+ * the session and not from the `read:audience` ability, which an admin's
13
+ * `manage:all` grants whatever the server said. Nothing is asked while it is
14
+ * false, so a refused user never sees a panel, not even while it loads.
15
+ */
16
+ export default function useAudience() {
17
+ const trpc = useTrpc()
18
+ const session = useSession()
19
+
20
+ const visible = computed(() => session.user.value?.audience === true)
21
+
22
+ const summary = (ask: MaybeRefOrGetter<AudienceAsk>) =>
23
+ useQuery({
24
+ enabled: visible,
25
+ queryKey: computed(() => {
26
+ const { period, collection, entry } = toValue(ask)
27
+ return ['audience', period, collection ?? null, entry ?? null]
28
+ }),
29
+ queryFn: () => trpc.audience.summary.query(toValue(ask)),
30
+ placeholderData: keepPreviousData,
31
+ staleTime: 60_000,
32
+ retry: false,
33
+ })
34
+
35
+ return { visible, summary }
36
+ }
@@ -43,6 +43,7 @@ export default function useEntries() {
43
43
  const invalidateCollection = (collectionId: string) => {
44
44
  queryClient.invalidateQueries({ queryKey: ['entries', collectionId] })
45
45
  queryClient.invalidateQueries({ queryKey: ['entries', 'byId'] })
46
+ queryClient.invalidateQueries({ queryKey: ['entries', 'recent'] })
46
47
  }
47
48
 
48
49
  const list = (
@@ -133,6 +134,17 @@ export default function useEntries() {
133
134
  })
134
135
  }
135
136
 
137
+ /**
138
+ * The entries last touched, whatever their collection. Under the `entries`
139
+ * prefix, so any write to a collection refreshes it.
140
+ */
141
+ const recent = (limit = 5, { enabled = true } = {}) =>
142
+ useQuery({
143
+ queryKey: ['entries', 'recent', limit],
144
+ queryFn: () => trpc.collections.entries.recent.query({ limit }),
145
+ enabled,
146
+ })
147
+
136
148
  const get = (id: MaybeRef<string>) =>
137
149
  useQuery({
138
150
  queryKey: computed(() => ['entries', 'byId', unref(id)]),
@@ -168,5 +180,5 @@ export default function useEntries() {
168
180
  queryFn: () => trpc.collections.entries.count.query({ collectionId }),
169
181
  })
170
182
 
171
- return { list, infinite, get, getMany, count, create, update, remove, invalidateCollection }
183
+ return { list, infinite, recent, get, getMany, count, create, update, remove, invalidateCollection }
172
184
  }
@@ -7,6 +7,7 @@ import { ERROR_TYPES, type ErrorType } from '@open-commune/core/dtos';
7
7
  * stops this file compiling until it has its sentence.
8
8
  */
9
9
  export const REFUSALS: Record<ErrorType, string> = {
10
+ [ERROR_TYPES.AUDIENCE_UNAVAILABLE]: "La fréquentation n'est pas disponible pour le moment.",
10
11
  [ERROR_TYPES.COLLECTION_NOT_FOUND]: "Cette collection n'existe plus.",
11
12
  [ERROR_TYPES.ENTRY_NOT_FOUND]: "Cette entrée n'existe plus.",
12
13
  [ERROR_TYPES.INVALID_ENTRY_DATA]:
package/nuxt.config.ts CHANGED
@@ -107,7 +107,10 @@ export default defineNuxtConfig({
107
107
  // Scan nested composables (composables/core/domains/*).
108
108
  imports: { dirs: [join(layerDir, 'composables/**')] },
109
109
  // Session auth lives in use-session + middleware/00.auth (no auth module).
110
- modules: ['@nuxt/ui', '@pinia/nuxt', '@pinia-orm/nuxt', '@vueuse/nuxt'],
110
+ modules: ['@nuxt/ui', '@pinia/nuxt', '@pinia-orm/nuxt', '@vueuse/nuxt', 'nuxt-charts'],
111
+ // The charts the admin draws (the audience panels), themed by Nuxt UI. Only
112
+ // those it uses are registered, so the others stay out of the bundle.
113
+ nuxtCharts: { include: ['AreaChart'] },
111
114
  vite: {
112
115
  resolve: {
113
116
  // Sous le layout node_modules de Bun, Vite retombe sur l'entrée CJS
package/package.json CHANGED
@@ -19,8 +19,8 @@
19
19
  "@iconify/vue": "^5.0.3",
20
20
  "@nuxt/kit": "^4.6.1",
21
21
  "@nuxt/ui": "^4.12.0",
22
- "@open-commune/core": "^0.2.15",
23
- "@open-commune/editor": "^0.2.15",
22
+ "@open-commune/core": "^0.2.17",
23
+ "@open-commune/editor": "^0.2.17",
24
24
  "@pinia-orm/nuxt": "^2.0.0",
25
25
  "@pinia/nuxt": "^1.0.3",
26
26
  "@tanstack/vue-query": "^5.104.3",
@@ -35,6 +35,7 @@
35
35
  "h3": "^1.15.11",
36
36
  "luxon": "^3.4.4",
37
37
  "mapbox-gl": "^3.33.0",
38
+ "nuxt-charts": "^3.2.0",
38
39
  "ofetch": "^1.3.3",
39
40
  "pinia-orm": "^2.0.0",
40
41
  "tailwindcss": "^4.3.2",
@@ -42,7 +43,7 @@
42
43
  },
43
44
  "description": "The Open Commune application: the admin interface and the server, on a single origin.",
44
45
  "license": "AGPL-3.0-or-later",
45
- "version": "0.2.15",
46
+ "version": "0.2.17",
46
47
  "type": "module",
47
48
  "main": "./nuxt.config.ts",
48
49
  "files": [
@@ -1,5 +1,11 @@
1
1
  <template>
2
2
  <div>
3
+ <audience-panel
4
+ v-if="!isCreating"
5
+ :collection="{ id: String($route.params.collection), slug: String($route.params.collection) }"
6
+ :entry="String($route.params.record)"
7
+ class="mt-4"
8
+ />
3
9
  <!-- <alert
4
10
  v-if="alertSort"
5
11
  :sort="alertSort"
@@ -17,6 +23,7 @@
17
23
  <script setup>
18
24
  // import alert from '@/components/template/content-section/Alert'
19
25
  import formsLayout from '~/components/forms/layouts/layout'
26
+ import AudiencePanel from '~/components/audience/audience-panel.vue'
20
27
 
21
28
  definePageMeta({
22
29
  permissions: ['read:records'],
@@ -1,68 +1,75 @@
1
1
  <template>
2
- <section v-if="isPending" class="w-full">
3
- <div class="mb-4 flex flex-wrap items-center gap-2">
4
- <USkeleton class="h-9 w-44 rounded-md" />
5
- <USkeleton class="h-9 w-28 rounded-md" />
6
- <USkeleton class="ml-auto size-9 rounded-md" />
7
- </div>
8
- <div class="space-y-2">
9
- <USkeleton v-for="i in 5" :key="i" class="h-16 rounded-lg" />
10
- </div>
11
- </section>
12
-
13
- <section v-else class="w-full">
14
- <!-- Both controls narrow on the SERVER: a collection of several hundred
15
- entries does not fit in the browser, and narrowing what is loaded only
16
- ever finds what is already visible. -->
17
- <div class="mb-4 flex flex-wrap items-center gap-2">
18
- <input-filter
19
- v-if="collection?.name"
20
- label="Collection"
21
- :value="collection.name"
22
- disabled
23
- />
24
- <input-filter-status v-model="filters.status" />
25
- <input-search v-model="filters.search" class="ml-auto" />
26
- </div>
27
-
28
- <data-table
29
- v-if="records.length"
30
- :items="records"
31
- v-bind="listingKeys"
32
- :actions="ACTIONS"
33
- :loading="isFetching"
34
- :on-select="_onRowSelect"
35
- @update="_open"
36
- @remove="_remove"
2
+ <div class="w-full">
3
+ <audience-panel
4
+ :collection="{ id: String($route.params.collection), slug: String($route.params.collection) }"
5
+ class="mb-6"
37
6
  />
7
+ <section v-if="isPending" class="w-full">
8
+ <div class="mb-4 flex flex-wrap items-center gap-2">
9
+ <USkeleton class="h-9 w-44 rounded-md" />
10
+ <USkeleton class="h-9 w-28 rounded-md" />
11
+ <USkeleton class="ml-auto size-9 rounded-md" />
12
+ </div>
13
+ <div class="space-y-2">
14
+ <USkeleton v-for="i in 5" :key="i" class="h-16 rounded-lg" />
15
+ </div>
16
+ </section>
38
17
 
39
- <UEmpty
40
- v-else
41
- icon="i-lucide-inbox"
42
- :title="narrowed ? 'Aucun résultat' : 'Aucune entrée'"
43
- :description="narrowed
44
- ? 'Aucune entrée ne correspond à cette recherche ou à ces statuts.'
45
- : 'Cette collection est vide pour le moment.'"
46
- />
18
+ <section v-else class="w-full">
19
+ <!-- Both controls narrow on the SERVER: a collection of several hundred
20
+ entries does not fit in the browser, and narrowing what is loaded only
21
+ ever finds what is already visible. -->
22
+ <div class="mb-4 flex flex-wrap items-center gap-2">
23
+ <input-filter
24
+ v-if="collection?.name"
25
+ label="Collection"
26
+ :value="collection.name"
27
+ disabled
28
+ />
29
+ <input-filter-status v-model="filters.status" />
30
+ <input-search v-model="filters.search" class="ml-auto" />
31
+ </div>
47
32
 
48
- <div v-if="records.length" class="mt-6 flex items-center justify-center gap-4">
49
- <p class="text-sm text-dimmed">
50
- {{ records.length }} affichée{{ records.length > 1 ? 's' : '' }} sur {{ total }}
51
- </p>
52
- <UButton
53
- v-if="hasNextPage"
54
- color="neutral"
55
- variant="outline"
56
- class="px-4"
57
- label="Afficher plus"
58
- :loading="isFetchingNextPage"
59
- @click="fetchNextPage()"
33
+ <data-table
34
+ v-if="records.length"
35
+ :items="records"
36
+ v-bind="listingKeys"
37
+ :actions="ACTIONS"
38
+ :loading="isFetching"
39
+ :on-select="_onRowSelect"
40
+ @update="_open"
41
+ @remove="_remove"
60
42
  />
61
- </div>
62
- </section>
43
+
44
+ <UEmpty
45
+ v-else
46
+ icon="i-lucide-inbox"
47
+ :title="narrowed ? 'Aucun résultat' : 'Aucune entrée'"
48
+ :description="narrowed
49
+ ? 'Aucune entrée ne correspond à cette recherche ou à ces statuts.'
50
+ : 'Cette collection est vide pour le moment.'"
51
+ />
52
+
53
+ <div v-if="records.length" class="mt-6 flex items-center justify-center gap-4">
54
+ <p class="text-sm text-dimmed">
55
+ {{ records.length }} affichée{{ records.length > 1 ? 's' : '' }} sur {{ total }}
56
+ </p>
57
+ <UButton
58
+ v-if="hasNextPage"
59
+ color="neutral"
60
+ variant="outline"
61
+ class="px-4"
62
+ label="Afficher plus"
63
+ :loading="isFetchingNextPage"
64
+ @click="fetchNextPage()"
65
+ />
66
+ </div>
67
+ </section>
68
+ </div>
63
69
  </template>
64
70
 
65
71
  <script setup>
72
+ import AudiencePanel from '~/components/audience/audience-panel.vue'
66
73
  import dataTable from '~/components/data/lists/data-table'
67
74
  import inputFilter from '~/components/forms/fields/input-filter'
68
75
  import inputFilterStatus from '~/components/forms/fields/input-filter-status'
@@ -1,10 +1,85 @@
1
1
  <template>
2
- <div class="relative block w-full">
2
+ <!-- Today's look keeps today's home: a greeting, and only the audience when an instance measures it. -->
3
+ <div v-if="plain" class="relative block w-full max-w-4xl">
4
+ <audience-panel />
5
+ </div>
6
+
7
+ <div v-else class="space-y-8">
8
+ <!-- Said only of a site that has an address: an instance without one has
9
+ nothing online to announce. -->
10
+ <section
11
+ v-if="siteUrl"
12
+ class="flex flex-wrap items-center justify-between gap-4 rounded-lg bg-elevated px-5 py-4 shadow-card"
13
+ >
14
+ <div class="flex items-center gap-3">
15
+ <span class="inline-flex items-center gap-2 text-xs font-semibold tracking-wider text-success uppercase">
16
+ <span class="size-1.5 rounded-full bg-success" />
17
+ Site en ligne
18
+ </span>
19
+ <NuxtLink
20
+ :to="siteUrl"
21
+ target="_blank"
22
+ external
23
+ class="inline-flex items-center gap-1.5 text-sm text-muted hover:text-highlighted"
24
+ >
25
+ {{ siteHost }}
26
+ <UIcon name="i-lucide-external-link" class="size-3.5" />
27
+ </NuxtLink>
28
+ </div>
29
+ <p class="text-xs text-dimmed">
30
+ Le site se met à jour chaque nuit, ou immédiatement avec « Publier le site ».
31
+ </p>
32
+ </section>
33
+
34
+ <audience-panel />
3
35
 
36
+ <section>
37
+ <h2 class="mb-3 text-xs font-semibold tracking-widest text-muted uppercase">
38
+ Dernières modifications
39
+ </h2>
40
+ <div class="divide-y divide-default overflow-hidden rounded-lg bg-elevated shadow-card">
41
+ <template v-if="pending">
42
+ <div v-for="i in RECENT" :key="i" class="px-5 py-3.5">
43
+ <USkeleton class="h-5 w-2/3" />
44
+ </div>
45
+ </template>
46
+ <p v-else-if="!recent.length" class="px-5 py-6 text-sm text-muted">
47
+ Aucune modification pour le moment.
48
+ </p>
49
+ <NuxtLink
50
+ v-for="entry in recent"
51
+ :key="entry.id"
52
+ :to="`/${entry.collection.slug}/${entry.id}`"
53
+ class="group flex items-center justify-between gap-4 px-5 py-3.5"
54
+ >
55
+ <div class="min-w-0">
56
+ <p class="truncate text-sm text-highlighted group-hover:underline">{{ entry.title }}</p>
57
+ <p class="text-xs text-dimmed">{{ entry.collection.name }}</p>
58
+ </div>
59
+ <div class="flex shrink-0 items-center gap-3">
60
+ <status-badge :status="entry.status" />
61
+ <span class="w-28 text-right text-xs text-dimmed">{{ _fromNow(entry.updatedAt) }}</span>
62
+ </div>
63
+ </NuxtLink>
64
+ </div>
65
+ </section>
4
66
  </div>
5
67
  </template>
6
68
 
7
69
  <script setup>
70
+ import { DateTime } from 'luxon'
71
+ import AudiencePanel from '~/components/audience/audience-panel.vue'
72
+ import statusBadge from '~/components/elements/badges/status-badge'
73
+
74
+ // Prepare constants
75
+ const RECENT = 5
76
+
77
+ // Prepare composables
78
+ const $organization = useOrganization()
79
+ const $definitions = useDefinitions()
80
+ const $entries = useEntries()
81
+ const { public: { appearance } } = useRuntimeConfig()
82
+
8
83
  definePageMeta({
9
84
  permissions: ['entrance:self'],
10
85
  headings: {
@@ -12,4 +87,33 @@ definePageMeta({
12
87
  description: ''
13
88
  }
14
89
  })
15
- </script>
90
+
91
+ // Prepare constants
92
+ // The home of today's look shows nothing, and asks the server for nothing.
93
+ const plain = appearance === 'plain'
94
+
95
+ // Fetch data
96
+ const { data: organization } = $organization.query()
97
+ const { data: definitions, isPending: isDefinitionsPending } = $definitions.list()
98
+ const { data: entries, isPending: isEntriesPending } = $entries.recent(RECENT, { enabled: !plain })
99
+
100
+ // Prepare computed
101
+ const pending = computed(() => isDefinitionsPending.value || isEntriesPending.value)
102
+ // An entry is shown with its collection, and reached through it: one whose
103
+ // collection is not in the list has no address to offer.
104
+ const recent = computed(() => (entries.value ?? [])
105
+ .map(entry => ({
106
+ ...entry,
107
+ collection: definitions.value?.find(({ id }) => id === entry.collectionId),
108
+ }))
109
+ .filter(({ collection }) => collection))
110
+ const siteUrl = computed(() => {
111
+ const url = organization.value?.deployment?.url
112
+ if (!url) return ''
113
+ return url.startsWith('http') ? url : `https://${url}`
114
+ })
115
+ const siteHost = computed(() => (siteUrl.value ? new URL(siteUrl.value).host : ''))
116
+
117
+ // Prepare methods
118
+ const _fromNow = value => (value ? DateTime.fromISO(value).setLocale('fr').toRelative() : '')
119
+ </script>
@@ -26,7 +26,9 @@ export const useWorkspaceStore = defineStore('layout/workspace', () => {
26
26
  const user = $session.user.value
27
27
  $abilities.assignAbilities([
28
28
  'entrance:self',
29
- ...(ROLES.find(({ id }) => id === user?.role)?.permissions ?? [])
29
+ ...(ROLES.find(({ id }) => id === user?.role)?.permissions ?? []),
30
+ // Decided by the server, not by the role (auth.me's `audience`).
31
+ ...(user?.audience === true ? ['read:audience'] : [])
30
32
  ])
31
33
  }
32
34