Files
XIP/frontend/src/composables/useMessageItem.ts
Kerboul cfa2eadec9
Some checks failed
Deploy XIP / deploy (push) Failing after 37s
feat: conformite enonce - explorer, favoris, stats perso, tests, slots
Fonctionnel
- Backend messages : GET /api/messages/:id (detail) + recherche (q),
  pagination par curseur (before/limit) avec enveloppe { items, nextCursor,
  hasMore } ; le flux temps reel garde l'ancien format quand aucun parametre.
- Explorer (/explorer) : catalogue distant, recherche debouncee + annulable
  (AbortController), filtre, defilement infini, etat garde (keep-alive).
- Details par id : /message/:id et /shop/p/:id (consomment route.params).
- Favoris (/favoris) : liste perso persistee en localStorage, notation
  (note/rating/statut) via modale, refletee partout (bouton favori).
- Mes stats (/mes-stats) : agregats derives des favoris (note moyenne, top
  pays/auteurs, statuts), auto-mis a jour, route gardee si liste vide.
- Routeur : pages secondaires en lazy-load + repli, garde beforeEnter.

Technique
- Slots : PrefSection (slot defaut + slot nomme) enveloppe les 5 sections
  "Mes Persos" ; Modal (Teleport + slots).
- v-model custom : SearchBox (defineModel + debounce).
- Directive custom : v-click-outside.
- Tests Vitest : 25 tests (etat, fonctions, composants), ~86% du code metier.
- Retrait d'Ionic (inutilise). Script typecheck backend ; tsconfig @types/bun.
- Correctif type : garde stockLimit nullable dans l'achat (catalog.ts).
- README complet (URL, stack, run, tests, secrets, deploiement, mention IA).
2026-05-31 23:59:34 +02:00

63 lines
2.3 KiB
TypeScript

import { type GeoInfo } from '@/composables/useMessages';
import { getIpColorWithPerks, getIpGlowWithPerks, getIpGlow } from '@/composables/ipColor';
import { usePerks } from '@/composables/usePerks';
import { useCustomStyles } from '@/composables/useCustomStyles';
import { useMyPerks } from '@/composables/useMessages';
export function useMessageItem() {
const { perksFor } = usePerks();
const { myPerks } = useMyPerks();
const { prefs } = useCustomStyles();
function perksOf(m: { authorIp: string; authorPerks?: any }) {
return m.authorPerks ?? perksFor(m.authorIp);
}
function ipStyle(m: { authorIp: string; authorPerks?: any }) {
const ip = m.authorIp;
const override = prefs.ipColors[ip];
if (override && override !== 'auto') {
return { color: override, textShadow: getIpGlow(override) };
}
const p = perksOf(m);
return { color: getIpColorWithPerks(ip, p), textShadow: getIpGlowWithPerks(ip, p) };
}
function petsLeft(m: { authorIp: string; authorPerks?: any }) {
const ip = m.authorIp;
if (ip in prefs.ipPets) return prefs.ipPets[ip];
return (perksOf(m)?.pets ?? [])
.filter((x: any) => x.position === 'left' || x.position === 'both')
.map((x: any) => x.char).join('');
}
function petsRight(m: { authorIp: string; authorPerks?: any }) {
const ip = m.authorIp;
if (ip in prefs.ipPets) return '';
return (perksOf(m)?.pets ?? [])
.filter((x: any) => x.position === 'right' || x.position === 'both')
.map((x: any) => x.char).join('');
}
function fmt(date: string) {
return new Date(date).toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' });
}
function geoLabel(geo?: GeoInfo | null): string {
if (!geo) return '';
if (!geo.countryCode) return 'Local';
const place = geo.city || geo.country;
if (geo.lat != null && geo.lon != null) {
return `${place} · ${geo.lat.toFixed(4)}, ${geo.lon.toFixed(4)}`;
}
return place;
}
function geoLink(geo?: GeoInfo | null): string {
if (!geo || geo.lat == null || geo.lon == null) return 'https://maps.google.com';
return `https://www.google.com/maps/search/?api=1&query=${geo.lat},${geo.lon}`;
}
return { perksOf, ipStyle, petsLeft, petsRight, fmt, geoLabel, geoLink, myPerks, prefs };
}