Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuLpz4 committed Oct 2, 2024
1 parent fdbe60a commit 3a00a88
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/components/plaude.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ const usePlaude = () => {
};

type PlaudeMessengerProps = React.PropsWithChildren<{
appId: string;
open: boolean;
token?: string;
}>;

function PlaudeMessenger({ open, token, children }: PlaudeMessengerProps) {
function PlaudeMessenger({
appId,
open,
token,
children,
}: PlaudeMessengerProps) {
const { closeMessenger } = usePlaude();

return (
Expand All @@ -55,20 +61,23 @@ function PlaudeMessenger({ open, token, children }: PlaudeMessengerProps) {
<WebView
useWebView2
source={{
uri: `https://embed.plaudeai.com/messenger`,
headers: token
? {
authorization: `Basic ${token}`,
}
: undefined,
uri: `https://embed.plaudeai.com/messenger?appId${appId}&token=${token}`,
}}
/>
</Modal>
</>
);
}

const PlaudeProvider = ({ children }: React.PropsWithChildren) => {
type PlaudeProviderProps = React.PropsWithChildren<{
appId?: string;
}>;

const PlaudeProvider = ({ appId, children }: PlaudeProviderProps) => {
if (!(process.env.PLAUDE_APP_ID ?? appId)) {
throw new Error('It seems like you forgot to set the App ID.');
}

const [isMessengerOpen, setIsMessengerOpen] = useState(false);
const [token, setToken] = useState<string>();

Expand All @@ -82,7 +91,11 @@ const PlaudeProvider = ({ children }: React.PropsWithChildren) => {

return (
<PlaudeContext.Provider value={{ openMessenger, closeMessenger, setToken }}>
<PlaudeMessenger open={isMessengerOpen} token={token}>
<PlaudeMessenger
appId={(process.env.PLAUDE_APP_ID ?? appId)!}
open={isMessengerOpen}
token={token}
>
{children}
</PlaudeMessenger>
</PlaudeContext.Provider>
Expand Down

0 comments on commit 3a00a88

Please sign in to comment.