| 1 |
import { AI_HOST } from '@constants'; |
| 2 |
|
| 3 |
// The whole set is a third of a megabyte, so callers ask for what they show. |
| 4 |
export const getVibes = async (query = '') => { |
| 5 |
const url = new URL(`${AI_HOST}/api/vibes`); |
| 6 |
if (query) url.searchParams.set('vibes', query); |
| 7 |
|
| 8 |
const response = await fetch(url, { |
| 9 |
method: 'GET', |
| 10 |
headers: { 'Content-Type': 'application/json' }, |
| 11 |
}); |
| 12 |
|
| 13 |
if (!response.ok) throw new Error('Bad response from server'); |
| 14 |
|
| 15 |
const { vibes } = await response.json(); |
| 16 |
return Array.isArray(vibes) ? vibes : []; |
| 17 |
}; |
| 18 |
|
| 19 |
export const vibesBySlug = (vibes) => |
| 20 |
Object.fromEntries((vibes ?? []).map((vibe) => [vibe.slug, vibe])); |
| 21 |
|
| 22 |
export const vibeCssBySlug = (vibes) => |
| 23 |
Object.fromEntries((vibes ?? []).map(({ slug, css }) => [slug, css ?? ''])); |
| 24 |
|