-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #1934 Move channel members types in features/channel-members/types * #1934 Update channel-members-api-client.ts * #1934 Add channel members state in features/channel-members * #1934 Add use channel members hook in features/channel-members * #1934 Implement channel members and pending emails state * #1934 Add use channel guests hook * #1927 Upgrade antd from 4.16.13 to 4.18.3 * #1928 Upgrade react-i18next from 11.12.0 to 11.15.3 * #1934 Implement Channel Members real time Co-authored-by: Romaric Mourgues <rmourgues@linagora.com>
- Loading branch information
1 parent
10e139a
commit 2905aed
Showing
30 changed files
with
739 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
twake/frontend/src/app/features/channel-members/hooks/use-channel-guests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useRecoilState } from 'recoil'; | ||
|
||
import { | ||
AtomChannelMembersKey, | ||
ChannelMemberType, | ||
} from 'app/features/channel-members/types/channel-member-types'; | ||
import { ChannelGuestsState } from 'app/features/channel-members/state/channel-guests'; | ||
import { useGlobalEffect } from 'app/features/global/hooks/use-global-effect'; | ||
import { LoadingState } from 'app/features/global/state/atoms/Loading'; | ||
import ChannelMembersAPIClient from '../api/channel-members-api-client'; | ||
|
||
export const useChannelGuests = ( | ||
key: AtomChannelMembersKey, | ||
): { | ||
channelGuests: ChannelMemberType[]; | ||
loading: boolean; | ||
refresh: () => Promise<void>; | ||
} => { | ||
const [channelGuests, _setChannelGuests] = useRecoilState(ChannelGuestsState(key)); | ||
const [loading, setLoading] = useRecoilState(LoadingState(`channel-guests-${key.channelId}`)); | ||
|
||
const refresh = async () => { | ||
const { companyId, workspaceId, channelId } = key; | ||
const channelGuestsUpdated = await ChannelMembersAPIClient.list( | ||
{ | ||
companyId, | ||
workspaceId, | ||
channelId, | ||
}, | ||
{ role: 'guest' }, | ||
); | ||
|
||
if (channelGuestsUpdated) _setChannelGuests(channelGuestsUpdated); | ||
}; | ||
|
||
useGlobalEffect( | ||
'useChannelGuests', | ||
async () => { | ||
if (!channelGuests) setLoading(true); | ||
|
||
await refresh(); | ||
|
||
setLoading(false); | ||
}, | ||
[key, channelGuests], | ||
); | ||
|
||
return { | ||
channelGuests, | ||
loading, | ||
refresh, | ||
}; | ||
}; |
57 changes: 57 additions & 0 deletions
57
twake/frontend/src/app/features/channel-members/hooks/use-channel-members.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useRecoilState } from 'recoil'; | ||
|
||
import { | ||
AtomChannelMembersKey, | ||
ChannelMemberType, | ||
} from 'app/features/channel-members/types/channel-member-types'; | ||
import { ChannelMembersState } from 'app/features/channel-members/state/channel-members'; | ||
import { useGlobalEffect } from 'app/features/global/hooks/use-global-effect'; | ||
import { LoadingState } from 'app/features/global/state/atoms/Loading'; | ||
import ChannelMembersAPIClient from '../api/channel-members-api-client'; | ||
import { useRealtimeRoom } from 'app/features/global/hooks/use-realtime'; | ||
|
||
export const useChannelMembers = ( | ||
key: AtomChannelMembersKey, | ||
): { | ||
channelMembers: ChannelMemberType[]; | ||
loading: boolean; | ||
refresh: () => Promise<void>; | ||
} => { | ||
const [channelMembers, _setChannelMembers] = useRecoilState(ChannelMembersState(key)); | ||
const [loading, setLoading] = useRecoilState(LoadingState(`channel-members-${key.channelId}`)); | ||
|
||
const refresh = async () => { | ||
const { companyId, workspaceId, channelId } = key; | ||
const channelMembersUpdated = await ChannelMembersAPIClient.list({ | ||
companyId, | ||
workspaceId, | ||
channelId, | ||
}); | ||
|
||
if (channelMembersUpdated) _setChannelMembers(channelMembersUpdated); | ||
}; | ||
|
||
useGlobalEffect( | ||
'useChannelMembers', | ||
async () => { | ||
if (!channelMembers) setLoading(true); | ||
|
||
await refresh(); | ||
|
||
setLoading(false); | ||
}, | ||
[key, channelMembers], | ||
); | ||
|
||
const room = ChannelMembersAPIClient.websocket(key)[0]; | ||
|
||
useRealtimeRoom<ChannelMemberType[]>(room, 'useChannelMembers', (_action, _resource) => { | ||
refresh(); | ||
}); | ||
|
||
return { | ||
channelMembers, | ||
loading, | ||
refresh, | ||
}; | ||
}; |
Oops, something went wrong.