feat: NSFW for mini-app send mode

This commit is contained in:
2026-10-11 03:06:47 +04:00
parent 8169b6474a
commit 525e99c6f3
+39 -8
View File
@@ -17,6 +17,7 @@
let items = $state([]) let items = $state([])
let query = $state('') let query = $state('')
let includeNsfw = $state(false)
let loading = $state(true) let loading = $state(true)
let error = $state(null) let error = $state(null)
let sending = $state(null) // id медиа, которое сейчас отправляется let sending = $state(null) // id медиа, которое сейчас отправляется
@@ -26,7 +27,7 @@
async function load() { async function load() {
loading = true; error = null; previews = {} loading = true; error = null; previews = {}
try { try {
items = await api.getMedia(query) items = await api.getMedia(query, includeNsfw)
for (const item of items) { for (const item of items) {
if (PREVIEWABLE.has(item.mediaType)) loadPreview(item.id) if (PREVIEWABLE.has(item.mediaType)) loadPreview(item.id)
} }
@@ -76,6 +77,11 @@
searchTimer = setTimeout(load, 400) searchTimer = setTimeout(load, 400)
} }
function toggleNsfw() {
includeNsfw = !includeNsfw
load()
}
onMount(load) onMount(load)
</script> </script>
@@ -96,12 +102,20 @@
{/if} {/if}
</div> </div>
<input <div class="search-row">
class="search" <input
placeholder="Поиск: #мем -#кот слово" class="search"
bind:value={query} placeholder="Поиск: #мем -#кот слово"
oninput={onSearch} bind:value={query}
/> oninput={onSearch}
/>
<button
class="nsfw-btn"
class:nsfw-btn--active={includeNsfw}
onclick={toggleNsfw}
title={includeNsfw ? 'Скрыть 18+' : 'Показать 18+'}
>18+</button>
</div>
{#if loading} {#if loading}
<div class="hint">Загрузка…</div> <div class="hint">Загрузка…</div>
@@ -180,13 +194,30 @@
} }
.chat-name :global(svg) { flex-shrink: 0; color: var(--tg-hint, #888); } .chat-name :global(svg) { flex-shrink: 0; color: var(--tg-hint, #888); }
.search-row {
display: flex; align-items: center; gap: 6px;
margin: 4px 8px 6px;
}
.search { .search {
margin: 4px 8px 6px; width: calc(100% - 16px); flex: 1; min-width: 0;
padding: 8px 12px; border-radius: 8px; border: none; padding: 8px 12px; border-radius: 8px; border: none;
background: var(--tg-secondary-bg, #f0f0f0); background: var(--tg-secondary-bg, #f0f0f0);
color: var(--tg-text, #000); font-size: 14px; color: var(--tg-text, #000); font-size: 14px;
} }
.nsfw-btn {
flex-shrink: 0;
padding: 8px 10px; border-radius: 8px; border: none;
background: var(--tg-secondary-bg, #f0f0f0);
color: var(--tg-hint, #888); font-size: 13px; font-weight: 600;
cursor: pointer; transition: background .15s, color .15s;
white-space: nowrap;
}
.nsfw-btn--active {
background: var(--tg-button, #2196f3);
color: var(--tg-btn-text, #fff);
}
.hint { text-align: center; padding: 32px; color: var(--tg-hint, #888); } .hint { text-align: center; padding: 32px; color: var(--tg-hint, #888); }
.error { color: #e53935; } .error { color: #e53935; }