2021-06-27 06:17:59 -04:00
|
|
|
import { Hash, VolumeFull } from "@styled-icons/boxicons-regular";
|
2021-07-29 13:41:01 -04:00
|
|
|
import { observer } from "mobx-react-lite";
|
2021-07-30 17:40:49 -04:00
|
|
|
import { Channel } from "revolt.js/dist/maps/Channels";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import { useContext } from "preact/hooks";
|
|
|
|
|
2021-06-19 07:34:53 -04:00
|
|
|
import { AppContext } from "../../context/revoltjs/RevoltClient";
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
import { ImageIconBase, IconBaseProps } from "./IconBase";
|
|
|
|
import fallback from "./assets/group.png";
|
|
|
|
|
2021-07-29 13:41:01 -04:00
|
|
|
interface Props extends IconBaseProps<Channel> {
|
2021-07-05 06:25:20 -04:00
|
|
|
isServerChannel?: boolean;
|
2021-06-19 07:34:53 -04:00
|
|
|
}
|
|
|
|
|
2021-07-29 13:41:01 -04:00
|
|
|
export default observer(
|
|
|
|
(
|
2021-08-05 09:47:00 -04:00
|
|
|
props: Props &
|
|
|
|
Omit<
|
|
|
|
JSX.HTMLAttributes<HTMLImageElement>,
|
|
|
|
keyof Props | "children" | "as"
|
|
|
|
>,
|
2021-07-29 13:41:01 -04:00
|
|
|
) => {
|
|
|
|
const client = useContext(AppContext);
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-29 13:41:01 -04:00
|
|
|
const {
|
|
|
|
size,
|
|
|
|
target,
|
|
|
|
attachment,
|
|
|
|
isServerChannel: server,
|
|
|
|
animate,
|
|
|
|
...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"));
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-29 13:41:01 -04:00
|
|
|
if (typeof iconURL === "undefined") {
|
|
|
|
if (isServerChannel) {
|
|
|
|
if (target?.channel_type === "VoiceChannel") {
|
|
|
|
return <VolumeFull size={size} />;
|
|
|
|
}
|
|
|
|
return <Hash size={size} />;
|
2021-07-05 06:25:20 -04:00
|
|
|
}
|
|
|
|
}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-08-30 17:39:02 -04:00
|
|
|
// The border radius of the channel icon, if it's a server-channel it should be square (undefined).
|
2021-09-03 06:21:51 -04:00
|
|
|
let borderRadius: string | undefined = "--border-radius-channel-icon";
|
|
|
|
if (isServerChannel) {
|
|
|
|
borderRadius = undefined;
|
2021-08-30 17:39:02 -04:00
|
|
|
}
|
|
|
|
|
2021-07-29 13:41:01 -04:00
|
|
|
return (
|
2021-07-31 05:31:16 -04:00
|
|
|
// ! TODO: replace fallback with <picture /> + <source />
|
2021-07-29 13:41:01 -04:00
|
|
|
<ImageIconBase
|
|
|
|
{...imgProps}
|
|
|
|
width={size}
|
|
|
|
height={size}
|
|
|
|
loading="lazy"
|
|
|
|
aria-hidden="true"
|
2021-09-03 06:21:51 -04:00
|
|
|
borderRadius={borderRadius}
|
2021-07-29 13:41:01 -04:00
|
|
|
src={iconURL ?? fallback}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|