import { h, Component, ComponentChild } from 'preact'; import classes from './MarginalAnnotations.module.scss'; import type { backgroundRpcServer } from '../background'; import type { AnnotationSourceDescriptor } from '../storage/AnnotationSource'; import { RpcClient } from 'webextension-rpc'; import rssIcon from '../assets/icons/rss.svg'; import infoIcon from '../assets/icons/info.svg'; import downloadIcon from '../assets/icons/download.svg'; const backgroundRpc = new RpcClient(); const addAnnotationSource = backgroundRpc.func('addAnnotationSource'); const removeSource = backgroundRpc.func('removeSource'); const refreshAnnotationSource = backgroundRpc.func('refreshAnnotationSource'); interface ToolbarButtonsProps { discoveredSources: (AnnotationSourceDescriptor & { subscribed: boolean })[]; onChange: () => void; } interface ToolbarButtonsState { showAll: boolean; } export class ToolbarButtons extends Component< ToolbarButtonsProps, ToolbarButtonsState > { render( { discoveredSources, onChange }: ToolbarButtonsProps, {}: ToolbarButtonsState, ) { const buttons: ComponentChild[] = []; for (const source of discoveredSources) { let explanationSummary, explanationFull; if (source.type === 'container') { explanationSummary = ( This page provides an annotation source{' '} “{source.title}”. ); explanationFull = `If you subscribe to it, annotations published by this website will be stored in your browser, and displayed on the web pages they target. Its annotations are automatically refreshed periodically.`; } else if (source.type === 'embeddedJsonld') { explanationSummary = ( This page contains embedded annotations. ); explanationFull = `If you import them, they will be stored in your browser, and displayed on the web pages they target. Note they will not be refreshed automatically.`; } buttons.push(
{explanationSummary} {explanationFull}
, ); if (source.subscribed) { if (source.type === 'container') { buttons.push( , , ); } else if (source.type === 'embeddedJsonld') { buttons.push( , , ); } } else { if (source.type === 'container') { buttons.push( , ); } else if (source.type === 'embeddedJsonld') { buttons.push( , ); } } } return buttons.length > 0 ? buttons : null; } } // TODO Refresh components properly. instead of reload the whole page. :) function pageReload() { window.location = window.location; }