2023-09-22 17:06:04 +03:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { createContext, useState } from "react";
|
|
|
|
|
2023-09-28 12:29:55 +03:00
|
|
|
import { FeedItemType } from "@/app/chat/[chatId]/components/ActionsBar/types";
|
2023-09-22 17:06:04 +03:00
|
|
|
|
2023-09-28 16:39:30 +03:00
|
|
|
type KnowledgeToFeedContextType = {
|
2023-09-28 12:29:55 +03:00
|
|
|
knowledgeToFeed: FeedItemType[];
|
|
|
|
setKnowledgeToFeed: React.Dispatch<React.SetStateAction<FeedItemType[]>>;
|
2023-09-29 11:24:31 +03:00
|
|
|
shouldDisplayFeedCard: boolean;
|
|
|
|
setShouldDisplayFeedCard: React.Dispatch<React.SetStateAction<boolean>>;
|
2023-09-22 17:06:04 +03:00
|
|
|
};
|
|
|
|
|
2023-09-28 16:39:30 +03:00
|
|
|
export const KnowledgeToFeedContext = createContext<
|
|
|
|
KnowledgeToFeedContextType | undefined
|
|
|
|
>(undefined);
|
2023-09-22 17:06:04 +03:00
|
|
|
|
2023-09-28 16:39:30 +03:00
|
|
|
export const KnowledgeToFeedProvider = ({
|
2023-09-22 17:06:04 +03:00
|
|
|
children,
|
|
|
|
}: {
|
|
|
|
children: React.ReactNode;
|
|
|
|
}): JSX.Element => {
|
2023-09-28 12:29:55 +03:00
|
|
|
const [knowledgeToFeed, setKnowledgeToFeed] = useState<FeedItemType[]>([]);
|
2023-09-29 11:24:31 +03:00
|
|
|
const [shouldDisplayFeedCard, setShouldDisplayFeedCard] = useState(false);
|
2023-09-22 17:06:04 +03:00
|
|
|
|
|
|
|
return (
|
2023-09-28 16:39:30 +03:00
|
|
|
<KnowledgeToFeedContext.Provider
|
2023-09-22 17:06:04 +03:00
|
|
|
value={{
|
2023-09-28 12:29:55 +03:00
|
|
|
knowledgeToFeed,
|
|
|
|
setKnowledgeToFeed,
|
2023-09-29 11:24:31 +03:00
|
|
|
shouldDisplayFeedCard,
|
|
|
|
setShouldDisplayFeedCard,
|
2023-09-22 17:06:04 +03:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
2023-09-28 16:39:30 +03:00
|
|
|
</KnowledgeToFeedContext.Provider>
|
2023-09-22 17:06:04 +03:00
|
|
|
);
|
|
|
|
};
|