Skip to content

Commit 5d4bd81

Browse files
Baseline styling
1 parent 5af7da8 commit 5d4bd81

File tree

6 files changed

+221
-184
lines changed

6 files changed

+221
-184
lines changed

examples/vite/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12+
"human-id": "^4.1.3",
1213
"react": "link:../../node_modules/react",
1314
"react-dom": "link:../../node_modules/react-dom",
1415
"stream-chat-react": "link:../../"
@@ -26,7 +27,7 @@
2627
"eslint-plugin-react-refresh": "^0.4.6",
2728
"sass": "^1.75.0",
2829
"typescript": "^5.4.5",
29-
"vite": "^7.2.2",
30+
"vite": "^7.3.0",
3031
"vite-plugin-babel": "^1.3.2"
3132
}
3233
}

examples/vite/src/App.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,15 @@ import {
2424
import { createTextComposerEmojiMiddleware, EmojiPicker } from 'stream-chat-react/emojis';
2525
import { init, SearchIndex } from 'emoji-mart';
2626
import data from '@emoji-mart/data';
27+
import { humanId } from 'human-id';
2728

2829
init({ data });
2930

30-
const params = new Proxy(new URLSearchParams(window.location.search), {
31-
get: (searchParams, property) => searchParams.get(property as string),
32-
}) as unknown as Record<string, string | null>;
31+
const apiKey = import.meta.env.VITE_STREAM_API_KEY;
3332

34-
const parseUserIdFromToken = (token: string) => {
35-
const [, payload] = token.split('.');
36-
37-
if (!payload) throw new Error('Token is missing');
38-
39-
return JSON.parse(atob(payload))?.user_id;
40-
};
41-
42-
const apiKey = params.key ?? (import.meta.env.VITE_STREAM_API_KEY as string);
33+
if (!apiKey) {
34+
throw new Error('VITE_STREAM_API_KEY is not defined');
35+
}
4336

4437
const options: ChannelOptions = { limit: 5, presence: true, state: true };
4538
const sort: ChannelSort = { pinned_at: 1, last_message_at: -1, updated_at: -1 };
@@ -50,22 +43,24 @@ const isMessageAIGenerated = (message: LocalMessage) => !!message?.ai_generated;
5043
const useUser = () => {
5144
const userId = useMemo(() => {
5245
return (
53-
new URLSearchParams(window.location.search).get('userId') ||
54-
localStorage.getItem('userId') ||
55-
`user-${crypto.randomUUID().slice(0, 8)}`
46+
new URLSearchParams(window.location.search).get('user_id') ||
47+
localStorage.getItem('user_id') ||
48+
humanId({ separator: '_', capitalize: false })
5649
);
5750
}, []);
5851

5952
useEffect(() => {
60-
const storedUserId = localStorage.getItem('userId');
53+
const storedUserId = localStorage.getItem('user_id');
6154

6255
if (userId && storedUserId === userId) return;
6356

64-
localStorage.setItem('userId', userId);
57+
localStorage.setItem('user_id', userId);
6558
}, [userId]);
6659

6760
const tokenProvider = useCallback(() => {
68-
return fetch(`https://pronto.getstream.io/api/auth/create-token?user_id=${userId}`)
61+
return fetch(
62+
`https://pronto.getstream.io/api/auth/create-token?environment=shared-chat-redesign&user_id=${userId}`,
63+
)
6964
.then((response) => response.json())
7065
.then((data) => data.token as string);
7166
}, [userId]);

examples/vite/src/index.scss

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,45 @@ body {
1919
}
2020

2121
@layer stream-overrides {
22-
.str-chat__channel-list {
22+
.str-chat {
23+
--max-content-width: 800px;
24+
}
25+
26+
.str-chat__channel-list, .str-chat__thread-list-container {
2327
flex-basis: 350px;
24-
flex-shrink: 1;
28+
flex-shrink: 0;
2529
}
2630

2731
.str-chat__channel {
28-
flex-grow: 1;
32+
width: 100%;
33+
}
34+
35+
.str-chat__main-panel, .str-chat__thread-container {
36+
align-items: center;
37+
}
38+
.str-chat__main-panel-inner {
39+
width: 100%;
2940
}
3041

3142
.str-chat__message-list-scroll {
32-
max-width: 800px;
43+
max-width: var(--max-content-width);
44+
width: 100%;
45+
}
46+
47+
.str-chat__channel-header, .str-chat__thread-header {
48+
max-width: var(--max-content-width);
3349
width: 100%;
3450
}
3551

36-
.str-chat__list {
52+
.str-chat__message-input {
53+
max-width: var(--max-content-width);
54+
// scrollbar-gutter: stable;
55+
// scrollbar-width: thin;
56+
// overflow-y: hidden;
57+
// flex-shrink: 0;
58+
}
59+
60+
.str-chat__list, .str-chat__virtual-list {
3761
display: flex;
3862
justify-content: center;
3963
scrollbar-gutter: stable;

examples/vite/src/vite-env.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
/// <reference types="vite/client" />
1+
interface ImportMetaEnv {
2+
readonly VITE_STREAM_API_KEY?: string;
3+
}
4+
5+
interface ImportMeta {
6+
readonly env: ImportMetaEnv;
7+
}

examples/vite/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig, loadEnv, type PluginOption } from 'vite';
1+
import { defineConfig, loadEnv } from 'vite';
22
import babel from 'vite-plugin-babel';
33
import react from '@vitejs/plugin-react';
44

0 commit comments

Comments
 (0)