SHA256
158 lines
5.6 KiB
JavaScript
158 lines
5.6 KiB
JavaScript
import { t } from '../i18n/index.js';
|
|
import {
|
|
clearArweaveAttachmentHistory,
|
|
formatArweaveHistoryTime,
|
|
getArweaveAttachmentAvailability,
|
|
openArweaveAttachmentManager,
|
|
readArweaveAttachmentHistory,
|
|
} from '../components/arweave-attachment-manager.js';
|
|
import { formatBytes } from '../services/attachment-format.js';
|
|
import { createOverflowDots } from '../components/overflow-dots.js';
|
|
import { createTopBar } from '../components/topbar.js';
|
|
import { confirmDialog } from '../components/confirm-dialog.js';
|
|
import { toUserMessage } from '../services/ui-error-texts.js';
|
|
import { state } from '../state.js';
|
|
|
|
export const pageMeta = { id: 'arweave-uploads-view', get title() { return t('screens.arweave_uploads_view.text_001'); } };
|
|
|
|
function setStatusBadge(node, status, label) {
|
|
if (!node) return;
|
|
node.className = `ar-attachment-status ar-attachment-status--${status || 'pending'}`;
|
|
node.textContent = label || t('screens.arweave_uploads_view.text_014');
|
|
}
|
|
|
|
function renderTile(item, index) {
|
|
const tile = document.createElement('article');
|
|
tile.className = 'ar-attachment-history-tile ar-attachment-history-tile--page';
|
|
|
|
const name = document.createElement('strong');
|
|
name.className = 'ar-attachment-history-name';
|
|
name.textContent = item.name;
|
|
|
|
const status = document.createElement('span');
|
|
status.className = 'ar-attachment-status ar-attachment-status--pending';
|
|
status.dataset.statusIndex = String(index);
|
|
status.textContent = t('screens.arweave_uploads_view.text_002');
|
|
|
|
const meta = document.createElement('div');
|
|
meta.className = 'ar-attachment-history-meta-row';
|
|
const size = document.createElement('span');
|
|
size.textContent = formatBytes(item.size);
|
|
const time = document.createElement('span');
|
|
time.textContent = formatArweaveHistoryTime(item.uploadedAtMs);
|
|
meta.append(status, size, time);
|
|
if (item.pendingPlacement) {
|
|
const flag = document.createElement('span');
|
|
flag.className = 'ar-attachment-placement-flag';
|
|
flag.textContent = t('screens.arweave_uploads_view.text_003');
|
|
meta.append(flag);
|
|
}
|
|
|
|
const txId = document.createElement('div');
|
|
txId.className = 'mono-cell ar-attachment-history-txid';
|
|
txId.textContent = item.ar;
|
|
|
|
tile.append(name, meta, txId);
|
|
return tile;
|
|
}
|
|
|
|
export function render({navigate, chrome}) {
|
|
const screen = document.createElement('section');
|
|
screen.className = 'stack arweave-uploads-screen';
|
|
|
|
const statusLine = document.createElement('p');
|
|
statusLine.className = 'meta-muted inline-error';
|
|
|
|
const list = document.createElement('div');
|
|
list.className = 'ar-attachment-history-tiles arweave-uploads-list';
|
|
|
|
const uploadFile = async () => {
|
|
statusLine.textContent = '';
|
|
try {
|
|
await openArweaveAttachmentManager({
|
|
login: state.session.login,
|
|
storagePwd: state.session.storagePwdInMemory,
|
|
gateway: state.entrySettings.arweaveServer,
|
|
historyOnly: true,
|
|
});
|
|
renderHistory();
|
|
} catch (error) {
|
|
statusLine.textContent = toUserMessage(error, t('screens.arweave_uploads_view.text_013'));
|
|
}
|
|
};
|
|
|
|
function renderHistory() {
|
|
const rows = readArweaveAttachmentHistory(state.session.login).slice().reverse();
|
|
list.innerHTML = '';
|
|
statusLine.textContent = '';
|
|
|
|
if (!rows.length) {
|
|
const empty = document.createElement('div');
|
|
empty.className = 'empty-note';
|
|
empty.textContent = t('screens.arweave_uploads_view.text_004');
|
|
list.append(empty);
|
|
return;
|
|
}
|
|
|
|
rows.forEach((item, index) => {
|
|
list.append(renderTile(item, index));
|
|
const statusEl = list.querySelector(`[data-status-index="${index}"]`);
|
|
void getArweaveAttachmentAvailability({
|
|
gateway: state.entrySettings.arweaveServer,
|
|
attachment: item,
|
|
})
|
|
.then((result) => setStatusBadge(statusEl, result.status, result.label))
|
|
.catch(() => setStatusBadge(statusEl, 'unavailable', t('screens.arweave_uploads_view.text_015')));
|
|
});
|
|
|
|
window.setTimeout(() => {
|
|
list.scrollTop = list.scrollHeight;
|
|
}, 0);
|
|
}
|
|
|
|
const topbar = createTopBar({
|
|
title: t('screens.arweave_uploads_view.text_005'),
|
|
back: { onClick: () => navigate('my-blockchain-view') },
|
|
actions: [
|
|
{
|
|
icon: 'plus',
|
|
title: t('screens.arweave_uploads_view.text_006'),
|
|
ariaLabel: t('screens.arweave_uploads_view.text_007'),
|
|
className: 'arweave-uploads-add',
|
|
onClick: () => { void uploadFile(); },
|
|
},
|
|
{
|
|
iconNode: createOverflowDots(),
|
|
title: t('screens.arweave_uploads_view.text_008'),
|
|
ariaLabel: t('screens.arweave_uploads_view.text_009'),
|
|
className: 'arweave-uploads-menu-btn',
|
|
menu: {
|
|
minWidth: 220,
|
|
items: [
|
|
{ label: t('screens.arweave_uploads_view.text_010'), action: () => uploadFile() },
|
|
{
|
|
label: t('screens.arweave_uploads_view.text_011'),
|
|
action: async () => {
|
|
const confirmed = await confirmDialog({ title: t('dialogs.pages.arweave_uploads_view.title_001'), text: t('dialogs.pages.arweave_uploads_view.text_002'), confirmLabel: t('dialogs.pages.arweave_uploads_view.confirmLabel_003'), danger: true });
|
|
if (!confirmed) return;
|
|
clearArweaveAttachmentHistory(state.session.login);
|
|
renderHistory();
|
|
},
|
|
},
|
|
{
|
|
label: t('screens.arweave_uploads_view.text_012'),
|
|
action: () => window.alert(
|
|
t('dialogs.final.uploads.help')
|
|
),
|
|
},
|
|
],
|
|
},
|
|
},
|
|
],
|
|
});
|
|
chrome?.setTopbar(topbar);
|
|
screen.append(statusLine, list);
|
|
renderHistory();
|
|
return screen;
|
|
}
|