mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-13 18:59:22 -05:00
719e5b4dd8
Fix various code issues. i18n invite menu.
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { Hash, VolumeFull } from "@styled-icons/boxicons-regular";
|
|
import { observer } from "mobx-react-lite";
|
|
import { Channel } from "revolt.js/dist/maps/Channels";
|
|
|
|
import { useContext } from "preact/hooks";
|
|
|
|
import { AppContext } from "../../context/revoltjs/RevoltClient";
|
|
|
|
import { ImageIconBase, IconBaseProps } from "./IconBase";
|
|
import fallback from "./assets/group.png";
|
|
|
|
interface Props extends IconBaseProps<Channel> {
|
|
isServerChannel?: boolean;
|
|
}
|
|
|
|
export default observer(
|
|
(
|
|
props: Props & Omit<JSX.HTMLAttributes<HTMLImageElement>, keyof Props>,
|
|
) => {
|
|
const client = useContext(AppContext);
|
|
|
|
const {
|
|
size,
|
|
target,
|
|
attachment,
|
|
isServerChannel: server,
|
|
animate,
|
|
children,
|
|
as,
|
|
...imgProps
|
|
} = props;
|
|
const iconURL = client.generateFileURL(
|
|
target?.icon ?? attachment,
|
|
{ max_side: 256 },
|
|
animate,
|
|
);
|
|
const isServerChannel =
|
|
server ||
|
|
(target &&
|
|
(target.channel_type === "TextChannel" ||
|
|
target.channel_type === "VoiceChannel"));
|
|
|
|
if (typeof iconURL === "undefined") {
|
|
if (isServerChannel) {
|
|
if (target?.channel_type === "VoiceChannel") {
|
|
return <VolumeFull size={size} />;
|
|
}
|
|
return <Hash size={size} />;
|
|
}
|
|
}
|
|
|
|
return (
|
|
// ! TODO: replace fallback with <picture /> + <source />
|
|
<ImageIconBase
|
|
{...imgProps}
|
|
width={size}
|
|
height={size}
|
|
loading="lazy"
|
|
aria-hidden="true"
|
|
square={isServerChannel}
|
|
src={iconURL ?? fallback}
|
|
/>
|
|
);
|
|
},
|
|
);
|