-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathApp.tsx
More file actions
149 lines (134 loc) Β· 4.67 KB
/
Copy pathApp.tsx
File metadata and controls
149 lines (134 loc) Β· 4.67 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { useEffect, useState } from 'react';
import type { ComponentType } from 'react';
import ClientSetupStep from './1-client-setup/App';
import CoreComponentSetupStep from './2-core-component-setup/App';
import ChannelListStep from './3-channel-list/App';
import CustomUiComponentsStep from './4-custom-ui-components/App';
import CustomAttachmentTypeStep from './5-custom-attachment-type/App';
import EmojiPickerStep from './6-emoji-picker/App';
import LivestreamStep from './7-livestream/App';
import './tutorial-main.css';
type TutorialStep = {
id: string;
title: string;
description: string;
Component: ComponentType;
};
const steps: TutorialStep[] = [
{
id: 'client-setup',
title: '1. Client Setup',
description:
'Connect the SDK to your Stream app and verify the chat client is ready.',
Component: ClientSetupStep,
},
{
id: 'core-component-setup',
title: '2. Core Components',
description:
'Render the first complete chat UI with Channel, MessageList, MessageComposer, and Thread.',
Component: CoreComponentSetupStep,
},
{
id: 'channel-list',
title: '3. Channel List',
description:
'Add channel navigation so the tutorial app feels like a real messaging experience.',
Component: ChannelListStep,
},
{
id: 'custom-ui-components',
title: '4. Custom UI Components',
description:
'Use WithComponents to replace SDK-owned UI surfaces without rebuilding the whole app.',
Component: CustomUiComponentsStep,
},
{
id: 'custom-attachment-type',
title: '5. Custom Attachment Type',
description:
'Render a branded product attachment while keeping the default attachment fallbacks.',
Component: CustomAttachmentTypeStep,
},
{
id: 'emoji-picker',
title: '6. Emoji Picker',
description:
'Wire a custom EmojiPicker into MessageComposer with built-in emoji search support.',
Component: EmojiPickerStep,
},
{
id: 'livestream',
title: '7. Livestream',
description:
'Switch the layout to a livestream-style experience with VirtualizedMessageList.',
Component: LivestreamStep,
},
];
const getInitialStep = () => {
const hash = window.location.hash.replace('#', '');
return steps.find((step) => step.id === hash) ?? steps[0];
};
const App = () => {
const [selectedStepId, setSelectedStepId] = useState(getInitialStep().id);
useEffect(() => {
const handleHashChange = () => {
const nextStep = getInitialStep();
setSelectedStepId(nextStep.id);
};
window.addEventListener('hashchange', handleHashChange);
return () => window.removeEventListener('hashchange', handleHashChange);
}, []);
useEffect(() => {
window.location.hash = selectedStepId;
}, [selectedStepId]);
const selectedStep = steps.find((step) => step.id === selectedStepId) ?? steps[0];
const SelectedComponent = selectedStep.Component;
return (
<div className='tutorial-browser'>
<aside className='tutorial-browser__sidebar'>
<div className='tutorial-browser__sidebar-copy'>
<div className='tutorial-browser__title'>React Tutorial</div>
<div className='tutorial-browser__subtitle'>
Browse every tutorial milestone without restarting the app.
</div>
</div>
<nav aria-label='Tutorial steps' className='tutorial-browser__nav'>
{steps.map((step) => {
const isActive = step.id === selectedStep.id;
return (
<button
className={`tutorial-browser__step-button${
isActive ? ' tutorial-browser__step-button--active' : ''
}`}
key={step.id}
onClick={() => setSelectedStepId(step.id)}
type='button'
>
<div className='tutorial-browser__step-title'>{step.title}</div>
<div className='tutorial-browser__step-description'>
{step.description}
</div>
</button>
);
})}
</nav>
</aside>
<main className='tutorial-browser__main'>
<header className='tutorial-browser__header'>
<div className='tutorial-browser__eyebrow'>CURRENT STEP</div>
<div className='tutorial-browser__header-title'>{selectedStep.title}</div>
<div className='tutorial-browser__header-description'>
{selectedStep.description}
</div>
</header>
<section className='tutorial-browser__preview-card'>
<div className='tutorial-browser__step-shell' key={selectedStep.id}>
<SelectedComponent />
</div>
</section>
</main>
</div>
);
};
export default App;