Skip to content

Commit 5534033

Browse files
Initial token
1 parent f5b2a5c commit 5534033

File tree

4 files changed

+99
-164
lines changed

4 files changed

+99
-164
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,39 @@ jobs:
3535
3636
- name: 🧪 Validate CommonJS bundle with Node ${{ env.NODE_VERSION }}
3737
run: yarn validate-cjs
38+
39+
deploy-vite-example:
40+
runs-on: ubuntu-latest
41+
needs:
42+
- tsc
43+
- test
44+
name: Deploy Vite Example to Vercel
45+
env:
46+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
47+
VERCEL_PROJECT_ID: prj_2Rq8kuNd0BmqKd2NwvkDjX9Htnx5
48+
VITE_STREAM_API_KEY: ${{ vars.VITE_EXAMPLE_STREAM_API_KEY }}
49+
NODE_ENV: production
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- uses: ./.github/actions/setup-node
54+
55+
- name: Build SDK
56+
run: yarn build
57+
58+
- name: Vercel Pull/Build/Deploy (Preview)
59+
working-directory: examples/vite
60+
61+
if: ${{ github.ref_name != 'master' }}
62+
run: >
63+
npx vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} &&
64+
npx vercel build &&
65+
npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
66+
67+
- name: Vercel Pull/Build/Deploy (Production)
68+
working-directory: examples/vite
69+
if: ${{ github.ref_name == 'master' }}
70+
run: >
71+
npx vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} &&
72+
npx vercel build --prod &&
73+
npx vercel deploy --prod --prebuilt --token=${{ secrets.VERCEL_TOKEN }}

.releaserc.json

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
{
22
"branches": [
3-
{
4-
"name": "rc",
5-
"channel": "rc",
6-
"prerelease": "rc"
7-
},
83
{
94
"name": "master",
10-
"channel": "latest"
11-
},
12-
{
13-
"name": "release-v12",
14-
"channel": "latest"
15-
},
16-
{
17-
"name": "release-v11",
18-
"channel": "v11",
19-
"range": "11.x"
20-
},
21-
{
22-
"name": "release-v10",
23-
"channel": "v10",
24-
"range": "10.x"
25-
},
26-
{
27-
"name": "release-v9",
28-
"channel": "v9",
29-
"range": "9.x"
5+
"channel": "canary",
6+
"prerelease": "canary"
307
}
318
],
329
"plugins": [

examples/vite/src/App.tsx

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react';
1+
import { useCallback, useEffect, useMemo } from 'react';
22
import {
33
ChannelFilters,
44
ChannelOptions,
@@ -39,28 +39,58 @@ const parseUserIdFromToken = (token: string) => {
3939
return JSON.parse(atob(payload))?.user_id;
4040
};
4141

42-
const apiKey = params.key ?? (import.meta.env.VITE_STREAM_KEY as string);
43-
const userToken = params.ut ?? (import.meta.env.VITE_USER_TOKEN as string);
44-
const userId = parseUserIdFromToken(userToken);
42+
const apiKey = params.key ?? (import.meta.env.VITE_STREAM_API_KEY as string);
4543

46-
const filters: ChannelFilters = {
47-
members: { $in: [userId] },
48-
type: 'messaging',
49-
archived: false,
50-
};
5144
const options: ChannelOptions = { limit: 5, presence: true, state: true };
5245
const sort: ChannelSort = { pinned_at: 1, last_message_at: -1, updated_at: -1 };
5346

5447
// @ts-ignore
5548
const isMessageAIGenerated = (message: LocalMessage) => !!message?.ai_generated;
5649

50+
const useUser = () => {
51+
const userId = useMemo(() => {
52+
return (
53+
new URLSearchParams(window.location.search).get('userId') ||
54+
localStorage.getItem('userId') ||
55+
`user-${crypto.randomUUID().slice(0, 8)}`
56+
);
57+
}, []);
58+
59+
useEffect(() => {
60+
const storedUserId = localStorage.getItem('userId');
61+
62+
if (userId && storedUserId === userId) return;
63+
64+
localStorage.setItem('userId', userId);
65+
}, [userId]);
66+
67+
const tokenProvider = useCallback(() => {
68+
return fetch(`https://pronto.getstream.io/api/auth/create-token?user_id=${userId}`)
69+
.then((response) => response.json())
70+
.then((data) => data.token as string);
71+
}, [userId]);
72+
73+
return { userId: userId, tokenProvider };
74+
};
75+
5776
const App = () => {
77+
const { userId, tokenProvider } = useUser();
78+
5879
const chatClient = useCreateChatClient({
5980
apiKey,
60-
tokenOrProvider: userToken,
81+
tokenOrProvider: tokenProvider,
6182
userData: { id: userId },
6283
});
6384

85+
const filters: ChannelFilters = useMemo(
86+
() => ({
87+
members: { $in: [userId] },
88+
type: 'messaging',
89+
archived: false,
90+
}),
91+
[userId],
92+
);
93+
6494
useEffect(() => {
6595
if (!chatClient) return;
6696

@@ -77,26 +107,6 @@ const App = () => {
77107

78108
if (!chatClient) return <>Loading...</>;
79109

80-
chatClient.axiosInstance.interceptors.response.use(
81-
(response) => {
82-
// Simulate a 500 for specific routes
83-
if (response.config.url?.includes('/delivered')) {
84-
// throw a fake error like a real server would
85-
const error = {
86-
response: {
87-
status: 500,
88-
statusText: 'Internal Server Error',
89-
data: { error: 'Simulated server error' },
90-
config: response.config,
91-
},
92-
};
93-
return Promise.reject(error);
94-
}
95-
96-
return response;
97-
},
98-
(error) => Promise.reject(error),
99-
);
100110
return (
101111
<Chat client={chatClient} isMessageAIGenerated={isMessageAIGenerated}>
102112
<ChatView>

examples/vite/src/index.scss

Lines changed: 21 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,42 @@
1-
body {
2-
margin: 0;
1+
@layer stream, stream-overrides;
2+
3+
@import url('stream-chat-react/dist/css/v2/index.css') layer(stream);
4+
5+
:root {
6+
font-synthesis: none;
7+
text-rendering: optimizeLegibility;
38
-webkit-font-smoothing: antialiased;
49
-moz-osx-font-smoothing: grayscale;
510
}
611

7-
html,
8-
body,
9-
#root {
10-
margin: unset;
11-
padding: unset;
12-
height: 100%;
12+
body {
13+
margin: 0;
1314
}
1415

15-
@layer stream, emoji-replacement;
16-
17-
@import url('stream-chat-react/css/v2/index.css') layer(stream);
18-
// use in combination with useImageFlagEmojisOnWindows prop on Chat component
19-
// @import url('stream-chat-react/css/v2/emoji-replacement.css') layer(emoji-replacement);
20-
2116
#root {
2217
display: flex;
23-
height: 100%;
24-
25-
& > div.str-chat {
26-
height: 100%;
27-
width: 100%;
28-
display: flex;
29-
}
18+
height: 100vh;
19+
}
3020

21+
@layer stream-overrides {
3122
.str-chat__channel-list {
32-
position: fixed;
33-
z-index: 1;
34-
height: 100%;
35-
width: 0;
36-
flex-shrink: 0;
37-
box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);
38-
max-width: 1000px;
39-
40-
&--open {
41-
width: 30%;
42-
position: fixed;
43-
}
44-
transition: width 0.3s ease-out;
23+
flex-basis: 350px;
24+
flex-shrink: 1;
4525
}
4626

4727
.str-chat__channel {
48-
flex: 1;
49-
min-width: 0;
28+
flex-grow: 1;
5029
}
5130

52-
.str-chat__main-panel {
53-
min-width: 0;
54-
flex: 1;
55-
56-
&--thread-open {
57-
display: none;
58-
}
59-
}
60-
61-
.str-chat__thread {
62-
flex: 1;
63-
height: 100%;
64-
position: absolute;
65-
z-index: 1;
31+
.str-chat__message-list-scroll {
32+
max-width: 800px;
33+
width: 100%;
6634
}
6735

68-
.str-chat__channel-header .str-chat__header-hamburger {
69-
width: 30px;
70-
height: 38px;
71-
padding: var(--xxs-p);
72-
margin-right: var(--xs-m);
36+
.str-chat__list {
7337
display: flex;
74-
align-items: center;
7538
justify-content: center;
76-
cursor: pointer;
77-
border: none;
78-
background: transparent;
79-
80-
&:hover {
81-
svg path {
82-
fill: var(--primary-color);
83-
}
84-
}
85-
}
86-
87-
@media screen and (min-width: 768px) {
88-
.str-chat__channel-list {
89-
width: 30%;
90-
position: initial;
91-
z-index: 0;
92-
}
93-
94-
.str-chat__chat-view__channels {
95-
.str-chat__thread {
96-
position: initial;
97-
z-index: 0;
98-
}
99-
}
100-
101-
.str-chat__channel-header .str-chat__header-hamburger {
102-
display: none;
103-
}
104-
}
105-
106-
@media screen and (min-width: 1024px) {
107-
.str-chat__main-panel {
108-
min-width: 0;
109-
110-
&--thread-open {
111-
max-width: 55%;
112-
display: flex;
113-
}
114-
}
115-
116-
.str-chat__chat-view__channels {
117-
.str-chat__thread {
118-
max-width: 45%;
119-
}
120-
}
121-
122-
.str-chat__channel-header .str-chat__header-hamburger {
123-
display: none;
124-
}
125-
}
126-
127-
.str-chat__thread-list-container {
128-
max-width: 350px;
39+
scrollbar-gutter: stable;
40+
scrollbar-width: thin;
12941
}
13042
}

0 commit comments

Comments
 (0)