-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathApp.tsx
More file actions
66 lines (59 loc) · 2.44 KB
/
App.tsx
File metadata and controls
66 lines (59 loc) · 2.44 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React, { ChangeEvent, memo, useCallback, useState } from 'react';
import './App.css';
import { Get, Login } from '@microsoft/mgt-react';
import { Chat, NewChat } from '@microsoft/mgt-chat';
import { Chat as GraphChat } from '@microsoft/microsoft-graph-types';
import ChatListTemplate from './components/ChatListTemplate/ChatListTemplate';
import { FluentProvider, Switch, SwitchOnChangeData, teamsLightTheme } from '@fluentui/react-components';
const ChatList = memo(({ chatSelected }: { chatSelected: (e: GraphChat) => void }) => {
return (
<Get resource="me/chats?$expand=members" scopes={['Chat.ReadWrite']} cacheEnabled={false}>
<ChatListTemplate template="default" onSelected={chatSelected} />
</Get>
);
});
function App() {
const [chatId, setChatId] = useState<string>('');
const chatSelected = useCallback((e: GraphChat) => {
setChatId(e.id ?? '');
}, []);
const [showNewChat, setShowNewChat] = useState<boolean>(false);
const onChatCreated = useCallback((chat: GraphChat) => {
setChatId(chat.id ?? '');
setShowNewChat(false);
}, []);
const [usePremiumApis, setUsePremiumApis] = useState<boolean>(false);
const onToggleChanged = useCallback((ev: ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => {
setUsePremiumApis(data.checked ?? false);
}, []);
return (
<div className="App">
<FluentProvider theme={teamsLightTheme}>
<header className="App-header">
Mgt Chat test harness
<br />
<Login />
</header>
<main className="main">
<div className="chat-selector">
<Switch onChange={onToggleChanged} checked={usePremiumApis} label="Use premium APIs?" />
<ChatList chatSelected={chatSelected} />
Selected chat: {chatId}
<br />
<button onClick={() => setChatId('')}>Clear selected chat</button>
<br />
<button onClick={() => setShowNewChat(true)}>New Chat</button>
{showNewChat && (
<div className="new-chat">
<NewChat onChatCreated={onChatCreated} onCancelClicked={() => setShowNewChat(false)} mode="auto" />
</div>
)}
</div>
{/* NOTE: removed the chatId guard as this case has an error state. */}
<div className="chat-pane">{<Chat chatId={chatId} usePremiumApis={usePremiumApis} />}</div>
</main>
</FluentProvider>
</div>
);
}
export default App;