Skip to content

Commit 3d6bd9f

Browse files
chore: prepare public Vite example deployment (#3145)
1 parent 4a6a8ae commit 3d6bd9f

3 files changed

Lines changed: 74 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,24 @@ jobs:
5555
token: ${{ secrets.CODECOV_TOKEN }}
5656

5757
deploy-vite-example:
58+
strategy:
59+
matrix:
60+
projects:
61+
- name: Vite Example Development
62+
project-id: prj_2Rq8kuNd0BmqKd2NwvkDjX9Htnx5
63+
stream-api-key: rq7ntdb4zzsq
64+
- name: Vite Example Public
65+
project-id: prj_yBYBe1AJV0tbpTqxCMzcyRfFWXxP
66+
stream-api-key: xzwhhgtazy6h
5867
runs-on: ubuntu-latest
5968
# skip if build fails
6069
needs:
6170
- build
6271
name: Deploy Vite Example to Vercel
6372
env:
6473
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
65-
VERCEL_PROJECT_ID: prj_2Rq8kuNd0BmqKd2NwvkDjX9Htnx5
66-
VITE_STREAM_API_KEY: ${{ vars.VITE_STREAM_API_KEY }}
74+
VERCEL_PROJECT_ID: ${{ matrix.projects.project-id }}
75+
VITE_STREAM_API_KEY: ${{ matrix.projects.stream-api-key }}
6776
NODE_ENV: production
6877
steps:
6978
- uses: actions/checkout@v6
@@ -91,15 +100,15 @@ jobs:
91100
- name: Vercel Pull/Build/Deploy (Preview)
92101
working-directory: examples/vite
93102
if: ${{ github.ref_name != 'master' }}
94-
run: >
103+
run: >-
95104
npx vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} &&
96105
npx vercel build &&
97106
npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
98107
99108
- name: Vercel Pull/Build/Deploy (Production)
100109
working-directory: examples/vite
101110
if: ${{ github.ref_name == 'master' }}
102-
run: >
111+
run: >-
103112
npx vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} &&
104113
npx vercel build --prod &&
105114
npx vercel deploy --prod --prebuilt --token=${{ secrets.VERCEL_TOKEN }}

examples/vite/src/App.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ import {
6868
import { ConfigurableMessageActions } from './CustomMessageActions';
6969
import { SidebarToggle } from './Sidebar/SidebarToggle.tsx';
7070

71+
const PUBLIC_VITE_EXAMPLE_API_KEY = 'xzwhhgtazy6h';
72+
7173
init({ data });
7274

7375
const parseUserIdFromToken = (token: string) => {
@@ -125,12 +127,20 @@ const useUser = () => {
125127
localStorage.setItem('user_id', userId);
126128
}, [userId]);
127129

130+
const environment =
131+
apiKey === PUBLIC_VITE_EXAMPLE_API_KEY
132+
? 'public-shared-chat-redesign'
133+
: 'shared-chat-redesign';
134+
135+
const url = new URL('https://pronto.getstream.io/api/auth/create-token');
136+
137+
url.searchParams.set('environment', environment);
138+
url.searchParams.set('user_id', userId);
139+
128140
const tokenProvider = useCallback(() => {
129141
return token && userId === parseUserIdFromToken(token)
130142
? Promise.resolve(token)
131-
: fetch(
132-
`https://pronto.getstream.io/api/auth/create-token?environment=shared-chat-redesign&user_id=${userId}`,
133-
)
143+
: fetch(url.toString())
134144
.then((response) => response.json())
135145
.then((data) => data.token as string);
136146
}, [userId]);
@@ -249,6 +259,7 @@ const App = () => {
249259
...(userName && { name: userName }),
250260
},
251261
});
262+
252263
const searchController = useMemo(() => {
253264
if (!chatClient) return undefined;
254265

@@ -278,6 +289,14 @@ const App = () => {
278289
members: { $in: [userId] },
279290
},
280291
{ type: 'public' },
292+
// public example channels
293+
{
294+
cid: {
295+
$in: ['random', 'general', 'music', 'jokes'].map(
296+
(channelId) => `messaging:${channelId}`,
297+
),
298+
},
299+
},
281300
],
282301
}),
283302
[userId],

examples/vite/src/ChatLayout/Panels.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import clsx from 'clsx';
2-
import type { ChannelFilters, ChannelOptions, ChannelSort } from 'stream-chat';
3-
import { useEffect, useRef } from 'react';
2+
import type {
3+
ChannelFilters,
4+
ChannelMemberResponse,
5+
ChannelOptions,
6+
ChannelSort,
7+
} from 'stream-chat';
8+
import { useCallback, useEffect, useRef } from 'react';
49
import {
510
AIStateIndicator,
611
Channel,
@@ -21,6 +26,8 @@ import {
2126
useChatContext,
2227
type ChatViewSelectorEntry,
2328
useThreadsViewContext,
29+
Button,
30+
useChannelMembersState,
2431
} from 'stream-chat-react';
2532

2633
import { useAppSettingsSelector } from '../AppSettings/state';
@@ -97,6 +104,34 @@ const ResponsiveChannelPanels = () => {
97104
);
98105
};
99106

107+
const HeaderStartContent = () => {
108+
const { client } = useChatContext();
109+
const { channel } = useChannelStateContext();
110+
const members = useChannelMembersState(channel);
111+
const membership = members[client.userID!] as ChannelMemberResponse | undefined;
112+
113+
const isMember = typeof membership?.channel_role === 'string';
114+
const canJoin = channel.data?.own_capabilities?.includes('join-channel');
115+
116+
const handleClick = useCallback(() => {
117+
if (isMember) {
118+
channel.removeMembers([client.userID!]).then(() => {
119+
channel.watch();
120+
});
121+
} else {
122+
channel.addMembers([client.userID!]);
123+
}
124+
}, [isMember]);
125+
126+
if (!canJoin) return null;
127+
128+
return (
129+
<Button onClick={handleClick} variant='secondary' appearance='outline' size='sm'>
130+
{isMember ? 'Leave' : 'Join'}
131+
</Button>
132+
);
133+
};
134+
100135
export const ChannelsPanels = ({
101136
filters,
102137
iconOnly,
@@ -148,6 +183,7 @@ export const ChannelsPanels = ({
148183
}}
149184
>
150185
<ChannelList
186+
onRemovedFromChannel={() => {}}
151187
customActiveChannel={initialChannelId}
152188
filters={filters}
153189
options={options}
@@ -157,7 +193,7 @@ export const ChannelsPanels = ({
157193
</WithComponents>
158194
</div>
159195
<SidebarResizeHandle layoutRef={channelsLayoutRef} />
160-
<WithComponents overrides={{ TypingIndicator }}>
196+
<WithComponents overrides={{ TypingIndicator, HeaderStartContent }}>
161197
<Channel>
162198
<ResponsiveChannelPanels />
163199
</Channel>

0 commit comments

Comments
 (0)