55 lines
2.3 KiB
TypeScript
55 lines
2.3 KiB
TypeScript
import * as moment from "moment";
|
|
import { Message } from '../data-types';
|
|
import CombinedGuild from "../guild-combined";
|
|
import Q from "../q-module";
|
|
|
|
import ElementsUtil from "./require/elements-util";
|
|
|
|
class ShouldNeverHappenError extends Error {
|
|
constructor(...args: any[]) {
|
|
super(...args);
|
|
this.name = 'ShouldNeverHappenError';
|
|
}
|
|
}
|
|
|
|
export default function createResourceMessageContinued(q: Q, guild: CombinedGuild, message: Message): HTMLElement {
|
|
if (!message.resourceId || !message.resourceName) {
|
|
throw new ShouldNeverHappenError('Message is not a resource message');
|
|
}
|
|
|
|
let element = q.create({ class: 'message continued', 'meta-id': message.id, 'meta-member-id': message.member.id, 'meta-guild-id': guild.id, content: [
|
|
{ class: 'timestamp', content: moment(message.sent).format('HH:mm') },
|
|
{ class: 'right', content: [
|
|
{ class: 'content resource', content: [
|
|
{ tag: 'img', class: 'icon', src: './img/file-icon.png' }, // TODO: SVG based on content-type
|
|
{ class: 'text', content: [
|
|
{ class: 'filename', content: message.resourceName },
|
|
{ class: 'download-status', content: 'Click to Download' },
|
|
] }
|
|
] },
|
|
{ class: 'content text', content: ElementsUtil.parseMessageText(message.text ?? '') }
|
|
] }
|
|
] }) as HTMLElement;
|
|
q.$$$(element, '.resource').addEventListener('click', ElementsUtil.createDownloadListener({
|
|
guild: guild, resourceId: message.resourceId, resourceName: message.resourceName,
|
|
downloadStartFunc: () => {
|
|
q.$$$(element, '.resource .download-status').innerText = 'Downloading...';
|
|
},
|
|
downloadFailFunc: async () => {
|
|
q.$$$(element, '.resource .download-status').innerText = 'Error Downloading. Click to Try Again';
|
|
await ElementsUtil.shakeElement(q.$$$(element, '.resource .download-status'), 400);
|
|
},
|
|
writeStartFunc: () => {
|
|
q.$$$(element, '.resource .download-status').innerText = 'Writing...';
|
|
},
|
|
writeFailFunc: async () => {
|
|
q.$$$(element, '.resource .download-status').innerText = 'Error Writing. Click to Try Again';
|
|
await ElementsUtil.shakeElement(q.$$$(element, '.resource .download-status'), 400);
|
|
},
|
|
successFunc: (downloadPath) => {
|
|
q.$$$(element, '.resource .download-status').innerText = 'Click to Open in Explorer';
|
|
}
|
|
}));
|
|
return element;
|
|
}
|