import * as React from "react"; import {LocalIcon} from "tc-shared/file/Icons"; export const IconRenderer = (props: { icon: string | LocalIcon; title?: string; className?: string; }) => { if(!props.icon) { return
; } else if(typeof props.icon === "string") { return
; } else if(props.icon instanceof LocalIcon) { return ; } else { throw "JQuery icons are not longer supported"; } } export interface LoadedIconRenderer { icon: LocalIcon; title?: string; className?: string; } export class LocalIconRenderer extends React.Component { private readonly callback_state_update; constructor(props) { super(props); this.callback_state_update = () => { const icon = this.props.icon; if(icon.status !== "destroyed") this.forceUpdate(); }; } render() { const icon = this.props.icon; if(!icon || icon.status === "empty" || icon.status === "destroyed") return
; else if(icon.status === "loaded") { if(icon.icon_id >= 0 && icon.icon_id <= 1000) { if(icon.icon_id === 0) return
; return
; } return
{this.props.title
; } else if(icon.status === "loading") return
; else if(icon.status === "error") return
; } componentDidMount(): void { this.props.icon?.status_change_callbacks.push(this.callback_state_update); } componentWillUnmount(): void { this.props.icon?.status_change_callbacks.remove(this.callback_state_update); } componentDidUpdate(prevProps: Readonly, prevState: Readonly<{}>, snapshot?: any): void { prevProps.icon?.status_change_callbacks.remove(this.callback_state_update); this.props.icon?.status_change_callbacks.push(this.callback_state_update); } }