An open-source cross-platform alternative to AirDrop
feat: improve web layout
Tien Do Namc0d43d56aca6
diff --git a/assets/web/index.html b/assets/web/index.htmlindex 04464af9..133c2033 100644--- a/assets/web/index.html+++ b/assets/web/index.html@@ -4,175 +4,85 @@<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>LocalSend</title>- <script src="main.js"></script><style>:root {- --gray: rgb(236, 240, 241);- --black: rgb(38, 38, 38);- --teal: rgb(38,166,154);- --p-1: 1rem;- --p-2: 2rem;- }-- html {- font-family: sans-serif, system-ui;- color: var(--black);- height: 100%;- font-size: 16px;+ --grey: #E0E0E0;+ --teal: #00796B;+ --white: #FFFFFF;+ --p-1: 0.5rem;+ --p-2: 1rem;}body {+ font-family: sans-serif, system-ui;display: flex;flex-direction: column;- height: 100%;- line-height: 1.5;align-items: center;+ margin: 0;+ line-height: 1.5;}a {text-decoration: none;- }-- a:link {- color: blue;- }-- *,- *::before,- *::after {- margin: 0;- padding: 0;- box-sizing: border-box;- font-family: inherit;- border: 0;- outline: 0;- color: inherit;+ color: var(--white);}#file-list {- padding: var(--p-2);- min-width: 50vw;- width: fit-content;- }-- .size-cell {- background-color: var(--teal);- white-space: nowrap;- }-- .filesTable {- border-collapse: collapse;+ box-sizing: border-box;width: 100%;- border: 1px solid;- }+ max-width: 1000px;+ padding: 0 var(--p-2);- .filesTable tr th {- padding: 5px;+ display: flex;+ flex-wrap: wrap;+ column-gap: var(--p-2);+ row-gap: var(--p-2);}-- .filesTable tr td {- padding: 5px;- text-align: center;- font-weight: 500;- word-wrap: break-word;- max-width: 75vw;+ .file-item {+ display: flex;+ flex-direction: row;+ flex-basis: 100%;+ padding: var(--p-1) var(--p-2);+ background-color: var(--teal);+ border-radius: 0.5rem;}- .filesTable tr th:not(:first-of-type) {- width: calc(100% / 8);+ .file-name-cell {+ flex: 1;+ text-color: var(--white);}- .filesTable tbody tr:nth-of-type(2n + 2) {- background-color: var(--gray);+ .file-size-cell {+ display: flex;+ align-items: center;+ text-overflow: nowrap;+ color: var(--grey);+ font-size: 0.8rem;}- @media (max-width: 1124px) {- #file-list {- width: 100%;- }-- .filesTable {- margin-left: -10px;- border: 0;- }-- a::after {- content: "(" attr(sizeData) ")";- }-- .size-cell {- display: none;- }-- .filesTable thead {- display: none;- }-- .filesTable tbody {- display: flex;- flex-wrap: wrap;- }-- .filesTable tbody tr {- display: flex;- flex-direction: column;- margin-top: 10px;- width: calc(50% - 10px);- margin-left: 10px;- }-- .filesTable tr {- border-radius: 5px !important;- }-- .filesTable tr td {- border: 1px solid var(--gray);- }-- .filesTable tbody tr td {- padding: 5px 10px !important;- text-align: right !important;- position: relative;- height: 100%;- }-- .filesTable tbody tr td:before {- position: absolute;- left: 5px;- content: "";- width: 100px;- height: 100%;- display: flex;- align-items: center;- justify-content: center;- top: 0;- background-repeat: no-repeat;- background-size: contain;- background-position: left;- }-- .filesTable tbody tr:nth-of-type(2n + 2) {- background-color: transparent;+ /* Show 2 columns on tablet and up */+ @media (min-width: 768px) {+ .file-item {+ flex-basis: calc(50% - (var(--p-2) * 2.5));}}- @media (max-width: 768px) {- .filesTable {- margin-left: 0;- border: 0;- }+ /* Single file mode */- .filesTable tr td {- max-width: 90vw;- }+ #single-file {+ box-sizing: border-box;+ width: 100%;+ max-width: 400px;+ padding: var(--p-2);+ }- .filesTable tbody tr {- width: 100%;- margin-left: 0;- }+ #single-file .file-item {+ box-sizing: border-box;+ width: 100%;}</style>+ <script src="main.js"></script></head><body><noscript>@@ -181,8 +91,7 @@<h1 style="padding: var(--p-1)">LocalSend</h1><p id="status-text"></p>-<div id="file-list"></div>-+<div id="single-file"></div></body></html>diff --git a/assets/web/main.js b/assets/web/main.jsindex 62376d6b..df430e51 100644--- a/assets/web/main.js+++ b/assets/web/main.js@@ -25,29 +25,32 @@ async function requestFiles() {sessionId = data.sessionId;document.getElementById('status-text').innerText = `${i18n.files} (${Object.keys(data.files).length})`;+ if (Object.keys(files).length === 1) {+ // single file+ const file = files[Object.keys(files)[0]];+ document.getElementById('single-file').innerHTML = `+ <a class="file-item" href="${BASE_URL}/receive?sessionId=${sessionId}&fileId=${file.id}">+ <div class="file-name-cell">+ ${file.fileName}+ </div>+ <div class="file-size-cell">+ ${formatBytes(file.size)}+ </div>+ </a>+ `;+ return;+ }document.getElementById('file-list').innerHTML = `- <table class="filesTable">- <thead>- <tr>- <th>${i18n.fileName}</th>- <th class="size-cell">${i18n.size}</th>- </tr>- </thead>- <tbody>- ${Object.keys(files).map((key) => `- <tr>- <td>- <a sizeData="${formatBytes(files[key].size)}" href="${BASE_URL}/receive?sessionId=${sessionId}&fileId=${key}" target="_blank">- ${files[key].fileName}- </a>- </td>- <td class="size-cell">- ${formatBytes(files[key].size)}- </td>- </tr>- `).join('')}- </tbody>- </table>+ ${Object.keys(files).map((key) => `+ <a class="file-item" href="${BASE_URL}/receive?sessionId=${sessionId}&fileId=${key}">+ <div class="file-name-cell">+ ${files[key].fileName}+ </div>+ <div class="file-size-cell">+ ${formatBytes(files[key].size)}+ </div>+ </a>+ `).join('')}`;}@@ -61,8 +64,6 @@ async function init() {await requestFiles();}-init();-function formatBytes(bytes) {if (bytes < 1024) {return `${bytes} B`;@@ -74,3 +75,5 @@ function formatBytes(bytes) {return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;}}++init();