import {Component, html} from 'htm/preact'; import browser from 'webextension-polyfill'; import Settings from '../settings'; import {Queue} from '../../types.d'; import {Link} from './link'; import {ConfirmButton} from './confirm-button'; type MainProps = { settings: Settings; }; type MainState = { queue: Queue.Item[]; }; export class PageMain extends Component { constructor(props: MainProps) { super(props); this.state = { queue: props.settings.queue, }; } removeItem = async (id: number) => { await this.props.settings.removeItem(id); this.setState({queue: this.props.settings.queue}); await browser.runtime.sendMessage({action: 'queue update badge'}); }; render(): Queue.Component { const queueItems: Queue.Component[] = this.state.queue .sort((a, b) => a.added.getTime() - b.added.getTime()) .map((item) => html`<${Item} item=${item} remove=${this.removeItem} />`); if (queueItems.length === 0) { queueItems.push(html`
  • No items queued. 🤷
  • `); } return html`
    How do I use Queue?

    Adding links to your queue:

    • Right-click any link or tab and click "Add to Queue".

    Opening the next link from your queue:

    • Click on the extension icon to open it in the current tab (when possible).
    • Right-click the extension icon and click "Open next link in new tab".

    Opening the extension page:

    • Double-click the extension icon.
    • Right-click the extension icon and click "Open the extension page".

    Deleting queue items:

    • Click the red button with the ✗ and then confirm it by clicking again.
    `; } } type ItemProps = { item: Queue.Item; remove: (id: number) => Promise; }; function Item(props: ItemProps): Queue.Component { const added = props.item.added.toLocaleString(); const {id, text, url} = props.item; return html`
  • <${Link} text=${text ?? url} url=${url} />

    <${ConfirmButton} class="confirm-button" clickHandler=${async () => props.remove(id)} confirmClass="confirm" confirmText="✓" text="✗" timeout=${5 * 1000} title="Remove" />

  • `; }