feat(web): componentize frontend and replace native delete confirm

- Split monolithic app.js/style.css into Alpine.js components (icons, store, fileSection, confirm)
- Add central Alpine.store('files') as single source of truth for file lists and actions
- Replace duplicated Inbox/Outbox markup with reusable fileSection component (props: dir, canShare)
- Add shared window.Icons module to remove duplicated inline SVGs
- Replace browser-native confirm() for file deletion with a styled, accessible modal dialog
- Split CSS into design tokens, base, and component layers; modernize visuals
- Update web.go embed and server static routes for the new component/style dirs
This commit is contained in:
2026-08-27 15:03:09 +08:00
parent 110a8f7d9d
commit d84e4dfdba
14 changed files with 966 additions and 522 deletions
+148 -108
View File
@@ -1,120 +1,160 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>yDropbox</title>
<link rel="stylesheet" href="/style.css">
<script defer src="/alpine.min.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>yDropbox</title>
<link rel="stylesheet" href="/styles/tokens.css">
<link rel="stylesheet" href="/styles/base.css">
<link rel="stylesheet" href="/styles/components.css">
<!-- Components register themselves on `alpine:init`; Alpine is loaded last. -->
<script defer src="/components/icons.js"></script>
<script defer src="/components/store.js"></script>
<script defer src="/components/fileSection.js"></script>
<script defer src="/components/confirm.js"></script>
<script defer src="/alpine.min.js"></script>
</head>
<body>
<div class="app" x-data="app()" x-init="loadFiles()">
<header>
<h1>y<span>Dropbox</span></h1>
<button class="btn btn-logout" @click="logout()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
Logout
</button>
</header>
<body x-data>
<div class="app">
<header class="app-header">
<h1 class="brand">y<span>Dropbox</span></h1>
<button class="btn btn-ghost btn-logout" @click="$store.files.logout()">
<span class="icon" x-html="Icons.logout"></span>
Logout
</button>
</header>
<section class="section">
<div class="section-header">
<h2>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="22 12 16 12 14 15 10 15 8 12 2 12"/><path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/></svg>
Inbox
<span class="badge" x-text="inboxFiles.length"></span>
</h2>
</div>
<div class="section-body">
<div class="drop-zone" :class="{ 'dragover': dragover }"
@dragover.prevent="dragover = true"
@dragleave.prevent="dragover = false"
@drop.prevent="dragover = false; uploadDropped($event, 'inbox')">
<input type="file" @change="upload($event, 'inbox')" multiple>
<div class="drop-zone-icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
</div>
<div class="drop-zone-text"><strong>Click to upload</strong> or drag and drop</div>
</div>
<main>
<!-- Inbox -->
<section class="section" x-data="fileSection('inbox', { canShare: true })">
<div class="section-header">
<h2>
<span class="icon" x-html="icon"></span>
<span x-text="title"></span>
<span class="badge" x-text="count"></span>
</h2>
</div>
<template x-if="inboxFiles.length === 0">
<div class="empty-state">
<div class="empty-state-icon">
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M22 12h-4l-3 3L9 9l-3 3H2"/></svg>
</div>
<div class="empty-state-text">No files in inbox</div>
</div>
</template>
<div class="drop-zone"
:class="{ 'is-dragover': dragover }"
@dragover.prevent="dragover = true"
@dragleave.prevent="dragover = false"
@drop.prevent="dragover = false; onDrop($event)">
<input type="file" class="drop-zone-input" @change="onSelect($event)" multiple>
<div class="drop-zone-icon"><span class="icon" x-html="Icons.upload"></span></div>
<div class="drop-zone-text"><strong>Click to upload</strong> or drag and drop</div>
</div>
<ul class="file-list">
<template x-for="file in inboxFiles" :key="file.id">
<li class="file-row">
<div class="file-icon">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#2563eb" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
</div>
<div class="file-info">
<div class="file-name" x-text="file.name"></div>
</div>
<div class="file-actions">
<button class="btn btn-sm btn-ghost" @click="download(file.id)" title="Download">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<button class="btn btn-sm btn-ghost" @click="share(file.id)" title="Share">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/></svg>
</button>
<button class="btn btn-sm btn-ghost btn-danger" @click="deleteFile(file.id)" title="Delete">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
</button>
</div>
</li>
</template>
</ul>
</div>
</section>
<template x-if="count === 0">
<div class="empty-state">
<span class="empty-state-icon" x-html="Icons.empty"></span>
<div class="empty-state-text" x-text="'No files in ' + title.toLowerCase()"></div>
</div>
</template>
<section class="section">
<div class="section-header">
<h2>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
Outbox
<span class="badge" x-text="outboxFiles.length"></span>
</h2>
</div>
<div class="section-body">
<template x-if="outboxFiles.length === 0">
<div class="empty-state">
<div class="empty-state-icon">
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
</div>
<div class="empty-state-text">No files in outbox</div>
</div>
</template>
<ul class="file-list" x-show="count > 0">
<template x-for="file in files" :key="file.id">
<li class="file-row">
<span class="file-icon" x-html="Icons.file"></span>
<div class="file-info">
<div class="file-name" x-text="file.name"></div>
</div>
<div class="file-actions">
<button class="btn btn-icon" @click="$store.files.download(file.id)" title="Download">
<span class="icon" x-html="Icons.download"></span>
</button>
<button class="btn btn-icon" x-show="canShare" @click="$store.files.share(file.id)" title="Share">
<span class="icon" x-html="Icons.share"></span>
</button>
<button class="btn btn-icon btn-danger" @click="$store.files.deleteFile(file.id)" title="Delete">
<span class="icon" x-html="Icons.trash"></span>
</button>
</div>
</li>
</template>
</ul>
</section>
<ul class="file-list">
<template x-for="file in outboxFiles" :key="file.id">
<li class="file-row">
<div class="file-icon">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#2563eb" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
</div>
<div class="file-info">
<div class="file-name" x-text="file.name"></div>
</div>
<div class="file-actions">
<button class="btn btn-sm btn-ghost" @click="download(file.id)" title="Download">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<button class="btn btn-sm btn-ghost btn-danger" @click="deleteFile(file.id)" title="Delete">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
</button>
</div>
</li>
</template>
</ul>
</div>
</section>
<!-- Outbox -->
<section class="section" x-data="fileSection('outbox')">
<div class="section-header">
<h2>
<span class="icon" x-html="icon"></span>
<span x-text="title"></span>
<span class="badge" x-text="count"></span>
</h2>
</div>
<div class="toast" :class="{ 'show': toast.show }" x-text="toast.message"></div>
<div class="drop-zone"
:class="{ 'is-dragover': dragover }"
@dragover.prevent="dragover = true"
@dragleave.prevent="dragover = false"
@drop.prevent="dragover = false; onDrop($event)">
<input type="file" class="drop-zone-input" @change="onSelect($event)" multiple>
<div class="drop-zone-icon"><span class="icon" x-html="Icons.upload"></span></div>
<div class="drop-zone-text"><strong>Click to upload</strong> or drag and drop</div>
</div>
<template x-if="count === 0">
<div class="empty-state">
<span class="empty-state-icon" x-html="Icons.empty"></span>
<div class="empty-state-text" x-text="'No files in ' + title.toLowerCase()"></div>
</div>
</template>
<ul class="file-list" x-show="count > 0">
<template x-for="file in files" :key="file.id">
<li class="file-row">
<span class="file-icon" x-html="Icons.file"></span>
<div class="file-info">
<div class="file-name" x-text="file.name"></div>
</div>
<div class="file-actions">
<button class="btn btn-icon" @click="$store.files.download(file.id)" title="Download">
<span class="icon" x-html="Icons.download"></span>
</button>
<button class="btn btn-icon btn-danger" @click="$store.files.deleteFile(file.id)" title="Delete">
<span class="icon" x-html="Icons.trash"></span>
</button>
</div>
</li>
</template>
</ul>
</section>
</main>
<div class="toast"
:class="{ 'show': $store.files.toast.show }"
x-text="$store.files.toast.message"></div>
<!-- Confirmation modal -->
<div class="modal-overlay"
x-data="confirmDialog()"
x-show="open"
x-cloak
x-transition.opacity
@click="cancel()"
@keydown.escape.window="onEscape()">
<div class="modal"
x-transition
@click.stop
role="dialog"
aria-modal="true"
:aria-label="title">
<h3 class="modal-title" x-text="title"></h3>
<p class="modal-body" x-text="message"></p>
<div class="modal-actions">
<button class="btn btn-ghost" type="button" @click="cancel()">Cancel</button>
<button class="btn"
:class="danger ? 'btn-danger' : 'btn-primary'"
type="button"
x-ref="accept"
@click="accept()"
x-text="danger ? 'Delete' : 'Confirm'"></button>
</div>
</div>
</div>
<script src="/app.js"></script>
</div>
</body>
</html>