move GuildSubscriptions to just function exports
This commit is contained in:
parent
6fe1016047
commit
1e437c33ae
@ -13,8 +13,8 @@ import { Duration } from 'moment';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import DropdownInput from '../components/input-dropdown';
|
import DropdownInput from '../components/input-dropdown';
|
||||||
import Button, { ButtonColorType } from '../components/button';
|
import Button, { ButtonColorType } from '../components/button';
|
||||||
import GuildSubscriptions from '../require/guild-subscriptions';
|
|
||||||
import BaseElements from '../require/base-elements';
|
import BaseElements from '../require/base-elements';
|
||||||
|
import { useTokensSubscription, useGuildMetadataSubscription, useSoftImageSrcResourceSubscription } from '../require/guild-subscriptions';
|
||||||
|
|
||||||
|
|
||||||
export interface GuildInvitesDisplayProps {
|
export interface GuildInvitesDisplayProps {
|
||||||
@ -25,14 +25,14 @@ const GuildInvitesDisplay: FC<GuildInvitesDisplayProps> = (props: GuildInvitesDi
|
|||||||
|
|
||||||
const url = 'https://localhost:3030'; // TODO: this will likely be a dropdown list at some point
|
const url = 'https://localhost:3030'; // TODO: this will likely be a dropdown list at some point
|
||||||
|
|
||||||
const [ fetchRetryCallable, tokens, tokensError ] = GuildSubscriptions.useTokensSubscription(guild);
|
const [ fetchRetryCallable, tokens, tokensError ] = useTokensSubscription(guild);
|
||||||
|
|
||||||
const [ guildMeta, guildMetaError ] = GuildSubscriptions.useGuildMetadataSubscription(guild);
|
const [ guildMeta, guildMetaError ] = useGuildMetadataSubscription(guild);
|
||||||
|
|
||||||
const [ expiresFromNow, setExpiresFromNow ] = useState<Duration | null>(moment.duration(1, 'day'));
|
const [ expiresFromNow, setExpiresFromNow ] = useState<Duration | null>(moment.duration(1, 'day'));
|
||||||
const [ expiresFromNowText, setExpiresFromNowText ] = useState<string>('1 day');
|
const [ expiresFromNowText, setExpiresFromNowText ] = useState<string>('1 day');
|
||||||
|
|
||||||
const [ iconSrc ] = GuildSubscriptions.useSoftImageSrcResourceSubscription(guild, guildMeta?.iconResourceId ?? null);
|
const [ iconSrc ] = useSoftImageSrcResourceSubscription(guild, guildMeta?.iconResourceId ?? null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (expiresFromNowText === 'never') {
|
if (expiresFromNowText === 'never') {
|
||||||
|
@ -10,7 +10,7 @@ import CombinedGuild from '../../guild-combined';
|
|||||||
import Display from '../components/display';
|
import Display from '../components/display';
|
||||||
import TextInput from '../components/input-text';
|
import TextInput from '../components/input-text';
|
||||||
import ImageEditInput from '../components/input-image-edit';
|
import ImageEditInput from '../components/input-image-edit';
|
||||||
import GuildSubscriptions from '../require/guild-subscriptions';
|
import { useGuildMetadataSubscription, useResourceSubscription } from '../require/guild-subscriptions';
|
||||||
|
|
||||||
export interface GuildOverviewDisplayProps {
|
export interface GuildOverviewDisplayProps {
|
||||||
guild: CombinedGuild;
|
guild: CombinedGuild;
|
||||||
@ -18,8 +18,8 @@ export interface GuildOverviewDisplayProps {
|
|||||||
const GuildOverviewDisplay: FC<GuildOverviewDisplayProps> = (props: GuildOverviewDisplayProps) => {
|
const GuildOverviewDisplay: FC<GuildOverviewDisplayProps> = (props: GuildOverviewDisplayProps) => {
|
||||||
const { guild } = props;
|
const { guild } = props;
|
||||||
|
|
||||||
const [ guildMeta, guildMetaError ] = GuildSubscriptions.useGuildMetadataSubscription(guild);
|
const [ guildMeta, guildMetaError ] = useGuildMetadataSubscription(guild);
|
||||||
const [ iconResource, iconResourceError ] = GuildSubscriptions.useResourceSubscription(guild, guildMeta?.iconResourceId ?? null);
|
const [ iconResource, iconResourceError ] = useResourceSubscription(guild, guildMeta?.iconResourceId ?? null);
|
||||||
|
|
||||||
const [ savedName, setSavedName ] = useState<string | null>(null);
|
const [ savedName, setSavedName ] = useState<string | null>(null);
|
||||||
const [ savedIconBuff, setSavedIconBuff ] = useState<Buffer | null>(null);
|
const [ savedIconBuff, setSavedIconBuff ] = useState<Buffer | null>(null);
|
||||||
|
@ -5,7 +5,7 @@ import ContextMenu from '../../contexts/components/context-menu';
|
|||||||
import BasicHover, { BasicHoverSide } from '../../contexts/context-hover-basic';
|
import BasicHover, { BasicHoverSide } from '../../contexts/context-hover-basic';
|
||||||
import BaseElements from '../../require/base-elements';
|
import BaseElements from '../../require/base-elements';
|
||||||
import { IAlignment } from '../../require/elements-util';
|
import { IAlignment } from '../../require/elements-util';
|
||||||
import GuildSubscriptions from '../../require/guild-subscriptions';
|
import { useGuildMetadataSubscription, useSelfMemberSubscription, useSoftImageSrcResourceSubscription } from '../../require/guild-subscriptions';
|
||||||
import { useContextClickContextMenu, useContextHover } from '../../require/react-helper';
|
import { useContextClickContextMenu, useContextHover } from '../../require/react-helper';
|
||||||
|
|
||||||
export interface GuildListElementProps {
|
export interface GuildListElementProps {
|
||||||
@ -22,9 +22,9 @@ const GuildListElement: FC<GuildListElementProps> = (props: GuildListElementProp
|
|||||||
|
|
||||||
// TODO: state higher up
|
// TODO: state higher up
|
||||||
// TODO: handle metadata error
|
// TODO: handle metadata error
|
||||||
const [ guildMeta, guildMetaError ] = GuildSubscriptions.useGuildMetadataSubscription(guild);
|
const [ guildMeta, guildMetaError ] = useGuildMetadataSubscription(guild);
|
||||||
const [ selfMember ] = GuildSubscriptions.useSelfMemberSubscription(guild);
|
const [ selfMember ] = useSelfMemberSubscription(guild);
|
||||||
const [ iconSrc ] = GuildSubscriptions.useSoftImageSrcResourceSubscription(guild, guildMeta?.iconResourceId ?? null);
|
const [ iconSrc ] = useSoftImageSrcResourceSubscription(guild, guildMeta?.iconResourceId ?? null);
|
||||||
|
|
||||||
const [ contextHover, mouseEnterCallable, mouseLeaveCallable ] = useContextHover(() => {
|
const [ contextHover, mouseEnterCallable, mouseLeaveCallable ] = useContextHover(() => {
|
||||||
if (!guildMeta) return null;
|
if (!guildMeta) return null;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React, { FC, useMemo } from 'react';
|
import React, { FC, useMemo } from 'react';
|
||||||
import { Member } from '../../../data-types';
|
import { Member } from '../../../data-types';
|
||||||
import CombinedGuild from '../../../guild-combined';
|
import CombinedGuild from '../../../guild-combined';
|
||||||
import GuildSubscriptions from '../../require/guild-subscriptions';
|
import { useSoftImageSrcResourceSubscription } from '../../require/guild-subscriptions';
|
||||||
|
|
||||||
export interface DummyMember {
|
export interface DummyMember {
|
||||||
id: 'dummy';
|
id: 'dummy';
|
||||||
@ -19,7 +19,7 @@ export interface MemberProps {
|
|||||||
const MemberElement: FC<MemberProps> = (props: MemberProps) => {
|
const MemberElement: FC<MemberProps> = (props: MemberProps) => {
|
||||||
const { guild, member } = props;
|
const { guild, member } = props;
|
||||||
|
|
||||||
const [ avatarSrc ] = GuildSubscriptions.useSoftImageSrcResourceSubscription(guild, member.avatarResourceId);
|
const [ avatarSrc ] = useSoftImageSrcResourceSubscription(guild, member.avatarResourceId);
|
||||||
|
|
||||||
const nameStyle = useMemo(() => member.roleColor ? { color: member.roleColor } : {}, [ member.roleColor ]);
|
const nameStyle = useMemo(() => member.roleColor ? { color: member.roleColor } : {}, [ member.roleColor ]);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import CombinedGuild from '../../../guild-combined';
|
|||||||
import ImageContextMenu from '../../contexts/context-menu-image';
|
import ImageContextMenu from '../../contexts/context-menu-image';
|
||||||
import ImageOverlay from '../../overlays/overlay-image';
|
import ImageOverlay from '../../overlays/overlay-image';
|
||||||
import ElementsUtil, { IAlignment } from '../../require/elements-util';
|
import ElementsUtil, { IAlignment } from '../../require/elements-util';
|
||||||
import GuildSubscriptions from '../../require/guild-subscriptions';
|
import { useSoftImageSrcResourceSubscription } from '../../require/guild-subscriptions';
|
||||||
import { useContextClickContextMenu, useDownloadButton, useOneTimeAsyncAction } from '../../require/react-helper';
|
import { useContextClickContextMenu, useDownloadButton, useOneTimeAsyncAction } from '../../require/react-helper';
|
||||||
|
|
||||||
interface ResourceElementProps {
|
interface ResourceElementProps {
|
||||||
@ -53,7 +53,7 @@ const PreviewImageElement: FC<PreviewImageElementProps> = (props: PreviewImageEl
|
|||||||
const { guild, previewWidth, previewHeight, resourcePreviewId, resourceId, resourceName, setOverlay } = props;
|
const { guild, previewWidth, previewHeight, resourcePreviewId, resourceId, resourceName, setOverlay } = props;
|
||||||
|
|
||||||
// TODO: Handle resourceError
|
// TODO: Handle resourceError
|
||||||
const [ previewImgSrc, previewResource, previewResourceError ] = GuildSubscriptions.useSoftImageSrcResourceSubscription(guild, resourcePreviewId);
|
const [ previewImgSrc, previewResource, previewResourceError ] = useSoftImageSrcResourceSubscription(guild, resourcePreviewId);
|
||||||
|
|
||||||
const [ contextMenu, onContextMenu ] = useContextClickContextMenu((alignment: IAlignment, relativeToPos: { x: number, y: number }, close: () => void) => {
|
const [ contextMenu, onContextMenu ] = useContextClickContextMenu((alignment: IAlignment, relativeToPos: { x: number, y: number }, close: () => void) => {
|
||||||
if (!previewResource) return null;
|
if (!previewResource) return null;
|
||||||
|
@ -7,8 +7,8 @@ import React, { Dispatch, FC, ReactNode, SetStateAction, useMemo } from 'react';
|
|||||||
import { Channel, Message } from '../../data-types';
|
import { Channel, Message } from '../../data-types';
|
||||||
import CombinedGuild from '../../guild-combined';
|
import CombinedGuild from '../../guild-combined';
|
||||||
import MessageElement from './components/message-element';
|
import MessageElement from './components/message-element';
|
||||||
import GuildSubscriptions from '../require/guild-subscriptions';
|
|
||||||
import InfiniteScroll from '../components/infinite-scroll';
|
import InfiniteScroll from '../components/infinite-scroll';
|
||||||
|
import { useMessagesScrollingSubscription } from '../require/guild-subscriptions';
|
||||||
|
|
||||||
interface MessageListProps {
|
interface MessageListProps {
|
||||||
guild: CombinedGuild;
|
guild: CombinedGuild;
|
||||||
@ -29,7 +29,7 @@ const MessageList: FC<MessageListProps> = (props: MessageListProps) => {
|
|||||||
messagesFetchError,
|
messagesFetchError,
|
||||||
messagesFetchAboveError,
|
messagesFetchAboveError,
|
||||||
messagesFetchBelowError
|
messagesFetchBelowError
|
||||||
] = GuildSubscriptions.useMessagesScrollingSubscription(guild, channel);
|
] = useMessagesScrollingSubscription(guild, channel);
|
||||||
|
|
||||||
const messageElements = useMemo(() => {
|
const messageElements = useMemo(() => {
|
||||||
const result = [];
|
const result = [];
|
||||||
|
@ -8,9 +8,9 @@ import CombinedGuild from '../../guild-combined';
|
|||||||
import ElementsUtil, { IAlignment } from '../require/elements-util';
|
import ElementsUtil, { IAlignment } from '../require/elements-util';
|
||||||
import DownloadButton from '../components/button-download';
|
import DownloadButton from '../components/button-download';
|
||||||
import { useContextClickContextMenu } from '../require/react-helper';
|
import { useContextClickContextMenu } from '../require/react-helper';
|
||||||
import GuildSubscriptions from '../require/guild-subscriptions';
|
|
||||||
import ImageContextMenu from '../contexts/context-menu-image';
|
import ImageContextMenu from '../contexts/context-menu-image';
|
||||||
import Overlay from '../components/overlay';
|
import Overlay from '../components/overlay';
|
||||||
|
import { useSoftImageSrcResourceSubscription } from '../require/guild-subscriptions';
|
||||||
|
|
||||||
export interface ImageOverlayProps {
|
export interface ImageOverlayProps {
|
||||||
guild: CombinedGuild
|
guild: CombinedGuild
|
||||||
@ -24,7 +24,7 @@ const ImageOverlay: FC<ImageOverlayProps> = (props: ImageOverlayProps) => {
|
|||||||
|
|
||||||
const rootRef = useRef<HTMLDivElement>(null);
|
const rootRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const [ imgSrc, resource, resourceError ] = GuildSubscriptions.useSoftImageSrcResourceSubscription(guild, resourceId);
|
const [ imgSrc, resource, resourceError ] = useSoftImageSrcResourceSubscription(guild, resourceId);
|
||||||
|
|
||||||
const [ contextMenu, onContextMenu ] = useContextClickContextMenu((alignment: IAlignment, relativeToPos: { x: number, y: number }, close: () => void) => {
|
const [ contextMenu, onContextMenu ] = useContextClickContextMenu((alignment: IAlignment, relativeToPos: { x: number, y: number }, close: () => void) => {
|
||||||
if (!resource) return null;
|
if (!resource) return null;
|
||||||
|
@ -10,10 +10,10 @@ import CombinedGuild from '../../guild-combined';
|
|||||||
import ImageEditInput from '../components/input-image-edit';
|
import ImageEditInput from '../components/input-image-edit';
|
||||||
import TextInput from '../components/input-text';
|
import TextInput from '../components/input-text';
|
||||||
import SubmitOverlayLower from '../components/submit-overlay-lower';
|
import SubmitOverlayLower from '../components/submit-overlay-lower';
|
||||||
import GuildSubscriptions from '../require/guild-subscriptions';
|
|
||||||
import { useAsyncSubmitButton } from '../require/react-helper';
|
import { useAsyncSubmitButton } from '../require/react-helper';
|
||||||
import Button from '../components/button';
|
import Button from '../components/button';
|
||||||
import Overlay from '../components/overlay';
|
import Overlay from '../components/overlay';
|
||||||
|
import { useResourceSubscription } from '../require/guild-subscriptions';
|
||||||
|
|
||||||
export interface PersonalizeOverlayProps {
|
export interface PersonalizeOverlayProps {
|
||||||
document: Document;
|
document: Document;
|
||||||
@ -26,7 +26,7 @@ const PersonalizeOverlay: FC<PersonalizeOverlayProps> = (props: PersonalizeOverl
|
|||||||
|
|
||||||
const rootRef = useRef<HTMLDivElement>(null);
|
const rootRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const [ avatarResource, avatarResourceError ] = GuildSubscriptions.useResourceSubscription(guild, selfMember.avatarResourceId)
|
const [ avatarResource, avatarResourceError ] = useResourceSubscription(guild, selfMember.avatarResourceId)
|
||||||
|
|
||||||
const displayNameInputRef = createRef<HTMLInputElement>();
|
const displayNameInputRef = createRef<HTMLInputElement>();
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ export default class ElementsUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid this function. Use GuildSubscriptions.useSoftImgSrcResourceSubscription instead
|
// Avoid this function. Use useSoftImgSrcResourceSubscription instead
|
||||||
static async getImageSrcFromResourceFailSoftly(guild: CombinedGuild, resourceId: string | null): Promise<string> {
|
static async getImageSrcFromResourceFailSoftly(guild: CombinedGuild, resourceId: string | null): Promise<string> {
|
||||||
if (resourceId === null) {
|
if (resourceId === null) {
|
||||||
return './img/loading.svg';
|
return './img/loading.svg';
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,7 @@ import CombinedGuild from '../../guild-combined';
|
|||||||
import ChannelList from '../lists/channel-list';
|
import ChannelList from '../lists/channel-list';
|
||||||
import MemberList from '../lists/member-list';
|
import MemberList from '../lists/member-list';
|
||||||
import MessageList from '../lists/message-list';
|
import MessageList from '../lists/message-list';
|
||||||
import GuildSubscriptions from '../require/guild-subscriptions';
|
import { useSelfMemberSubscription, useGuildMetadataSubscription, useMembersSubscription, useChannelsSubscription } from '../require/guild-subscriptions';
|
||||||
import ChannelTitle from './channel-title';
|
import ChannelTitle from './channel-title';
|
||||||
import ConnectionInfo from './connection-info';
|
import ConnectionInfo from './connection-info';
|
||||||
import GuildTitle from './guild-title';
|
import GuildTitle from './guild-title';
|
||||||
@ -23,10 +23,10 @@ const GuildElement: FC<GuildElementProps> = (props: GuildElementProps) => {
|
|||||||
// TODO: React set hasMessagesAbove and hasMessagesBelow when re-verified?
|
// TODO: React set hasMessagesAbove and hasMessagesBelow when re-verified?
|
||||||
// TODO: React jump messages to bottom when the current user sent a message
|
// TODO: React jump messages to bottom when the current user sent a message
|
||||||
|
|
||||||
const [ selfMember ] = GuildSubscriptions.useSelfMemberSubscription(guild);
|
const [ selfMember ] = useSelfMemberSubscription(guild);
|
||||||
const [ guildMeta, guildMetaFetchError ] = GuildSubscriptions.useGuildMetadataSubscription(guild);
|
const [ guildMeta, guildMetaFetchError ] = useGuildMetadataSubscription(guild);
|
||||||
const [ membersRetry, members, membersFetchError ] = GuildSubscriptions.useMembersSubscription(guild);
|
const [ membersRetry, members, membersFetchError ] = useMembersSubscription(guild);
|
||||||
const [ channelsRetry, channels, channelsFetchError ] = GuildSubscriptions.useChannelsSubscription(guild);
|
const [ channelsRetry, channels, channelsFetchError ] = useChannelsSubscription(guild);
|
||||||
|
|
||||||
const [ activeChannel, setActiveChannel ] = useState<Channel | null>(null);
|
const [ activeChannel, setActiveChannel ] = useState<Channel | null>(null);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user