Skip to content

Commit c9ef2b0

Browse files
Merge pull request #10876 from kind6688/fix-channel-list
251125 WEB/DESKTOP - fix : list channel , dont have socket
2 parents 1a97231 + 8d6e1f4 commit c9ef2b0

6 files changed

Lines changed: 120 additions & 15 deletions

File tree

apps/chat/src/app/pages/setting/channelSetting.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
selectNumberChannelCount,
99
useAppDispatch
1010
} from '@mezon/store';
11-
import { ChangeEvent, useEffect, useMemo, useState } from 'react';
11+
import type { ChangeEvent } from 'react';
12+
import { useEffect, useMemo, useState } from 'react';
1213
import { useSelector } from 'react-redux';
1314
import { useDebouncedCallback } from 'use-debounce';
1415
import ChannelTopBar from './ChannelTopBar';
@@ -42,8 +43,7 @@ const ChannelSetting = () => {
4243
return listChannelSearch;
4344
}
4445
return listChannel;
45-
}, [listChannelSearch, listChannel]);
46-
46+
}, [listChannelSearch, listChannel, searchFilter]);
4747
useEffect(() => {
4848
async function fetchListChannel() {
4949
await dispatch(

libs/components/src/lib/components/ChannelList/EventChannelModal/ModalCreate/modalDetailItemEvent.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ const EventInfoDetail = (props: EventInfoDetailProps) => {
141141
}
142142
}
143143
};
144+
const avatarDefault = userCreate?.clan_avatar || userCreate?.user?.avatar_url;
145+
const avatarLetter = (userCreate?.clan_nick || userCreate?.user?.display_name || userCreate?.user?.username)?.trim().charAt(0).toUpperCase();
144146

145147
return (
146148
<div className="px-4 py-8 space-y-2 text-theme-primary max-h-[370px] h-fit hide-scrollbar overflow-auto">
@@ -218,11 +220,17 @@ const EventInfoDetail = (props: EventInfoDetailProps) => {
218220
<p>{t('eventDetail.personInterested', { count: event?.user_ids?.length || 0 })}</p>
219221
</div>
220222
<div className="flex items-center gap-x-3">
221-
<img
222-
src={createImgproxyUrl(userCreate?.clan_avatar || userCreate?.user?.avatar_url || '')}
223-
alt={userCreate?.clan_nick || userCreate?.user?.username}
224-
className="size-5 rounded-full"
225-
/>
223+
{avatarDefault ? (
224+
<img
225+
src={createImgproxyUrl(avatarDefault)}
226+
alt={userCreate?.clan_nick || userCreate?.user?.username}
227+
className="size-5 rounded-full object-cover"
228+
/>
229+
) : (
230+
<div className="size-5 bg-bgAvatarDark rounded-full flex justify-center items-center text-bgAvatarLight text-lg ">
231+
{avatarLetter || '?'}
232+
</div>
233+
)}
226234
<p>{t('eventDetail.createdBy', { username: userCreate?.clan_nick || userCreate?.user?.username })}</p>
227235
</div>
228236
<div className="break-all" data-e2e={generateE2eId('clan_page.modal.create_event.event_management.item.modal_detail_item.description')}>

libs/components/src/lib/components/ClanSettings/SettingSoundEffect/ModalUploadSound.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,15 @@ const ModalUploadSound = ({ sound, onSuccess, onClose }: ModalUploadSoundProps)
283283
value={name}
284284
maxLength={62}
285285
onChange={(e) => setName(e.target.value)}
286-
className="w-full h-full px-3 py-2 bg-transparent text-theme-messaga=e border-none rounded-md text-sm focus:outline-none focus:ring-0 focus:border-none "
286+
className="w-full h-full px-3 py-2 bg-transparent text-theme-messaga=e border-none rounded-md text-sm focus:outline-none focus:ring-0 focus:border-none pr-[50px]"
287287
/>
288288
<div className="absolute right-3 top-1/2 transform -translate-y-1/2">
289-
<span className={`text-xs font-medium ${name.length > 25 ? 'text-[#faa61a]' : ''}`}>
290-
{name.length}/62
289+
<span
290+
className={`text-xs font-medium ${
291+
(name.length ?? 0) > 59 ? 'text-red-500' : (name.length ?? 0) > 40 ? 'text-[#faa61a]' : ''
292+
}`}
293+
>
294+
{name.length ?? 0}/62
291295
</span>
292296
</div>
293297
</div>

libs/components/src/lib/components/GifsStickersEmojis/inputSearch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const InputSearch: React.FC = () => {
9595
onChange={handleInputChange}
9696
type="text"
9797
placeholder={placeHolder}
98-
className="bg-theme-input outline-none bg-theme-input flex-1 p-2 rounded-md "
98+
className="bg-theme-input outline-none bg-theme-input flex-1 p-2 rounded-md pr-10"
9999
value={valueInput}
100100
ref={searchInputRef}
101101
/>

libs/core/src/lib/chat/contexts/ChatContext.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
channelMembers,
1616
channelMembersActions,
1717
channelMetaActions,
18+
channelSettingActions,
1819
channelsActions,
1920
channelsSlice,
2021
clansActions,
@@ -1472,8 +1473,24 @@ const ChatContextProvider: React.FC<ChatContextProviderProps> = ({ children, isM
14721473
);
14731474
}
14741475
}
1475-
}, []);
14761476

1477+
if (channelCreated.channel_type !== ChannelType.CHANNEL_TYPE_DM && channelCreated.channel_type !== ChannelType.CHANNEL_TYPE_GROUP) {
1478+
dispatch(
1479+
channelSettingActions.addChannelFromSocket({
1480+
id: channelCreated.channel_id,
1481+
channel_id: channelCreated.channel_id,
1482+
channel_label: channelCreated.channel_label,
1483+
parent_id: channelCreated.parent_id,
1484+
category_id: channelCreated.category_id,
1485+
clan_id: channelCreated.clan_id,
1486+
channel_private: channelCreated.channel_private,
1487+
channel_type: channelCreated.channel_type,
1488+
creator_id: channelCreated.creator_id,
1489+
app_id: channelCreated.app_id
1490+
})
1491+
);
1492+
}
1493+
}, []);
14771494
const oncategoryevent = useCallback(async (categoryEvent: CategoryEvent) => {
14781495
if (categoryEvent.status === EEventAction.CREATED) {
14791496
dispatch(
@@ -1630,6 +1647,10 @@ const ChatContextProvider: React.FC<ChatContextProviderProps> = ({ children, isM
16301647
dispatch(voiceActions.resetVoiceControl());
16311648
}
16321649

1650+
if (channelDeleted.channel_id !== '0') {
1651+
dispatch(channelSettingActions.removeChannelFromSocket(channelDeleted.channel_id));
1652+
}
1653+
16331654
if (channelDeleted?.deletor === userId) {
16341655
dispatch(channelsActions.deleteChannelSocket(channelDeleted));
16351656
dispatch(listChannelsByUserActions.remove(channelDeleted.channel_id));
@@ -1757,7 +1778,22 @@ const ChatContextProvider: React.FC<ChatContextProviderProps> = ({ children, isM
17571778
}
17581779
return dispatch(directActions.updateOne({ ...channelUpdated, currentUserId: userId }));
17591780
}
1760-
1781+
if (channelUpdated.channel_type !== ChannelType.CHANNEL_TYPE_DM && channelUpdated.channel_type !== ChannelType.CHANNEL_TYPE_GROUP) {
1782+
dispatch(
1783+
channelSettingActions.updateChannelFromSocket({
1784+
id: channelUpdated.channel_id,
1785+
channel_id: channelUpdated.channel_id,
1786+
channel_label: channelUpdated.channel_label,
1787+
parent_id: channelUpdated.parent_id,
1788+
category_id: channelUpdated.category_id,
1789+
clan_id: channelUpdated.clan_id,
1790+
channel_private: channelUpdated.channel_private,
1791+
channel_type: channelUpdated.channel_type,
1792+
creator_id: channelUpdated.creator_id,
1793+
app_id: channelUpdated.app_id
1794+
})
1795+
);
1796+
}
17611797
// Switch public to private
17621798
if (channelUpdated.channel_private && channelExist && channelExist.channel_private !== channelUpdated.channel_private) {
17631799
const result = await dispatch(

libs/store/src/lib/clans/clanSettingChannel.slice.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,64 @@ export const fetchChannelSettingInClan = createAsyncThunk(
145145
export const settingClanChannelSlice = createSlice({
146146
name: SETTING_CLAN_CHANNEL,
147147
initialState: initialSettingClanChannelState,
148-
reducers: {},
148+
reducers: {
149+
addChannelFromSocket: (state, action) => {
150+
const channel = action.payload;
151+
if (!channel?.id) return;
152+
if (channel.parent_id && channel.parent_id !== '0') {
153+
if (!state.threadsByChannel[channel.parent_id]) {
154+
state.threadsByChannel[channel.parent_id] = [];
155+
}
156+
const existingThread = state.threadsByChannel[channel.parent_id].find((t) => t.id === channel.id);
157+
if (!existingThread) {
158+
state.threadsByChannel[channel.parent_id].push(channel);
159+
state.threadCount += 1;
160+
}
161+
return;
162+
}
163+
channelSettingAdapter.addOne(state, channel);
164+
state.channelCount += 1;
165+
},
166+
removeChannelFromSocket: (state, action) => {
167+
const channelId = action.payload;
168+
if (state.entities[channelId]) {
169+
channelSettingAdapter.removeOne(state, channelId);
170+
state.channelCount = Math.max(0, state.channelCount - 1);
171+
return;
172+
}
173+
Object.keys(state.threadsByChannel).some((parentId) => {
174+
const threads = state.threadsByChannel[parentId];
175+
const threadExists = threads.some((t) => t.id === channelId);
176+
if (threadExists) {
177+
state.threadsByChannel[parentId] = threads.filter((t) => t.id !== channelId);
178+
state.threadCount = Math.max(0, state.threadCount - 1);
179+
return true;
180+
}
181+
return false;
182+
});
183+
},
184+
updateChannelFromSocket: (state, action) => {
185+
const channel = action.payload;
186+
if (!channel?.id) return;
187+
if (state.entities[channel.id]) {
188+
channelSettingAdapter.updateOne(state, {
189+
id: channel.id,
190+
changes: channel
191+
});
192+
return;
193+
}
194+
if (channel.parent_id && state.threadsByChannel[channel.parent_id]) {
195+
const threads = state.threadsByChannel[channel.parent_id];
196+
const threadIndex = threads.findIndex((t) => t.id === channel.id);
197+
if (threadIndex !== -1) {
198+
state.threadsByChannel[channel.parent_id][threadIndex] = {
199+
...threads[threadIndex],
200+
...channel
201+
};
202+
}
203+
}
204+
}
205+
},
149206
extraReducers(builder) {
150207
builder
151208
.addCase(fetchChannelSettingInClan.fulfilled, (state: SettingClanChannelState, actions) => {

0 commit comments

Comments
 (0)