import { FunctionComponent, createRef } from "preact"; import { useCallback, useState } from "preact/hooks" import { BridgeConfig } from "../../BridgeAPI"; import { FeedConnectionState, FeedResponseItem } from "../../../src/Connections/FeedConnection"; import { ConnectionConfigurationProps, IRoomConfigText, RoomConfig } from "./RoomConfig"; import { Button, ButtonSet, InputField } from "../elements"; import styles from "./FeedConnection.module.scss"; import FeedsIcon from "../../icons/feeds.png"; const DEFAULT_TEMPLATE = "New post in $FEEDNAME: $LINK" const FeedRecentResults: FunctionComponent<{item: FeedResponseItem}> = ({ item }) => { if (!item.secrets) { return null; } return <>

Recent feed results

{!item.secrets.lastResults.length && There have been no recent updates for this feed.} ; } const DOCUMENTATION_LINK = "https://matrix-org.github.io/matrix-hookshot/latest/setup/feeds.html#feed-templates"; const ConnectionConfiguration: FunctionComponent> = ({existingConnection, onSave, onRemove, isMigrationCandidate, isUpdating}) => { const urlRef = createRef(); const labelRef = createRef(); const templateRef = createRef(); const canSave = !existingConnection?.id || (existingConnection?.canEdit ?? false); const canEdit = canSave && !isMigrationCandidate; const [notifyOnFailure, setNotifyOnFailure] = useState(existingConnection?.config.notifyOnFailure ?? false); const handleSave = useCallback((evt: Event) => { evt.preventDefault(); if (!canSave) { return; } const url = urlRef?.current?.value || existingConnection?.config.url; if (url) { onSave({ url, label: labelRef?.current?.value || existingConnection?.config.label, template: templateRef.current?.value || existingConnection?.config.template, notifyOnFailure, }) } }, [canSave, onSave, urlRef, labelRef, templateRef, notifyOnFailure, existingConnection]); const onlyVisibleOnExistingConnection = !!existingConnection; return
{ existingConnection && } setNotifyOnFailure(v => !v), [])} />

See the documentation for help writing templates.

{ canSave && } { canEdit && existingConnection?.id && } ; }; interface ServiceConfig { pollIntervalSeconds: number, } const roomConfigText: IRoomConfigText = { header: 'RSS/Atom feeds', createNew: 'Subscribe to a feed', listCanEdit: 'Feeds subscribed to', listCantEdit: 'Feeds subscribed to', }; const RoomConfigListItemFunc = (c: FeedResponseItem) => c.config.label || c.config.url; const FeedsConfig: BridgeConfig = ({ roomId, showHeader }) => { return headerImg={FeedsIcon} showHeader={showHeader} roomId={roomId} type="feeds" connectionEventType="uk.half-shot.matrix-hookshot.feed" text={roomConfigText} listItemName={RoomConfigListItemFunc} connectionConfigComponent={ConnectionConfiguration} />; }; export default FeedsConfig;