fix(sidebar): don't keep refetching server members

This commit is contained in:
Paul Makles 2022-01-04 13:37:19 +00:00
parent 3baf82ca94
commit fc91a75acb
2 changed files with 17 additions and 3 deletions

View file

@ -179,14 +179,24 @@ export const GroupMemberSidebar = observer(
},
);
// ! FIXME: this is temporary code until we get lazy guilds like subscriptions
const FETCHED: Set<String> = new Set();
export function resetMemberSidebarFetched() {
FETCHED.clear();
}
export const ServerMemberSidebar = observer(
({ channel }: { channel: Channel }) => {
const client = useClient();
const status = useContext(StatusContext);
useEffect(() => {
if (status === ClientStatus.ONLINE) {
channel.server!.fetchMembers();
const server_id = channel.server_id!;
if (status === ClientStatus.ONLINE && !FETCHED.has(server_id)) {
channel
.server!.fetchMembers()
.then(() => FETCHED.add(server_id));
}
// eslint-disable-next-line
}, [status, channel.server_id]);

View file

@ -4,6 +4,7 @@ import { StateUpdater } from "preact/hooks";
import Auth from "../../mobx/stores/Auth";
import { resetMemberSidebarFetched } from "../../components/navigation/right/MemberSidebar";
import { ClientStatus } from "./RevoltClient";
export let preventReconnect = false;
@ -43,7 +44,10 @@ export function registerEvents(
attemptReconnect();
},
ready: () => setStatus(ClientStatus.ONLINE),
ready: () => {
resetMemberSidebarFetched();
setStatus(ClientStatus.ONLINE);
},
logout: () => {
auth.logout();