toast cleanup

This commit is contained in:
talksik
2022-06-20 07:09:15 -05:00
parent 8b8c645ec4
commit 8a26212f50
4 changed files with 29 additions and 29 deletions
@@ -44,10 +44,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
fetchUser() fetchUser()
.then((response) => { .then((response) => {
toast.success('authenticated user'); // toast.success('authenticated user');
}) })
.catch(() => { .catch((error) => {
toast.error('problem in authenticating jwt token'); toast.error('problem in authenticating');
console.error(error);
}); });
} }
}, [jwtToken, fetchUser]); }, [jwtToken, fetchUser]);
@@ -58,10 +59,10 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
fetchUser() fetchUser()
.then((response) => { .then((response) => {
toast.success('authenticated user'); // toast.success('authenticated user');
}) })
.catch(() => { .catch((error) => {
toast.error('logged out'); // toast.error('logged out');
}); });
setJwtToken(undefined); setJwtToken(undefined);
@@ -98,7 +98,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
$ws.on(ServerResponseChannels.SOMEONE_CONNECTED_TO_LINE, (res: SomeoneConnectedResponse) => { $ws.on(ServerResponseChannels.SOMEONE_CONNECTED_TO_LINE, (res: SomeoneConnectedResponse) => {
setConversationMap((draft) => { setConversationMap((draft) => {
if (!draft[res.lineId]) { if (!draft[res.lineId]) {
toast.error('no line'); console.error('no line');
return; return;
} }
@@ -110,7 +110,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
$ws.on(ServerResponseChannels.SOMEONE_TUNED_INTO_LINE, (res: SomeoneTunedResponse) => { $ws.on(ServerResponseChannels.SOMEONE_TUNED_INTO_LINE, (res: SomeoneTunedResponse) => {
setConversationMap((draft) => { setConversationMap((draft) => {
if (!draft[res.lineId]) { if (!draft[res.lineId]) {
toast.error('no line'); console.error('no line');
return; return;
} }
@@ -123,7 +123,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
(res: SomeoneUntunedFromLineResponse) => { (res: SomeoneUntunedFromLineResponse) => {
setConversationMap((draft) => { setConversationMap((draft) => {
if (!draft[res.lineId]) { if (!draft[res.lineId]) {
toast.error('no line'); console.error('no line');
return; return;
} }
@@ -141,7 +141,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
(res: SomeoneDisconnectedResponse) => { (res: SomeoneDisconnectedResponse) => {
setConversationMap((draft) => { setConversationMap((draft) => {
if (!draft[res.lineId]) { if (!draft[res.lineId]) {
toast.error('there was a problem updating rooms!!!'); console.error('there was a problem updating rooms!!!');
return; return;
} }
@@ -208,8 +208,6 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
let conversationToSelect: MasterConversation; let conversationToSelect: MasterConversation;
if (allConversationIds.includes(conversationId)) { if (allConversationIds.includes(conversationId)) {
toast.success('we have that conversation!!!');
conversationToSelect = conversationMap[conversationId]; conversationToSelect = conversationMap[conversationId];
} else { } else {
// TODO: somehow use handleAddToCache instead of this duplicated code // TODO: somehow use handleAddToCache instead of this duplicated code
@@ -290,7 +288,8 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
*/ */
if (!otherUsers || otherUsers.length === 0) { if (!otherUsers || otherUsers.length === 0) {
toast.error('Must provider users'); toast.error('Must select other people!');
return false; return false;
} }
@@ -305,7 +304,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
// if we found a conversation // if we found a conversation
if (conversationDmCheck.data) { if (conversationDmCheck.data) {
toast.success('already have this user...quick dialing'); console.log('already have this user...quick dialing');
selectConversation(conversationDmCheck.data, true); selectConversation(conversationDmCheck.data, true);
return true; return true;
@@ -318,8 +317,6 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
selectConversation(createdConversationResult.data.conversationId.toString(), true); selectConversation(createdConversationResult.data.conversationId.toString(), true);
toast.success('started conversation');
return true; return true;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@@ -464,11 +461,10 @@ function Room({
const allOtherUserIds = conversation.tunedInUsers.filter( const allOtherUserIds = conversation.tunedInUsers.filter(
(memberUserId) => memberUserId !== user._id.toString(), (memberUserId) => memberUserId !== user._id.toString(),
); );
toast.success('calling bunch of people');
// for each person, create peer object // for each person, create peer object
allOtherUserIds.forEach((otherUserId) => { allOtherUserIds.forEach((otherUserId) => {
const connectingToast = toast.loading('calling peer for a snappy experience'); const connectingToast = toast.loading('connecting you for a snappy experience');
// ========= PEER CREATION ============= // ========= PEER CREATION =============
// make sure this peer gets destroyed when it's time to remove this listener // make sure this peer gets destroyed when it's time to remove this listener
@@ -483,7 +479,7 @@ function Room({
// ========= PEER EVENT HANDLERS ============= // ========= PEER EVENT HANDLERS =============
localPeerConnection.on('signal', (signal) => { localPeerConnection.on('signal', (signal) => {
console.log('have a signal to make call to someone '); // console.log('have a signal to make call to someone ');
$ws.emit( $ws.emit(
ServerRequestChannels.RTC_CALL_SOMEONE_FOR_LINE, ServerRequestChannels.RTC_CALL_SOMEONE_FOR_LINE,
@@ -506,7 +502,7 @@ function Room({
localPeerConnection.on('stream', (remoteStream: MediaStream) => { localPeerConnection.on('stream', (remoteStream: MediaStream) => {
// globally updating conversation so that other views can render what they want // globally updating conversation so that other views can render what they want
toast.success('got stream from remote, going to add to our '); // toast.success('got stream from remote, going to add to our ');
console.log('got stream from master'); console.log('got stream from master');
@@ -522,7 +518,7 @@ function Room({
}); });
localPeerConnection.on('connect', () => { localPeerConnection.on('connect', () => {
toast.success('successfully connected to another peer'); // toast.success('successfully connected to another peer');
setConversationMap((draft) => { setConversationMap((draft) => {
if (draft[conversation._id.toString()].room[otherUserId]) { if (draft[conversation._id.toString()].room[otherUserId]) {
draft[conversation._id.toString()].room[otherUserId].isConnecting = false; draft[conversation._id.toString()].room[otherUserId].isConnecting = false;
@@ -553,7 +549,7 @@ function Room({
localPeerConnection.on('error', (err) => { localPeerConnection.on('error', (err) => {
console.error(err); console.error(err);
toast.error('there was a problem with the peer connection'); toast.error('there was a problem with the connecting');
}); });
}); });
} }
@@ -570,7 +566,7 @@ function Room({
}:${conversation._id.toString()}`; }:${conversation._id.toString()}`;
$ws.on(someoneJoinedChannelNameForRoom, (res: RtcNewUserJoinedResponse) => { $ws.on(someoneJoinedChannelNameForRoom, (res: RtcNewUserJoinedResponse) => {
toast.success('NEWBIE JOINED!!!'); // toast.success('NEWBIE JOINED!!!');
console.log('someone calling me', res); console.log('someone calling me', res);
// todo, take trickle into account to not overwrite prev peer // todo, take trickle into account to not overwrite prev peer
@@ -606,7 +602,7 @@ function Room({
peerForMeAndNewbie.on('stream', (remoteStream: MediaStream) => { peerForMeAndNewbie.on('stream', (remoteStream: MediaStream) => {
// globally updating conversation so that other views can render what they want // globally updating conversation so that other views can render what they want
toast.success('got stream from remote, going to add to our '); // toast.success('got stream from remote, going to add to our ');
console.log('got stream from newbie'); console.log('got stream from newbie');
@@ -654,12 +650,12 @@ function Room({
peerForMeAndNewbie.on('error', (err) => { peerForMeAndNewbie.on('error', (err) => {
console.error(err); console.error(err);
toast.error('there was a problem with the peer connection'); toast.error('there was a problem with connecting');
}); });
}); });
$ws.on(mastersAnswerReceivedChannelNameForRoom, (res: RtcReceiveAnswerResponse) => { $ws.on(mastersAnswerReceivedChannelNameForRoom, (res: RtcReceiveAnswerResponse) => {
toast.success('MASTER gave me an answer!!!'); // toast.success('MASTER gave me an answer!!!');
console.log('master gave me this answer: ', res); console.log('master gave me this answer: ', res);
@@ -24,7 +24,7 @@ export function SocketProvider({ children }: { children: React.ReactNode }) {
const initiateSocketStabilityListeners = useCallback( const initiateSocketStabilityListeners = useCallback(
(socketConnection: Socket) => { (socketConnection: Socket) => {
socketConnection.on('connect', () => { socketConnection.on('connect', () => {
toast.success('sockets connected'); // toast.success('sockets connected');
}); });
socketConnection.io.on('close', () => { socketConnection.io.on('close', () => {
@@ -88,8 +88,11 @@ export default function NewConversationDialog() {
return; return;
} }
if (selectedUsers.length + 1 >= NirvanaRules.maxMembersPerConversation) { // everyone else + me should be less than or equal to max
toast.error('A group can only have 8 people including you!'); if (selectedUsers.length + 1 > NirvanaRules.maxMembersPerConversation) {
toast.error(
`A group can only have ${NirvanaRules.maxMembersPerConversation} people including you!`,
);
return; return;
} }