@@ -9,7 +9,7 @@ import { NewAppModal } from '../components/modal/NewAppModal';
99import { Sorting } from '../components/Sorting' ;
1010import CsvButton from '../components/UI/Buttons/CSVButton.tsx' ;
1111import { Pagination } from '../components/UI/Pagination/Pagination.tsx' ;
12- import { useCentrifugeChannel } from '../hooks/useCentrifuge .ts' ;
12+ import { useCentrifugeAppUpdater } from '../hooks/useCentrifugeAppUpdater .ts' ;
1313import { getExportAppsCsv , httpGetApps } from '../http' ;
1414import { ModelApp , OrderByType } from '../models' ;
1515import { useAppStore } from '../store/useAppStore' ;
@@ -28,8 +28,6 @@ export default function AdminApps() {
2828 const doSetApps = useAppStore ( ( s ) => s . doSetApps ) ;
2929 const currentApp = useAppStore ( ( s ) => s . currentApp as ModelApp ) ;
3030
31- const { data } = useCentrifugeChannel ( ) ;
32-
3331 const limit = useMemo (
3432 ( ) => Number ( searchParams . get ( 'limit' ) ) || 5 ,
3533 [ searchParams ]
@@ -175,26 +173,28 @@ export default function AdminApps() {
175173 setAppState ( apps ) ;
176174 } , [ apps ] ) ;
177175
178- useEffect ( ( ) => {
179- if ( ! data ) return ;
180-
181- if ( data . type === 'counter_new_chats' ) {
182- setAppState ( ( prev ) =>
183- prev . map ( ( app ) =>
184- app . _id === data . appId
185- ? {
186- ...app ,
187- stats : {
188- ...app . stats ,
189- totalChats : app . stats . totalChats + 1 ,
190- recentlyChats : app . stats . recentlyChats + 1 ,
191- } ,
192- }
193- : app
194- )
195- ) ;
196- }
197- } , [ data ] ) ;
176+ useCentrifugeAppUpdater ( setAppState ) ;
177+
178+ // useEffect(() => {
179+ // if (!data) return;
180+
181+ // if (data.type === 'counter_chats') {
182+ // setAppState((prev) =>
183+ // prev.map((app) =>
184+ // app._id === data.appId
185+ // ? {
186+ // ...app,
187+ // stats: {
188+ // ...app.stats,
189+ // totalChats: app.stats.totalChats + 1,
190+ // recentlyChats: app.stats.recentlyChats + 1,
191+ // },
192+ // }
193+ // : app
194+ // )
195+ // );
196+ // }
197+ // }, [data]);
198198
199199 return (
200200 < >
@@ -218,7 +218,7 @@ export default function AdminApps() {
218218 ) }
219219 < button
220220 onClick = { ( ) => setShowModal ( true ) }
221- className = "flex items-center justify-center sm:w-[40px] h-[40px] w-[60px] bg-brand-500 rounded-xl hover:bg-brand-darker text-white text-sm font-varela"
221+ className = "flex items-center justify-center sm:w-full h-[40px] w-[60px] bg-brand-500 rounded-xl hover:bg-brand-darker text-white text-sm font-varela"
222222 >
223223 < IconAdd color = "white" className = "md:mr-2" />
224224 < span className = "hidden md:block" > Create App</ span >
@@ -234,13 +234,14 @@ export default function AdminApps() {
234234 < ApplicationStarterInf onClose = { ( ) => setShowStarterInf ( false ) } />
235235 ) }
236236
237- { appsState . map ( ( app ) => (
238- < ApplicationPreview
239- key = { app . _id }
240- app = { app }
241- primaryColor = { currentApp . primaryColor }
242- />
243- ) ) }
237+ { appsState &&
238+ appsState . map ( ( app ) => (
239+ < ApplicationPreview
240+ key = { app . _id }
241+ app = { app }
242+ primaryColor = { currentApp . primaryColor }
243+ />
244+ ) ) }
244245
245246 { currentUser ?. isSuperAdmin && (
246247 < Pagination
0 commit comments