too many changes
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import { jwt, isAuthed } from './stores/auth.js'
|
||||
import { api } from './lib/api.js'
|
||||
import { initData, applyTheme } from './lib/telegram.js'
|
||||
import MediaPage from './pages/MediaPage.svelte'
|
||||
import CollectionsPage from './pages/CollectionsPage.svelte'
|
||||
|
||||
let tab = 'media' // 'media' | 'collections'
|
||||
let authError = null
|
||||
let authing = true
|
||||
|
||||
function devTokenFromHash() {
|
||||
if (!import.meta.env.DEV) return null
|
||||
const params = new URLSearchParams(window.location.hash.slice(1))
|
||||
return params.get('token') ?? null
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
applyTheme()
|
||||
|
||||
// Dev-режим: #token=<jwt> в URL — пропускаем обмен initData
|
||||
const devToken = devTokenFromHash()
|
||||
if (devToken) {
|
||||
jwt.set(devToken)
|
||||
authing = false
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const { token } = await api.auth(initData)
|
||||
jwt.set(token)
|
||||
} catch (e) {
|
||||
authError = e.message
|
||||
} finally {
|
||||
authing = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<main>
|
||||
{#if authing}
|
||||
<div class="splash">Загрузка…</div>
|
||||
{:else if authError}
|
||||
<div class="splash error">Ошибка авторизации:<br/>{authError}</div>
|
||||
{:else if $isAuthed}
|
||||
<nav>
|
||||
<button class:active={tab === 'media'} on:click={() => (tab = 'media')}>Медиа</button>
|
||||
<button class:active={tab === 'collections'} on:click={() => (tab = 'collections')}>Коллекции</button>
|
||||
</nav>
|
||||
|
||||
{#if tab === 'media'}
|
||||
<MediaPage />
|
||||
{:else}
|
||||
<CollectionsPage />
|
||||
{/if}
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
<style>
|
||||
:global(*) { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
:global(body) {
|
||||
background: var(--tg-bg, #fff);
|
||||
color: var(--tg-text, #000);
|
||||
font-family: system-ui, -apple-system, sans-serif;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
main { display: flex; flex-direction: column; height: 100vh; }
|
||||
|
||||
.splash {
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
height: 100vh; color: var(--tg-hint, #888); font-size: 16px; text-align: center; padding: 24px;
|
||||
}
|
||||
.error { color: #e53935; }
|
||||
|
||||
nav {
|
||||
display: flex; border-bottom: 1px solid var(--tg-hint, #ccc);
|
||||
background: var(--tg-bg, #fff); position: sticky; top: 0; z-index: 10;
|
||||
}
|
||||
nav button {
|
||||
flex: 1; padding: 12px; border: none; background: none;
|
||||
color: var(--tg-hint, #888); font-size: 15px; cursor: pointer;
|
||||
border-bottom: 2px solid transparent;
|
||||
}
|
||||
nav button.active {
|
||||
color: var(--tg-button, #2196f3);
|
||||
border-bottom-color: var(--tg-button, #2196f3);
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,49 @@
|
||||
import { get } from 'svelte/store'
|
||||
import { jwt } from '../stores/auth.js'
|
||||
|
||||
const BASE = '/api'
|
||||
|
||||
async function request(method, path, body) {
|
||||
const token = get(jwt)
|
||||
const headers = { 'Content-Type': 'application/json' }
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`
|
||||
|
||||
const res = await fetch(BASE + path, {
|
||||
method,
|
||||
headers,
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text()
|
||||
throw new Error(`${res.status}: ${text}`)
|
||||
}
|
||||
|
||||
const ct = res.headers.get('content-type') ?? ''
|
||||
return ct.includes('application/json') ? res.json() : null
|
||||
}
|
||||
|
||||
export const api = {
|
||||
// ── Auth ──────────────────────────────────────────────────────────────────
|
||||
auth: (initData) => request('POST', '/auth/telegram', { initData }),
|
||||
|
||||
// ── Media ─────────────────────────────────────────────────────────────────
|
||||
getMedia: (q) => request('GET', `/media${q ? `?q=${encodeURIComponent(q)}` : ''}`),
|
||||
getDownloadUrl: (id) => request('GET', `/media/${id}/download-url`).then((r) => r?.url),
|
||||
sendToChat: (id, queryId) => request('POST', `/media/${id}/send`, { queryId }),
|
||||
updateMedia: (id, patch) => request('PATCH', `/media/${id}`, patch),
|
||||
deleteMedia: (id) => request('DELETE', `/media/${id}`),
|
||||
|
||||
// ── Collections ───────────────────────────────────────────────────────────
|
||||
getCollections: () => request('GET', '/collections'),
|
||||
createCollection: (name, description) => request('POST', '/collections', { name, description }),
|
||||
updateCollection: (id, name, description) => request('PATCH', `/collections/${id}`, { name, description }),
|
||||
deleteCollection: (id) => request('DELETE', `/collections/${id}`),
|
||||
setCollectionInbox: (id) => request('PUT', `/collections/${id}/inbox`),
|
||||
getCollectionItems: (id) => request('GET', `/collections/${id}/items`),
|
||||
|
||||
// ── Invites ───────────────────────────────────────────────────────────────
|
||||
getInvites: (collectionId) => request('GET', `/collections/${collectionId}/invites`),
|
||||
createInvite: (collectionId, role) => request('POST', `/collections/${collectionId}/invites`, { role }),
|
||||
revokeInvite: (collectionId, inviteId) => request('DELETE', `/collections/${collectionId}/invites/${inviteId}`),
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/** Обёртка над Telegram WebApp SDK */
|
||||
const tg = window.Telegram?.WebApp
|
||||
|
||||
export const webApp = tg
|
||||
|
||||
/** initData для обмена на JWT */
|
||||
export const initData = tg?.initData ?? ''
|
||||
|
||||
/** Закрыть Mini App */
|
||||
export const close = () => tg?.close()
|
||||
|
||||
/**
|
||||
* query_id присутствует когда Mini App открыта из меню «Приложить».
|
||||
* Используется для answerWebAppQuery: позволяет отправить контент в чат одним тапом.
|
||||
*/
|
||||
export const getQueryId = () => tg?.initDataUnsafe?.query_id ?? null
|
||||
export const isAttachmentMode = () => !!getQueryId()
|
||||
|
||||
/** Показать нативный алерт Telegram, или fallback на browser alert вне TG-контекста */
|
||||
export const showAlert = (msg) => {
|
||||
if (tg?.showAlert) tg.showAlert(msg)
|
||||
else alert(msg)
|
||||
}
|
||||
|
||||
/** Применить тему Telegram к CSS-переменным */
|
||||
export function applyTheme() {
|
||||
if (!tg) return
|
||||
tg.expand()
|
||||
tg.ready()
|
||||
const colors = tg.themeParams
|
||||
const root = document.documentElement.style
|
||||
if (colors.bg_color) root.setProperty('--tg-bg', colors.bg_color)
|
||||
if (colors.text_color) root.setProperty('--tg-text', colors.text_color)
|
||||
if (colors.hint_color) root.setProperty('--tg-hint', colors.hint_color)
|
||||
if (colors.link_color) root.setProperty('--tg-link', colors.link_color)
|
||||
if (colors.button_color) root.setProperty('--tg-button', colors.button_color)
|
||||
if (colors.button_text_color) root.setProperty('--tg-btn-text', colors.button_text_color)
|
||||
if (colors.secondary_bg_color) root.setProperty('--tg-secondary-bg', colors.secondary_bg_color)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { mount } from 'svelte'
|
||||
import App from './App.svelte'
|
||||
|
||||
mount(App, { target: document.getElementById('app') })
|
||||
@@ -0,0 +1,280 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import { Pencil, Trash2, Star, Check, X } from 'lucide-svelte'
|
||||
import { api } from '../lib/api.js'
|
||||
import { showAlert } from '../lib/telegram.js'
|
||||
|
||||
let collections = $state([])
|
||||
let loading = $state(true)
|
||||
let error = $state(null)
|
||||
let creating = $state(false)
|
||||
let newName = $state('')
|
||||
|
||||
// Inline-редактирование: { id, value }
|
||||
let editing = $state(null)
|
||||
|
||||
// Подтверждение удаления: id коллекции, которую хотим удалить
|
||||
let confirmDelete = $state(null)
|
||||
|
||||
// Подтверждение смены Inbox: id целевой коллекции
|
||||
let confirmInbox = $state(null)
|
||||
|
||||
$derived: var deleteTarget = collections.find(c => c.id === confirmDelete)
|
||||
$derived: var inboxTarget = collections.find(c => c.id === confirmInbox)
|
||||
|
||||
async function load() {
|
||||
loading = true; error = null
|
||||
try { collections = await api.getCollections() }
|
||||
catch (e) { error = e.message }
|
||||
finally { loading = false }
|
||||
}
|
||||
|
||||
async function createCollection() {
|
||||
if (!newName.trim()) return
|
||||
creating = true
|
||||
try {
|
||||
await api.createCollection(newName.trim(), null)
|
||||
newName = ''
|
||||
await load()
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
} finally { creating = false }
|
||||
}
|
||||
|
||||
// ── Редактирование ─────────────────────────────────────────────────────────
|
||||
function startEdit(col) {
|
||||
editing = { id: col.id, value: col.name }
|
||||
}
|
||||
|
||||
async function commitEdit() {
|
||||
if (!editing || !editing.value.trim()) { editing = null; return }
|
||||
try {
|
||||
await api.updateCollection(editing.id, editing.value.trim(), null)
|
||||
const idx = collections.findIndex(c => c.id === editing.id)
|
||||
if (idx !== -1) collections[idx] = { ...collections[idx], name: editing.value.trim() }
|
||||
editing = null
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
function cancelEdit() { editing = null }
|
||||
|
||||
// ── Удаление ───────────────────────────────────────────────────────────────
|
||||
async function commitDelete() {
|
||||
if (!confirmDelete) return
|
||||
try {
|
||||
await api.deleteCollection(confirmDelete)
|
||||
collections = collections.filter(c => c.id !== confirmDelete)
|
||||
confirmDelete = null
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
confirmDelete = null
|
||||
}
|
||||
}
|
||||
|
||||
// ── Смена Inbox ────────────────────────────────────────────────────────────
|
||||
async function commitSetInbox() {
|
||||
if (!confirmInbox) return
|
||||
try {
|
||||
await api.setCollectionInbox(confirmInbox)
|
||||
collections = collections.map(c => ({
|
||||
...c,
|
||||
isInbox: c.id === confirmInbox,
|
||||
}))
|
||||
confirmInbox = null
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
confirmInbox = null
|
||||
}
|
||||
}
|
||||
|
||||
onMount(load)
|
||||
</script>
|
||||
|
||||
<div class="page">
|
||||
<!-- Форма создания -->
|
||||
<div class="new-row">
|
||||
<input
|
||||
class="new-input"
|
||||
placeholder="Новая коллекция…"
|
||||
bind:value={newName}
|
||||
onkeydown={(e) => e.key === 'Enter' && createCollection()}
|
||||
disabled={creating}
|
||||
/>
|
||||
<button class="btn-create" onclick={createCollection} disabled={creating || !newName.trim()}>+</button>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<div class="hint">Загрузка…</div>
|
||||
{:else if error}
|
||||
<div class="hint error">{error}</div>
|
||||
{:else if collections.length === 0}
|
||||
<div class="hint">Нет коллекций</div>
|
||||
{:else}
|
||||
<ul class="list">
|
||||
{#each collections as col (col.id)}
|
||||
<li class="item">
|
||||
<!-- Имя / inline-редактор -->
|
||||
<div class="col-info">
|
||||
{#if editing?.id === col.id}
|
||||
<input
|
||||
class="edit-input"
|
||||
bind:value={editing.value}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') commitEdit()
|
||||
if (e.key === 'Escape') cancelEdit()
|
||||
}}
|
||||
autofocus
|
||||
/>
|
||||
{:else}
|
||||
<div class="col-name">
|
||||
{col.name}
|
||||
{#if col.isInbox}
|
||||
<span class="badge-inbox">основная</span>
|
||||
{/if}
|
||||
</div>
|
||||
{#if col.itemCount > 0}
|
||||
<div class="col-meta">{col.itemCount} эл.</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Кнопки действий -->
|
||||
<div class="actions">
|
||||
{#if editing?.id === col.id}
|
||||
<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}
|
||||
{#if !col.isInbox}
|
||||
<button class="icon-btn" onclick={() => startEdit(col)} title="Переименовать">
|
||||
<Pencil size={16}/>
|
||||
</button>
|
||||
<button class="icon-btn star" onclick={() => confirmInbox = col.id} title="Сделать основной">
|
||||
<Star size={16}/>
|
||||
</button>
|
||||
<button class="icon-btn del" onclick={() => confirmDelete = col.id} title="Удалить">
|
||||
<Trash2 size={16}/>
|
||||
</button>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<!-- Подтверждение удаления -->
|
||||
{#if confirmDelete === col.id && deleteTarget}
|
||||
<li class="confirm-panel">
|
||||
<div class="confirm-text">
|
||||
{#if deleteTarget.itemCount > 0}
|
||||
⚠️ Коллекция содержит <strong>{deleteTarget.itemCount} эл.</strong> — они будут удалены безвозвратно.
|
||||
{:else}
|
||||
Удалить «{deleteTarget.name}»?
|
||||
{/if}
|
||||
</div>
|
||||
<div class="confirm-actions">
|
||||
<button class="btn-danger" onclick={commitDelete}>Удалить</button>
|
||||
<button class="btn-ghost" onclick={() => confirmDelete = null}>Отмена</button>
|
||||
</div>
|
||||
</li>
|
||||
{/if}
|
||||
|
||||
<!-- Подтверждение смены Inbox -->
|
||||
{#if confirmInbox === col.id && inboxTarget}
|
||||
<li class="confirm-panel">
|
||||
<div class="confirm-text">
|
||||
Сделать «{inboxTarget.name}» основной коллекцией? Новые медиа будут сохраняться в неё.
|
||||
</div>
|
||||
<div class="confirm-actions">
|
||||
<button class="btn-primary" onclick={commitSetInbox}>Подтвердить</button>
|
||||
<button class="btn-ghost" onclick={() => confirmInbox = null}>Отмена</button>
|
||||
</div>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.page { padding: 8px; }
|
||||
|
||||
/* Создание */
|
||||
.new-row { display: flex; gap: 6px; margin-bottom: 8px; }
|
||||
.new-input {
|
||||
flex: 1; padding: 8px 12px; border-radius: 8px; border: none;
|
||||
background: var(--tg-secondary-bg, #f0f0f0);
|
||||
color: var(--tg-text, #000); font-size: 14px;
|
||||
}
|
||||
.btn-create {
|
||||
width: 36px; border-radius: 8px; border: none;
|
||||
background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff);
|
||||
font-size: 20px; cursor: pointer;
|
||||
}
|
||||
.btn-create:disabled { opacity: .4; cursor: default; }
|
||||
|
||||
/* Список */
|
||||
.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: 4px; }
|
||||
|
||||
.item {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
background: var(--tg-secondary-bg, #f5f5f5);
|
||||
border-radius: 10px; padding: 10px 10px 10px 12px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.col-info { flex: 1; min-width: 0; }
|
||||
.col-name {
|
||||
font-size: 15px; font-weight: 500;
|
||||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
}
|
||||
.col-meta { font-size: 12px; color: var(--tg-hint, #888); margin-top: 2px; }
|
||||
|
||||
.badge-inbox {
|
||||
font-size: 11px; font-weight: 600; letter-spacing: .02em;
|
||||
background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff);
|
||||
border-radius: 4px; padding: 1px 5px;
|
||||
}
|
||||
|
||||
/* Inline-редактор */
|
||||
.edit-input {
|
||||
width: 100%; padding: 4px 8px; border-radius: 6px; border: none;
|
||||
background: var(--tg-bg, #fff); color: var(--tg-text, #000);
|
||||
font-size: 15px; font-weight: 500;
|
||||
outline: 2px solid var(--tg-button, #2196f3);
|
||||
}
|
||||
|
||||
/* Кнопки-иконки */
|
||||
.actions { display: flex; gap: 2px; flex-shrink: 0; }
|
||||
.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, #999); cursor: pointer;
|
||||
transition: background .15s, color .15s;
|
||||
}
|
||||
.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.ok { color: #43a047; }
|
||||
.icon-btn.cancel { color: var(--tg-hint, #999); }
|
||||
|
||||
/* Подтверждение */
|
||||
.confirm-panel {
|
||||
background: var(--tg-secondary-bg, #f5f5f5);
|
||||
border-radius: 10px; padding: 10px 12px;
|
||||
border-left: 3px solid var(--tg-button, #2196f3);
|
||||
}
|
||||
.confirm-text { font-size: 13px; color: var(--tg-text, #000); margin-bottom: 8px; line-height: 1.4; }
|
||||
.confirm-actions { display: flex; gap: 6px; }
|
||||
|
||||
.btn-danger, .btn-primary, .btn-ghost {
|
||||
padding: 6px 14px; border-radius: 8px; border: none;
|
||||
font-size: 13px; font-weight: 500; cursor: pointer;
|
||||
}
|
||||
.btn-danger { background: #e53935; color: #fff; }
|
||||
.btn-primary { background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff); }
|
||||
.btn-ghost { background: none; color: var(--tg-hint, #888); }
|
||||
.btn-ghost:hover { background: var(--tg-secondary-bg, #e8e8e8); }
|
||||
</style>
|
||||
@@ -0,0 +1,227 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import { api } from '../lib/api.js'
|
||||
import { isAttachmentMode, getQueryId, close as tgClose, showAlert } from '../lib/telegram.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
|
||||
|
||||
// Map of itemId → { url: string|null, loading: boolean, error: boolean }
|
||||
let previews = {}
|
||||
|
||||
async function load() {
|
||||
loading = true
|
||||
error = null
|
||||
previews = {}
|
||||
try {
|
||||
items = await api.getMedia(query)
|
||||
// Kick off preview loading for each previewable item (fire & forget)
|
||||
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[id] = { url: null, loading: true, error: false }
|
||||
try {
|
||||
const url = await api.getDownloadUrl(id)
|
||||
previews[id] = { url, loading: false, error: false }
|
||||
} catch {
|
||||
previews[id] = { url: null, loading: false, error: true }
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSendToChat(id) {
|
||||
try {
|
||||
await api.sendToChat(id, queryId)
|
||||
tgClose()
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(id) {
|
||||
try {
|
||||
await api.deleteMedia(id)
|
||||
items = items.filter((i) => i.id !== id)
|
||||
const { [id]: _, ...rest } = previews
|
||||
previews = rest
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
let searchTimer
|
||||
function onSearch() {
|
||||
clearTimeout(searchTimer)
|
||||
searchTimer = setTimeout(load, 400)
|
||||
}
|
||||
|
||||
onMount(load)
|
||||
</script>
|
||||
|
||||
<div class="page">
|
||||
{#if attachMode}
|
||||
<div class="attach-banner">Выберите медиа для отправки в чат</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>
|
||||
{: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}
|
||||
>
|
||||
{#if PREVIEWABLE.has(item.mediaType)}
|
||||
<div class="thumb-wrap">
|
||||
{#if preview?.loading || !preview}
|
||||
<div class="thumb-skeleton" aria-hidden="true"></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" title="Не удалось загрузить">🖼</div>
|
||||
{/if}
|
||||
</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>
|
||||
{#if attachMode}
|
||||
<span class="attach-hint">Отправить</span>
|
||||
{:else}
|
||||
<button class="del" on:click={() => handleDelete(item.id)} title="Удалить">✕</button>
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.page { padding: 8px; }
|
||||
.attach-banner {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
color: var(--tg-hint, #888);
|
||||
padding: 6px 0 4px;
|
||||
}
|
||||
.search {
|
||||
width: 100%; 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;
|
||||
}
|
||||
.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; }
|
||||
.item {
|
||||
display: flex; align-items: flex-start; gap: 10px;
|
||||
background: var(--tg-secondary-bg, #f5f5f5);
|
||||
border-radius: 10px; padding: 10px 12px;
|
||||
}
|
||||
|
||||
/* ── Thumbnail ──────────────────────────────────────────────────────────── */
|
||||
.thumb-wrap {
|
||||
flex-shrink: 0;
|
||||
width: 64px; height: 64px;
|
||||
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;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.thumb-error {
|
||||
width: 100%; height: 100%;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-size: 24px;
|
||||
background: var(--tg-secondary-bg, #eee);
|
||||
}
|
||||
@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: 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--attach:active {
|
||||
opacity: 0.7;
|
||||
}
|
||||
.attach-hint {
|
||||
font-size: 12px;
|
||||
color: var(--tg-button, #2196f3);
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
align-self: center;
|
||||
}
|
||||
.del {
|
||||
background: none; border: none; color: var(--tg-hint, #888);
|
||||
font-size: 16px; cursor: pointer; padding: 0; flex-shrink: 0;
|
||||
align-self: flex-start;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,7 @@
|
||||
import { writable, derived } from 'svelte/store'
|
||||
|
||||
/** JWT-токен. null — не авторизован. */
|
||||
export const jwt = writable(null)
|
||||
|
||||
/** true, если пользователь авторизован */
|
||||
export const isAuthed = derived(jwt, ($jwt) => $jwt !== null)
|
||||
Reference in New Issue
Block a user