too many changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import { Pencil, Trash2, Star, Check, X } from 'lucide-svelte'
|
||||
import { Pencil, Trash2, Star, Check, X, EyeOff, Copy } from 'lucide-svelte'
|
||||
import { api } from '../lib/api.js'
|
||||
import { showAlert } from '../lib/telegram.js'
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
let error = $state(null)
|
||||
let creating = $state(false)
|
||||
let newName = $state('')
|
||||
let createError = $state(null)
|
||||
|
||||
// Inline-редактирование: { id, value }
|
||||
let editing = $state(null)
|
||||
@@ -19,8 +20,11 @@
|
||||
// Подтверждение смены Inbox: id целевой коллекции
|
||||
let confirmInbox = $state(null)
|
||||
|
||||
$derived: var deleteTarget = collections.find(c => c.id === confirmDelete)
|
||||
$derived: var inboxTarget = collections.find(c => c.id === confirmInbox)
|
||||
// Клонирование: id коллекции, которая клонируется прямо сейчас
|
||||
let cloning = $state(null)
|
||||
|
||||
let deleteTarget = $derived(collections.find(c => c.id === confirmDelete))
|
||||
let inboxTarget = $derived(collections.find(c => c.id === confirmInbox))
|
||||
|
||||
async function load() {
|
||||
loading = true; error = null
|
||||
@@ -32,12 +36,24 @@
|
||||
async function createCollection() {
|
||||
if (!newName.trim()) return
|
||||
creating = true
|
||||
const name = newName.trim()
|
||||
createError = null
|
||||
try {
|
||||
await api.createCollection(newName.trim(), null)
|
||||
const result = await api.createCollection(name, null)
|
||||
newName = ''
|
||||
await load()
|
||||
collections = [...collections, {
|
||||
id: result.id,
|
||||
name,
|
||||
description: null,
|
||||
isInbox: false,
|
||||
isNsfw: false,
|
||||
itemCount: 0,
|
||||
visibility: 0,
|
||||
shareToken: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
}]
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
createError = e.message
|
||||
} finally { creating = false }
|
||||
}
|
||||
|
||||
@@ -49,7 +65,7 @@
|
||||
async function commitEdit() {
|
||||
if (!editing || !editing.value.trim()) { editing = null; return }
|
||||
try {
|
||||
await api.updateCollection(editing.id, editing.value.trim(), null)
|
||||
await api.updateCollection(editing.id, { name: editing.value.trim(), description: null })
|
||||
const idx = collections.findIndex(c => c.id === editing.id)
|
||||
if (idx !== -1) collections[idx] = { ...collections[idx], name: editing.value.trim() }
|
||||
editing = null
|
||||
@@ -60,6 +76,17 @@
|
||||
|
||||
function cancelEdit() { editing = null }
|
||||
|
||||
// ── NSFW ───────────────────────────────────────────────────────────────────
|
||||
async function toggleNsfw(col) {
|
||||
try {
|
||||
await api.updateCollection(col.id, { name: col.name, description: null, isNsfw: !col.isNsfw })
|
||||
const idx = collections.findIndex(c => c.id === col.id)
|
||||
if (idx !== -1) collections[idx] = { ...collections[idx], isNsfw: !col.isNsfw }
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Удаление ───────────────────────────────────────────────────────────────
|
||||
async function commitDelete() {
|
||||
if (!confirmDelete) return
|
||||
@@ -77,7 +104,7 @@
|
||||
async function commitSetInbox() {
|
||||
if (!confirmInbox) return
|
||||
try {
|
||||
await api.setCollectionInbox(confirmInbox)
|
||||
await api.setInboxCollection(confirmInbox)
|
||||
collections = collections.map(c => ({
|
||||
...c,
|
||||
isInbox: c.id === confirmInbox,
|
||||
@@ -89,11 +116,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
// ── Клонирование ───────────────────────────────────────────────────────────
|
||||
async function cloneCollection(id) {
|
||||
cloning = id
|
||||
try {
|
||||
await api.cloneCollection(id)
|
||||
await load()
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
} finally {
|
||||
cloning = null
|
||||
}
|
||||
}
|
||||
|
||||
onMount(load)
|
||||
</script>
|
||||
|
||||
<div class="page">
|
||||
<!-- Форма создания -->
|
||||
{#if createError}
|
||||
<div class="create-error">{createError}</div>
|
||||
{/if}
|
||||
<div class="new-row">
|
||||
<input
|
||||
class="new-input"
|
||||
@@ -133,6 +176,9 @@
|
||||
{#if col.isInbox}
|
||||
<span class="badge-inbox">основная</span>
|
||||
{/if}
|
||||
{#if col.isNsfw}
|
||||
<span class="badge-nsfw">18+</span>
|
||||
{/if}
|
||||
</div>
|
||||
{#if col.itemCount > 0}
|
||||
<div class="col-meta">{col.itemCount} эл.</div>
|
||||
@@ -146,6 +192,22 @@
|
||||
<button class="icon-btn ok" onclick={commitEdit} title="Сохранить"><Check size={16}/></button>
|
||||
<button class="icon-btn cancel" onclick={cancelEdit} title="Отмена"> <X size={16}/></button>
|
||||
{:else}
|
||||
<button
|
||||
class="icon-btn nsfw"
|
||||
class:nsfw--on={col.isNsfw}
|
||||
onclick={() => toggleNsfw(col)}
|
||||
title={col.isNsfw ? 'Снять метку 18+' : 'Пометить как 18+'}
|
||||
>
|
||||
<EyeOff size={16}/>
|
||||
</button>
|
||||
<button
|
||||
class="icon-btn clone"
|
||||
onclick={() => cloneCollection(col.id)}
|
||||
disabled={cloning === col.id}
|
||||
title="Клонировать коллекцию"
|
||||
>
|
||||
<Copy size={16}/>
|
||||
</button>
|
||||
{#if !col.isInbox}
|
||||
<button class="icon-btn" onclick={() => startEdit(col)} title="Переименовать">
|
||||
<Pencil size={16}/>
|
||||
@@ -211,6 +273,10 @@
|
||||
font-size: 20px; cursor: pointer;
|
||||
}
|
||||
.btn-create:disabled { opacity: .4; cursor: default; }
|
||||
.create-error {
|
||||
margin: 0 0 6px; padding: 8px 12px; border-radius: 8px;
|
||||
background: #fdecea; color: #c62828; font-size: 13px; line-height: 1.4;
|
||||
}
|
||||
|
||||
/* Список */
|
||||
.hint { text-align: center; padding: 32px; color: var(--tg-hint, #888); }
|
||||
@@ -237,6 +303,11 @@
|
||||
background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff);
|
||||
border-radius: 4px; padding: 1px 5px;
|
||||
}
|
||||
.badge-nsfw {
|
||||
font-size: 11px; font-weight: 700; letter-spacing: .03em;
|
||||
background: #e53935; color: #fff;
|
||||
border-radius: 4px; padding: 1px 5px;
|
||||
}
|
||||
|
||||
/* Inline-редактор */
|
||||
.edit-input {
|
||||
@@ -256,9 +327,14 @@
|
||||
}
|
||||
.icon-btn:hover { background: var(--tg-secondary-bg, #e8e8e8); color: var(--tg-text, #000); }
|
||||
.icon-btn.star:hover { color: #f5a623; }
|
||||
.icon-btn.del:hover { color: #e53935; }
|
||||
.icon-btn.del:hover { color: #e53935; }
|
||||
.icon-btn.clone:hover { color: #7e57c2; }
|
||||
.icon-btn.clone:disabled { opacity: .4; cursor: default; }
|
||||
.icon-btn.ok { color: #43a047; }
|
||||
.icon-btn.cancel { color: var(--tg-hint, #999); }
|
||||
.icon-btn.nsfw { color: var(--tg-hint, #999); }
|
||||
.icon-btn.nsfw:hover { color: #e53935; background: var(--tg-secondary-bg, #e8e8e8); }
|
||||
.icon-btn.nsfw--on { color: #e53935; }
|
||||
|
||||
/* Подтверждение */
|
||||
.confirm-panel {
|
||||
|
||||
@@ -1,34 +1,76 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import { Trash2, FolderInput, Plus, Pencil, Check, X } from 'lucide-svelte'
|
||||
import { api } from '../lib/api.js'
|
||||
import { isAttachmentMode, getQueryId, close as tgClose, showAlert } from '../lib/telegram.js'
|
||||
import { showAlert } from '../lib/telegram.js'
|
||||
import { collectionsStore } from '../stores/collections.svelte.js'
|
||||
import { urlCache } from '../lib/urlCache.js'
|
||||
|
||||
const attachMode = isAttachmentMode()
|
||||
const queryId = getQueryId()
|
||||
|
||||
// Types that have a downloadable file preview
|
||||
const PREVIEWABLE = new Set(['Photo', 'Video', 'Animation', 'Sticker'])
|
||||
|
||||
let items = []
|
||||
let query = ''
|
||||
let loading = true
|
||||
let error = null
|
||||
let items = $state([])
|
||||
let query = $state('')
|
||||
let includeNsfw = $state(false)
|
||||
let loading = $state(true)
|
||||
let error = $state(null)
|
||||
let previews = $state({})
|
||||
|
||||
// Map of itemId → { url: string|null, loading: boolean, error: boolean }
|
||||
let previews = {}
|
||||
// Создание текстовой записи
|
||||
let showCreate = $state(false)
|
||||
let newCaption = $state('')
|
||||
let newTags = $state('')
|
||||
let creating = $state(false)
|
||||
|
||||
async function handleCreate() {
|
||||
if (!newCaption.trim()) return
|
||||
creating = true
|
||||
try {
|
||||
const tags = newTags
|
||||
.split(/[\s,]+/)
|
||||
.map(t => t.replace(/^#/, '').trim().toLowerCase())
|
||||
.filter(Boolean)
|
||||
await api.createText(newCaption.trim(), tags)
|
||||
showCreate = false
|
||||
newCaption = ''
|
||||
newTags = ''
|
||||
await load()
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
} finally {
|
||||
creating = false
|
||||
}
|
||||
}
|
||||
|
||||
// Копирование в коллекцию
|
||||
let copyTarget = $state(null)
|
||||
let copying = $state(null)
|
||||
|
||||
// Редактирование
|
||||
let editTarget = $state(null) // id редактируемого элемента
|
||||
let editCaption = $state('')
|
||||
let editTags = $state('') // теги через пробел, без #
|
||||
let saving = $state(false)
|
||||
let editInlineTitle = $state('')
|
||||
let editInlineDesc = $state('')
|
||||
|
||||
async function load() {
|
||||
loading = true
|
||||
error = null
|
||||
previews = {}
|
||||
loading = true; error = null
|
||||
try {
|
||||
items = await api.getMedia(query)
|
||||
// Kick off preview loading for each previewable item (fire & forget)
|
||||
items = await api.getMedia(query, includeNsfw)
|
||||
// Rebuild previews: use cache for known items, fetch only uncached
|
||||
const next = {}
|
||||
for (const item of items) {
|
||||
if (PREVIEWABLE.has(item.mediaType)) {
|
||||
loadPreview(item.id)
|
||||
if (!PREVIEWABLE.has(item.mediaType)) continue
|
||||
if (urlCache[item.id]) {
|
||||
next[item.id] = { url: urlCache[item.id], loading: false, error: false }
|
||||
} else {
|
||||
next[item.id] = { url: null, loading: true, error: false }
|
||||
}
|
||||
}
|
||||
previews = next
|
||||
for (const item of items) {
|
||||
if (PREVIEWABLE.has(item.mediaType) && !urlCache[item.id]) loadPreview(item.id)
|
||||
}
|
||||
} catch (e) {
|
||||
error = e.message
|
||||
} finally {
|
||||
@@ -37,21 +79,44 @@
|
||||
}
|
||||
|
||||
async function loadPreview(id) {
|
||||
previews[id] = { url: null, loading: true, error: false }
|
||||
try {
|
||||
const url = await api.getDownloadUrl(id)
|
||||
previews[id] = { url, loading: false, error: false }
|
||||
urlCache[id] = url
|
||||
previews = { ...previews, [id]: { url, loading: false, error: false } }
|
||||
} catch {
|
||||
previews[id] = { url: null, loading: false, error: true }
|
||||
previews = { ...previews, [id]: { url: null, loading: false, error: true } }
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSendToChat(id) {
|
||||
async function openCopyPicker(id) {
|
||||
editTarget = null
|
||||
copyTarget = copyTarget === id ? null : id
|
||||
if (copyTarget !== null) {
|
||||
try {
|
||||
await collectionsStore.load()
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
copyTarget = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCopy(mediaId, collectionId) {
|
||||
copying = collectionId
|
||||
try {
|
||||
await api.sendToChat(id, queryId)
|
||||
tgClose()
|
||||
const result = await api.copyMedia(mediaId, collectionId)
|
||||
const original = items.find(i => i.id === mediaId)
|
||||
if (original && result?.id) {
|
||||
const newItem = { ...original, id: result.id, collectionId }
|
||||
items = [newItem, ...items]
|
||||
if (previews[mediaId]) previews = { ...previews, [result.id]: previews[mediaId] }
|
||||
if (urlCache[mediaId]) urlCache[result.id] = urlCache[mediaId]
|
||||
}
|
||||
copyTarget = null
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
} finally {
|
||||
copying = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,55 +126,143 @@
|
||||
items = items.filter((i) => i.id !== id)
|
||||
const { [id]: _, ...rest } = previews
|
||||
previews = rest
|
||||
delete urlCache[id]
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
function openEditPanel(item) {
|
||||
copyTarget = null
|
||||
if (editTarget === item.id) {
|
||||
editTarget = null
|
||||
return
|
||||
}
|
||||
editTarget = item.id
|
||||
editCaption = item.caption ?? ''
|
||||
editTags = item.tags?.join(' ') ?? ''
|
||||
editInlineTitle = item.inlineTitle ?? ''
|
||||
editInlineDesc = item.inlineDescription ?? ''
|
||||
}
|
||||
|
||||
function cancelEdit() {
|
||||
editTarget = null
|
||||
}
|
||||
|
||||
async function handleSave(id) {
|
||||
saving = true
|
||||
try {
|
||||
const tags = editTags
|
||||
.split(/[\s,]+/)
|
||||
.map(t => t.replace(/^#/, '').trim().toLowerCase())
|
||||
.filter(Boolean)
|
||||
await api.updateMedia(id, {
|
||||
caption: editCaption || null,
|
||||
tags,
|
||||
inlineTitle: editInlineTitle.trim() || null,
|
||||
inlineDescription: editInlineDesc.trim() || null,
|
||||
})
|
||||
// Обновляем локально
|
||||
const idx = items.findIndex(i => i.id === id)
|
||||
if (idx !== -1) {
|
||||
items[idx] = { ...items[idx], caption: editCaption || null, tags,
|
||||
inlineTitle: editInlineTitle.trim() || null,
|
||||
inlineDescription: editInlineDesc.trim() || null }
|
||||
}
|
||||
editTarget = null
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
} finally {
|
||||
saving = false
|
||||
}
|
||||
}
|
||||
|
||||
let searchTimer
|
||||
function onSearch() {
|
||||
clearTimeout(searchTimer)
|
||||
searchTimer = setTimeout(load, 400)
|
||||
}
|
||||
|
||||
onMount(load)
|
||||
function toggleNsfw() {
|
||||
includeNsfw = !includeNsfw
|
||||
load()
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
collectionsStore.load().catch(() => {})
|
||||
await load()
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="page">
|
||||
{#if attachMode}
|
||||
<div class="attach-banner">Выберите медиа для отправки в чат</div>
|
||||
<div class="search-row">
|
||||
<input
|
||||
class="search"
|
||||
placeholder="Поиск: #мем -#кот слово"
|
||||
bind:value={query}
|
||||
oninput={onSearch}
|
||||
/>
|
||||
<button
|
||||
class="nsfw-toggle"
|
||||
class:nsfw-toggle--on={includeNsfw}
|
||||
onclick={toggleNsfw}
|
||||
title={includeNsfw ? 'Скрыть 18+' : 'Показать 18+'}
|
||||
>18+</button>
|
||||
<button
|
||||
class="btn-add"
|
||||
class:btn-add--active={showCreate}
|
||||
onclick={() => showCreate = !showCreate}
|
||||
title="Создать текстовую запись"
|
||||
><Plus size={18}/></button>
|
||||
</div>
|
||||
|
||||
{#if showCreate}
|
||||
<div class="create-panel">
|
||||
<textarea
|
||||
class="create-textarea"
|
||||
placeholder="Текст записи…"
|
||||
bind:value={newCaption}
|
||||
rows="3"
|
||||
onkeydown={(e) => { if (e.key === 'Escape') showCreate = false }}
|
||||
></textarea>
|
||||
<input
|
||||
class="create-tags"
|
||||
placeholder="Теги: мем реакция кот"
|
||||
bind:value={newTags}
|
||||
onkeydown={(e) => { if (e.key === 'Escape') showCreate = false }}
|
||||
/>
|
||||
<div class="create-actions">
|
||||
<button class="btn-save" onclick={handleCreate} disabled={creating || !newCaption.trim()}>
|
||||
{creating ? 'Сохранение…' : 'Сохранить'}
|
||||
</button>
|
||||
<button class="btn-cancel" onclick={() => { showCreate = false; newCaption = ''; newTags = '' }}>
|
||||
Отмена
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<input
|
||||
class="search"
|
||||
placeholder="Поиск: #мем -#кот слово"
|
||||
bind:value={query}
|
||||
on:input={onSearch}
|
||||
/>
|
||||
|
||||
{#if loading}
|
||||
<div class="hint">Загрузка…</div>
|
||||
{:else if error}
|
||||
<div class="hint error">{error}</div>
|
||||
{:else if items.length === 0}
|
||||
<div class="hint">Нет медиа</div>
|
||||
<div class="hint">Нет медиа{query ? ' по запросу' : ''}</div>
|
||||
{:else}
|
||||
<ul class="list">
|
||||
{#each items as item (item.id)}
|
||||
{@const preview = previews[item.id]}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-noninteractive-element-interactions -->
|
||||
<li
|
||||
class="item"
|
||||
class:item--attach={attachMode}
|
||||
on:click={attachMode ? () => handleSendToChat(item.id) : undefined}
|
||||
role={attachMode ? 'button' : undefined}
|
||||
>
|
||||
{@const col = collectionsStore.items.find(c => c.id === item.collectionId)}
|
||||
{@const colName = col?.name}
|
||||
{@const isNsfw = col?.isNsfw}
|
||||
<li class="item">
|
||||
{#if PREVIEWABLE.has(item.mediaType)}
|
||||
<div class="thumb-wrap">
|
||||
{#if preview?.loading || !preview}
|
||||
<div class="thumb-skeleton" aria-hidden="true"></div>
|
||||
<div class="thumb-skeleton"></div>
|
||||
{:else if preview.url}
|
||||
{#if item.mediaType === 'Video'}
|
||||
<video class="thumb" src={preview.url} muted preload="metadata" />
|
||||
{#if item.mediaType === 'Video' || item.mediaType === 'Animation'}
|
||||
<video class="thumb" src={preview.url} muted preload="metadata" loop autoplay playsinline />
|
||||
{:else}
|
||||
<img class="thumb" src={preview.url} alt={item.caption ?? item.mediaType} loading="lazy" />
|
||||
{/if}
|
||||
@@ -117,13 +270,22 @@
|
||||
<div class="thumb-error" title="Не удалось загрузить">🖼</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="thumb-wrap thumb-text">
|
||||
<span class="text-icon">T</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="item-info">
|
||||
<span class="item-type">{item.mediaType}</span>
|
||||
{#if item.caption}
|
||||
<span class="item-caption">{item.caption}</span>
|
||||
{/if}
|
||||
<div class="item-meta">
|
||||
<span class="item-type">{item.mediaType}</span>
|
||||
{#if colName}
|
||||
<span class="item-col">· {colName}</span>
|
||||
{/if}
|
||||
{#if isNsfw}
|
||||
<span class="item-nsfw">18+</span>
|
||||
{/if}
|
||||
</div>
|
||||
{#if item.tags?.length}
|
||||
<div class="tags">
|
||||
{#each item.tags as tag}
|
||||
@@ -131,13 +293,103 @@
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{#if item.caption}
|
||||
<span class="item-caption">{item.caption}</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="item-actions">
|
||||
<button
|
||||
class="icon-btn"
|
||||
class:icon-btn--active={editTarget === item.id}
|
||||
onclick={() => openEditPanel(item)}
|
||||
title="Редактировать"
|
||||
><Pencil size={16}/></button>
|
||||
<button
|
||||
class="icon-btn"
|
||||
class:icon-btn--active={copyTarget === item.id}
|
||||
onclick={() => openCopyPicker(item.id)}
|
||||
title="Копировать в коллекцию"
|
||||
><FolderInput size={16}/></button>
|
||||
<button class="icon-btn del" onclick={() => handleDelete(item.id)} title="Удалить"><Trash2 size={16}/></button>
|
||||
</div>
|
||||
{#if attachMode}
|
||||
<span class="attach-hint">Отправить</span>
|
||||
{:else}
|
||||
<button class="del" on:click={() => handleDelete(item.id)} title="Удалить">✕</button>
|
||||
{/if}
|
||||
</li>
|
||||
|
||||
{#if editTarget === item.id}
|
||||
<li class="edit-panel">
|
||||
<textarea
|
||||
class="edit-input edit-textarea"
|
||||
placeholder="Подпись"
|
||||
bind:value={editCaption}
|
||||
rows="3"
|
||||
onkeydown={(e) => { if (e.key === 'Escape') cancelEdit() }}
|
||||
></textarea>
|
||||
<input
|
||||
class="edit-input"
|
||||
placeholder="Теги: мем реакция кот"
|
||||
bind:value={editTags}
|
||||
onkeydown={(e) => { if (e.key === 'Escape') cancelEdit() }}
|
||||
/>
|
||||
{#if item.mediaType !== 'Sticker'}
|
||||
<input
|
||||
class="edit-input edit-input--inline"
|
||||
placeholder="Заголовок в пикере (необязательно)"
|
||||
bind:value={editInlineTitle}
|
||||
onkeydown={(e) => { if (e.key === 'Escape') cancelEdit() }}
|
||||
/>
|
||||
{/if}
|
||||
{#if item.mediaType === 'Photo' || item.mediaType === 'Video' || item.mediaType === 'Text'}
|
||||
<input
|
||||
class="edit-input edit-input--inline"
|
||||
placeholder="Описание в пикере (необязательно)"
|
||||
bind:value={editInlineDesc}
|
||||
onkeydown={(e) => { if (e.key === 'Escape') cancelEdit() }}
|
||||
/>
|
||||
{/if}
|
||||
<div class="edit-actions">
|
||||
<button
|
||||
class="icon-btn ok"
|
||||
onclick={() => handleSave(item.id)}
|
||||
disabled={saving}
|
||||
title="Сохранить"
|
||||
><Check size={16}/></button>
|
||||
<button
|
||||
class="icon-btn cancel"
|
||||
onclick={cancelEdit}
|
||||
disabled={saving}
|
||||
title="Отмена"
|
||||
><X size={16}/></button>
|
||||
</div>
|
||||
</li>
|
||||
{/if}
|
||||
|
||||
{#if copyTarget === item.id}
|
||||
<li class="copy-panel">
|
||||
{#if collectionsStore.loading}
|
||||
<div class="copy-hint">Загрузка…</div>
|
||||
{:else if collectionsStore.items.length === 0}
|
||||
<div class="copy-hint">Нет коллекций</div>
|
||||
{:else}
|
||||
<div class="copy-hint">Копировать в:</div>
|
||||
<ul class="copy-list">
|
||||
{#each collectionsStore.items as col (col.id)}
|
||||
<li>
|
||||
<button
|
||||
class="copy-col"
|
||||
class:copy-col--busy={copying === col.id}
|
||||
disabled={!!copying}
|
||||
onclick={() => handleCopy(item.id, col.id)}
|
||||
>
|
||||
{col.name}
|
||||
{#if col.isInbox}<span class="copy-badge">основная</span>{/if}
|
||||
{#if col.isNsfw}<span class="copy-badge copy-badge--nsfw">18+</span>{/if}
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
@@ -145,19 +397,67 @@
|
||||
|
||||
<style>
|
||||
.page { padding: 8px; }
|
||||
.attach-banner {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
color: var(--tg-hint, #888);
|
||||
padding: 6px 0 4px;
|
||||
|
||||
.search-row {
|
||||
display: flex; gap: 6px; margin-bottom: 8px;
|
||||
}
|
||||
.search {
|
||||
width: 100%; box-sizing: border-box;
|
||||
flex: 1; box-sizing: border-box;
|
||||
padding: 8px 12px; border-radius: 8px; border: none;
|
||||
background: var(--tg-secondary-bg, #f0f0f0);
|
||||
color: var(--tg-text, #000);
|
||||
font-size: 14px; margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.nsfw-toggle {
|
||||
flex-shrink: 0;
|
||||
padding: 0 10px; border-radius: 8px; border: none;
|
||||
background: var(--tg-secondary-bg, #f0f0f0);
|
||||
color: var(--tg-hint, #888);
|
||||
font-size: 12px; font-weight: 700; cursor: pointer;
|
||||
transition: background .15s, color .15s;
|
||||
}
|
||||
.nsfw-toggle--on {
|
||||
background: #e53935; color: #fff;
|
||||
}
|
||||
.btn-add {
|
||||
flex-shrink: 0; width: 36px; height: 36px;
|
||||
border-radius: 8px; border: none;
|
||||
background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
cursor: pointer; transition: opacity .15s;
|
||||
}
|
||||
.btn-add--active { opacity: .75; }
|
||||
.create-panel {
|
||||
background: var(--tg-secondary-bg, #f5f5f5);
|
||||
border-radius: 10px; padding: 10px 12px;
|
||||
border-left: 3px solid var(--tg-button, #2196f3);
|
||||
margin-bottom: 8px;
|
||||
display: flex; flex-direction: column; gap: 6px;
|
||||
}
|
||||
.create-textarea, .create-tags {
|
||||
width: 100%; box-sizing: border-box;
|
||||
padding: 8px 10px; border-radius: 6px; border: none;
|
||||
background: var(--tg-bg, #fff); color: var(--tg-text, #000);
|
||||
font-size: 14px; font-family: inherit; resize: none;
|
||||
outline: 1px solid var(--tg-secondary-bg, #ddd);
|
||||
}
|
||||
.create-textarea:focus, .create-tags:focus {
|
||||
outline: 2px solid var(--tg-button, #2196f3);
|
||||
}
|
||||
.create-actions { display: flex; gap: 6px; }
|
||||
.btn-save {
|
||||
padding: 6px 14px; border-radius: 8px; border: none;
|
||||
background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff);
|
||||
font-size: 13px; font-weight: 500; cursor: pointer;
|
||||
}
|
||||
.btn-save:disabled { opacity: .4; cursor: default; }
|
||||
.btn-cancel {
|
||||
padding: 6px 14px; border-radius: 8px; border: none;
|
||||
background: none; color: var(--tg-hint, #888);
|
||||
font-size: 13px; font-weight: 500; cursor: pointer;
|
||||
}
|
||||
.btn-cancel:hover { background: var(--tg-secondary-bg, #e8e8e8); }
|
||||
|
||||
.hint { text-align: center; padding: 32px; color: var(--tg-hint, #888); }
|
||||
.error { color: #e53935; }
|
||||
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
|
||||
@@ -169,13 +469,10 @@
|
||||
|
||||
/* ── Thumbnail ──────────────────────────────────────────────────────────── */
|
||||
.thumb-wrap {
|
||||
flex-shrink: 0;
|
||||
width: 64px; height: 64px;
|
||||
flex-shrink: 0; width: 64px; height: 64px;
|
||||
border-radius: 6px; overflow: hidden;
|
||||
}
|
||||
.thumb {
|
||||
width: 100%; height: 100%; object-fit: cover; display: block;
|
||||
}
|
||||
.thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||
.thumb-skeleton {
|
||||
width: 100%; height: 100%;
|
||||
background: linear-gradient(90deg,
|
||||
@@ -189,9 +486,14 @@
|
||||
.thumb-error {
|
||||
width: 100%; height: 100%;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-size: 24px;
|
||||
background: var(--tg-secondary-bg, #eee);
|
||||
font-size: 24px; background: var(--tg-secondary-bg, #eee);
|
||||
}
|
||||
.thumb-text {
|
||||
background: var(--tg-secondary-bg, #e8e8e8);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.text-icon { font-size: 24px; font-weight: 700; color: var(--tg-hint, #888); }
|
||||
|
||||
@keyframes shimmer {
|
||||
0% { background-position: 200% 0; }
|
||||
100% { background-position: -200% 0; }
|
||||
@@ -199,29 +501,76 @@
|
||||
|
||||
/* ── Text info ──────────────────────────────────────────────────────────── */
|
||||
.item-info { flex: 1; min-width: 0; }
|
||||
.item-meta { display: flex; align-items: baseline; gap: 4px; }
|
||||
.item-type { font-size: 11px; color: var(--tg-hint, #888); text-transform: uppercase; }
|
||||
.item-caption { display: block; font-size: 14px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.item-col { font-size: 11px; color: var(--tg-hint, #888); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.item-caption { display: block; font-size: 14px; margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
|
||||
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
|
||||
.tag {
|
||||
font-size: 12px; background: var(--tg-button, #2196f3);
|
||||
color: var(--tg-btn-text, #fff); border-radius: 4px; padding: 1px 6px;
|
||||
}
|
||||
.item--attach {
|
||||
cursor: pointer;
|
||||
.item-actions { display: flex; flex-direction: row; gap: 2px; flex-shrink: 0; align-self: flex-start; }
|
||||
|
||||
.icon-btn {
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
width: 32px; height: 32px; border-radius: 8px; border: none;
|
||||
background: none; color: var(--tg-hint, #888); cursor: pointer;
|
||||
transition: background .15s, color .15s;
|
||||
}
|
||||
.item--attach:active {
|
||||
opacity: 0.7;
|
||||
.icon-btn:hover { background: var(--tg-secondary-bg, #e8e8e8); color: var(--tg-text, #000); }
|
||||
.icon-btn--active { color: var(--tg-button, #2196f3); }
|
||||
.icon-btn.del:hover { color: #e53935; }
|
||||
.icon-btn.ok { color: #43a047; }
|
||||
.icon-btn.ok:hover { color: #43a047; background: var(--tg-secondary-bg, #e8e8e8); }
|
||||
.icon-btn.cancel { color: var(--tg-hint, #999); }
|
||||
.icon-btn:disabled { opacity: .4; cursor: default; }
|
||||
|
||||
/* ── Edit panel ─────────────────────────────────────────────────────────── */
|
||||
.edit-panel {
|
||||
background: var(--tg-secondary-bg, #f5f5f5);
|
||||
border-radius: 10px; padding: 10px 12px;
|
||||
border-left: 3px solid #43a047;
|
||||
display: flex; flex-direction: column; gap: 6px;
|
||||
}
|
||||
.attach-hint {
|
||||
font-size: 12px;
|
||||
color: var(--tg-button, #2196f3);
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
align-self: center;
|
||||
.edit-input {
|
||||
width: 100%; padding: 7px 10px; border-radius: 7px; border: none;
|
||||
background: var(--tg-bg, #fff); color: var(--tg-text, #000);
|
||||
font-size: 14px;
|
||||
outline: 1px solid var(--tg-hint, #ccc);
|
||||
}
|
||||
.del {
|
||||
background: none; border: none; color: var(--tg-hint, #888);
|
||||
font-size: 16px; cursor: pointer; padding: 0; flex-shrink: 0;
|
||||
align-self: flex-start;
|
||||
.edit-input:focus { outline-color: #43a047; }
|
||||
.edit-textarea { resize: vertical; font-family: inherit; }
|
||||
.edit-input--inline { font-size: 12px; color: var(--tg-hint, #888); }
|
||||
.edit-input--inline::placeholder { font-style: italic; }
|
||||
.edit-actions { display: flex; gap: 4px; justify-content: flex-end; }
|
||||
|
||||
/* ── Copy panel ─────────────────────────────────────────────────────────── */
|
||||
.copy-panel {
|
||||
background: var(--tg-secondary-bg, #f5f5f5);
|
||||
border-radius: 10px; padding: 10px 12px;
|
||||
border-left: 3px solid var(--tg-button, #2196f3);
|
||||
}
|
||||
.copy-hint { font-size: 12px; color: var(--tg-hint, #888); margin-bottom: 6px; }
|
||||
.copy-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
|
||||
.copy-col {
|
||||
width: 100%; text-align: left; background: none; border: none;
|
||||
padding: 6px 8px; border-radius: 6px; cursor: pointer;
|
||||
font-size: 14px; color: var(--tg-text, #000);
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
transition: background .12s;
|
||||
}
|
||||
.copy-col:hover:not(:disabled) { background: var(--tg-bg, #fff); }
|
||||
.copy-col:disabled { opacity: .5; cursor: default; }
|
||||
.copy-col--busy { opacity: .5; }
|
||||
.copy-badge--nsfw { background: #e53935; }
|
||||
.copy-badge {
|
||||
font-size: 10px; background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff);
|
||||
border-radius: 3px; padding: 1px 4px;
|
||||
}
|
||||
.item-nsfw {
|
||||
font-size: 10px; font-weight: 700; letter-spacing: .02em;
|
||||
background: #e53935; color: #fff;
|
||||
border-radius: 3px; padding: 1px 5px; flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
<script>
|
||||
import { User, Users, Megaphone } from 'lucide-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
import { api } from '../lib/api.js'
|
||||
import { getQueryId, getChatName, getChatType, close as tgClose, showAlert } from '../lib/telegram.js'
|
||||
|
||||
const queryId = getQueryId()
|
||||
const chatName = getChatName()
|
||||
const chatType = getChatType()
|
||||
|
||||
const PREVIEWABLE = new Set(['Photo', 'Video', 'Animation', 'Sticker'])
|
||||
|
||||
let items = $state([])
|
||||
let query = $state('')
|
||||
let loading = $state(true)
|
||||
let error = $state(null)
|
||||
let sending = $state(null) // id медиа, которое сейчас отправляется
|
||||
|
||||
let previews = $state({})
|
||||
|
||||
async function load() {
|
||||
loading = true; error = null; previews = {}
|
||||
try {
|
||||
items = await api.getMedia(query)
|
||||
for (const item of items) {
|
||||
if (PREVIEWABLE.has(item.mediaType)) loadPreview(item.id)
|
||||
}
|
||||
} catch (e) {
|
||||
error = e.message
|
||||
} finally {
|
||||
loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPreview(id) {
|
||||
previews = { ...previews, [id]: { url: null, loading: true, error: false } }
|
||||
try {
|
||||
const url = await api.getDownloadUrl(id)
|
||||
previews = { ...previews, [id]: { url, loading: false, error: false } }
|
||||
} catch {
|
||||
previews = { ...previews, [id]: { url: null, loading: false, error: true } }
|
||||
}
|
||||
}
|
||||
|
||||
async function send(id) {
|
||||
if (sending) return
|
||||
sending = id
|
||||
try {
|
||||
await api.sendToChat(id, queryId)
|
||||
tgClose()
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
sending = null
|
||||
}
|
||||
}
|
||||
|
||||
let searchTimer
|
||||
function onSearch() {
|
||||
clearTimeout(searchTimer)
|
||||
searchTimer = setTimeout(load, 400)
|
||||
}
|
||||
|
||||
onMount(load)
|
||||
</script>
|
||||
|
||||
<div class="page">
|
||||
<div class="header">
|
||||
<div class="title">Отправить в чат</div>
|
||||
{#if chatName}
|
||||
<div class="chat-name">
|
||||
{#if chatType === 'private'}
|
||||
<User size={14} strokeWidth={2} />
|
||||
{:else if chatType === 'channel'}
|
||||
<Megaphone size={14} strokeWidth={2} />
|
||||
{:else if chatType === 'group' || chatType === 'supergroup'}
|
||||
<Users size={14} strokeWidth={2} />
|
||||
{/if}
|
||||
{chatName}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<input
|
||||
class="search"
|
||||
placeholder="Поиск: #мем -#кот слово"
|
||||
bind:value={query}
|
||||
oninput={onSearch}
|
||||
/>
|
||||
|
||||
{#if loading}
|
||||
<div class="hint">Загрузка…</div>
|
||||
{:else if error}
|
||||
<div class="hint error">{error}</div>
|
||||
{:else if items.length === 0}
|
||||
<div class="hint">Нет медиа{query ? ' по запросу' : ''}</div>
|
||||
{:else}
|
||||
<ul class="list">
|
||||
{#each items as item (item.id)}
|
||||
{@const preview = previews[item.id]}
|
||||
{@const isSending = sending === item.id}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-noninteractive-element-interactions -->
|
||||
<li
|
||||
class="item"
|
||||
class:item--sending={isSending}
|
||||
onclick={() => send(item.id)}
|
||||
role="button"
|
||||
>
|
||||
{#if PREVIEWABLE.has(item.mediaType)}
|
||||
<div class="thumb-wrap">
|
||||
{#if preview?.loading || !preview}
|
||||
<div class="thumb-skeleton"></div>
|
||||
{:else if preview.url}
|
||||
{#if item.mediaType === 'Video'}
|
||||
<video class="thumb" src={preview.url} muted preload="metadata" />
|
||||
{:else}
|
||||
<img class="thumb" src={preview.url} alt={item.caption ?? item.mediaType} loading="lazy" />
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="thumb-error">🖼</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="thumb-wrap thumb-text">
|
||||
<span class="text-icon">T</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="item-info">
|
||||
<span class="item-type">{item.mediaType}</span>
|
||||
{#if item.caption}
|
||||
<span class="item-caption">{item.caption}</span>
|
||||
{/if}
|
||||
{#if item.tags?.length}
|
||||
<div class="tags">
|
||||
{#each item.tags as tag}
|
||||
<span class="tag">#{tag}</span>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<span class="send-label">
|
||||
{#if isSending}…{:else}→{/if}
|
||||
</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.page { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
|
||||
|
||||
.header {
|
||||
padding: 12px 12px 4px;
|
||||
}
|
||||
.title {
|
||||
font-size: 16px; font-weight: 600; color: var(--tg-text, #000);
|
||||
}
|
||||
.chat-name {
|
||||
font-size: 13px; color: var(--tg-hint, #888); margin-top: 2px;
|
||||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||||
display: flex; align-items: center; gap: 4px;
|
||||
}
|
||||
.chat-name :global(svg) { flex-shrink: 0; color: var(--tg-hint, #888); }
|
||||
|
||||
.search {
|
||||
margin: 4px 8px 6px; width: calc(100% - 16px);
|
||||
padding: 8px 12px; border-radius: 8px; border: none;
|
||||
background: var(--tg-secondary-bg, #f0f0f0);
|
||||
color: var(--tg-text, #000); font-size: 14px;
|
||||
}
|
||||
|
||||
.hint { text-align: center; padding: 32px; color: var(--tg-hint, #888); }
|
||||
.error { color: #e53935; }
|
||||
|
||||
.list {
|
||||
list-style: none; margin: 0; padding: 0 8px 8px;
|
||||
display: flex; flex-direction: column; gap: 6px;
|
||||
overflow-y: auto; flex: 1;
|
||||
}
|
||||
|
||||
.item {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
background: var(--tg-secondary-bg, #f5f5f5);
|
||||
border-radius: 10px; padding: 10px 12px;
|
||||
cursor: pointer; transition: opacity .15s;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.item:active, .item--sending { opacity: 0.6; }
|
||||
|
||||
/* ── Thumbnail ─────────────────────────────────────────────────────── */
|
||||
.thumb-wrap {
|
||||
flex-shrink: 0; width: 52px; height: 52px;
|
||||
border-radius: 6px; overflow: hidden;
|
||||
}
|
||||
.thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||
.thumb-skeleton {
|
||||
width: 100%; height: 100%;
|
||||
background: linear-gradient(90deg,
|
||||
var(--tg-secondary-bg, #e0e0e0) 25%,
|
||||
var(--tg-bg, #f5f5f5) 50%,
|
||||
var(--tg-secondary-bg, #e0e0e0) 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.4s infinite;
|
||||
}
|
||||
.thumb-error {
|
||||
width: 100%; height: 100%;
|
||||
display: flex; align-items: center; justify-content: center; font-size: 20px;
|
||||
background: var(--tg-secondary-bg, #eee);
|
||||
}
|
||||
.thumb-text {
|
||||
background: var(--tg-secondary-bg, #e8e8e8);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.text-icon { font-size: 20px; font-weight: 700; color: var(--tg-hint, #888); }
|
||||
|
||||
@keyframes shimmer {
|
||||
0% { background-position: 200% 0; }
|
||||
100% { background-position: -200% 0; }
|
||||
}
|
||||
|
||||
/* ── Text info ─────────────────────────────────────────────────────── */
|
||||
.item-info { flex: 1; min-width: 0; }
|
||||
.item-type { font-size: 11px; color: var(--tg-hint, #888); text-transform: uppercase; }
|
||||
.item-caption { display: block; font-size: 14px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
|
||||
.tag {
|
||||
font-size: 11px; background: var(--tg-button, #2196f3);
|
||||
color: var(--tg-btn-text, #fff); border-radius: 4px; padding: 1px 5px;
|
||||
}
|
||||
|
||||
.send-label {
|
||||
font-size: 18px; color: var(--tg-button, #2196f3);
|
||||
flex-shrink: 0; font-weight: 500;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user