inhaus-plugin-chat/resources/js/components/GifPicker.vue
Friederich Loheide 2844452002 Nachrichten-Plugin 1.0.0: Direktnachrichten, Gruppen, Anhänge, GIFs, Emojis
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 16:34:53 +00:00

51 lines
2.2 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup>
import { onMounted, ref, watch } from 'vue';
import { LoaderCircle, Search } from '@lucide/vue';
import { api } from '../lib/api';
const emit = defineEmits(['pick']);
const query = ref('');
const gifs = ref([]);
const giphy = ref(false);
const loading = ref(false);
let timer;
async function load() {
loading.value = true;
try {
const data = await api.gifs(query.value);
gifs.value = data.gifs;
giphy.value = data.giphy;
} finally {
loading.value = false;
}
}
watch(query, () => {
clearTimeout(timer);
timer = setTimeout(load, 300);
});
onMounted(load);
</script>
<template>
<div>
<div class="ih:border-b ih:p-2">
<div class="ih:relative">
<Search class="ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground" />
<input v-model="query" type="search" placeholder="GIFs suchen" aria-label="GIFs suchen" autofocus class="ih:h-9 ih:w-full ih:rounded-md ih:bg-muted ih:pr-3 ih:pl-8 ih:text-sm ih:focus-visible:outline-none" />
</div>
</div>
<div class="ih:max-h-72 ih:overflow-y-auto ih:p-2">
<div v-if="loading && !gifs.length" class="ih:grid ih:place-items-center ih:py-8"><LoaderCircle class="ih:size-5 ih:animate-spin ih:text-muted-foreground" /></div>
<div v-else-if="gifs.length" class="ih:columns-2 ih:gap-1.5">
<button v-for="gif in gifs" :key="gif.url" type="button" class="ih:mb-1.5 ih:block ih:w-full ih:overflow-hidden ih:rounded ih:bg-muted ih:hover:ring-2 ih:hover:ring-brand" :title="gif.title" @click="emit('pick', gif)">
<img :src="gif.preview" :alt="gif.title" loading="lazy" class="ih:block ih:w-full" :style="gif.width && gif.height ? { aspectRatio: `${gif.width} / ${gif.height}` } : {}" />
</button>
</div>
<p v-else class="ih:py-6 ih:text-center ih:text-sm ih:text-muted-foreground">{{ query ? 'Keine GIFs gefunden.' : 'Noch keine GIFs in der Sammlung.' }}</p>
</div>
<p v-if="giphy" class="ih:border-t ih:px-3 ih:py-1.5 ih:text-[10px] ih:text-muted-foreground">Mit Suche über GIPHY – Suchbegriffe gehen an GIPHY.</p>
</div>
</template>