import {html} from 'htm/preact';
import {useState} from 'preact/hooks';
import {browser} from 'webextension-polyfill-ts';
import {
ConfirmButton,
Link,
QComponent,
QItem,
removeQItem,
Settings
} from '../..';
type MainProps = {
settings: Settings;
};
export function PageMain(props: MainProps): QComponent {
const [queue, updateQueue] = useState(props.settings.queue);
const _removeQItem = async (id: number) => {
const updated = await removeQItem(id);
updateQueue(updated.queue);
await browser.runtime.sendMessage({action: 'queue update badge'});
};
const qItems: QComponent[] = queue
.sort((a, b) => a.added.getTime() - b.added.getTime())
.map((item) => html`<${Item} item=${item} remove=${_removeQItem} />`);
if (qItems.length === 0) {
qItems.push(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: QItem;
remove: (id: number) => Promise