File size: 1,070 Bytes
cc276cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

"use client";

import React, { createContext, useContext, useCallback } from 'react';
import { useGroupsCore } from '@/hooks/use-groups';
import type { ChatRecipient } from '@/lib/types';


type GroupsContextType = ReturnType<typeof useGroupsCore>;

const GroupsContext = createContext<GroupsContextType | null>(null);

export const useGroups = () => {
    const context = useContext(GroupsContext);
    if (!context) {
        throw new Error('useGroups must be used within a GroupsProvider');
    }
    return context;
};

export const GroupsProvider = ({ children }: { children: React.ReactNode }) => {
    // This hook is no longer used to set the recipient directly,
    // so we can pass a dummy function.
    const dummySetRecipient = useCallback((recipient: ChatRecipient | null | ((prev: ChatRecipient | null) => ChatRecipient | null)) => {}, []);
    const groupsData = useGroupsCore({ setRecipient: dummySetRecipient });
    
    return (
        <GroupsContext.Provider value={groupsData}>
            {children}
        </GroupsContext.Provider>
    );
};