Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dingens lol haher #121

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions mobile-app/api/realtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextEncoder } from 'text-encoding';

import { Logger, ScopedLogger } from '@/utils/logging';

Check warning on line 3 in mobile-app/api/realtime/index.ts

View workflow job for this annotation

GitHub Actions / Lint Code

'Logger' is defined but never used

/**
* stompjs is an abstraction layer on top of websocket that uses the global TextEncoder class.
Expand Down Expand Up @@ -72,21 +72,6 @@
});

this.ws.addEventListener('message', (e) => this.onMessage(e));

this.ws.addEventListener('open', () => {
this.logger.info('connection opened');
this._subscribeToGroups();
});

this.ws.addEventListener('close', () => {
this.logger.info('connection closed');
});

this.ws.addEventListener('error', (e) => {
this.logger.error('error:', e);
});

this.ws.addEventListener('message', (e) => this.onMessage(e));
}

/**
Expand Down
53 changes: 30 additions & 23 deletions mobile-app/api/realtime/useRealtimeConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import { useLogging } from '@/utils/useLogging';
import { useGroupStore } from '@/zustand/group/stateGroupStore';

import { RealtimeClient } from '.';
import {
RealtimeAffectedEntity,

Check warning on line 9 in mobile-app/api/realtime/useRealtimeConnection.ts

View workflow job for this annotation

GitHub Actions / Lint Code

'RealtimeAffectedEntity' is defined but never used
RealtimeClient,
RealtimeEvent,

Check warning on line 11 in mobile-app/api/realtime/useRealtimeConnection.ts

View workflow job for this annotation

GitHub Actions / Lint Code

'RealtimeEvent' is defined but never used
RealtimeEventHandler,
} from '.';
import { env } from '../env';
import { ignoreSeason, QK } from '../utils/reactQuery';

Expand All @@ -22,27 +27,7 @@
writeLog(...data);
}

useEffect(() => {
if (client.current) {
client.current.logger.addEventListener('*', writeLogs);

return () =>
client.current.logger.removeEventListener('*', writeLogs);
}
}, [client.current]);

useEffect(() => {
client.current.subscribeToGroups(groupIds);
}, [groupIds]);

function refetchGroup(groupId: string) {
qc.invalidateQueries({
queryKey: [QK.group, groupId],
exact: true,
});
}

client.current.on.event((e) => {
const hoher: RealtimeEventHandler = (e) => {
switch (e.eventType) {
case 'GROUPS':
client.current.logger.info('refetching groups');
Expand Down Expand Up @@ -125,7 +110,29 @@
});
break;
}
});
};

useEffect(() => {
if (client.current) {
client.current.logger.addEventListener('*', writeLogs);

client.current.on.event(hoher);

return () =>
client.current.logger.removeEventListener('*', writeLogs);

Check warning on line 122 in mobile-app/api/realtime/useRealtimeConnection.ts

View workflow job for this annotation

GitHub Actions / Lint Code

The ref value 'client.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'client.current' to a variable inside the effect, and use that variable in the cleanup function
}
}, [client.current]);

Check warning on line 124 in mobile-app/api/realtime/useRealtimeConnection.ts

View workflow job for this annotation

GitHub Actions / Lint Code

React Hook useEffect has missing dependencies: 'hoher' and 'writeLogs'. Either include them or remove the dependency array. Mutable values like 'client.current' aren't valid dependencies because mutating them doesn't re-render the component

useEffect(() => {
client.current.subscribeToGroups(groupIds);
}, [groupIds]);

function refetchGroup(groupId: string) {
qc.invalidateQueries({
queryKey: [QK.group, groupId],
exact: true,
});
}

return client.current;
}
Loading