Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 934a8c1

Browse files
author
Jeff Moore
committed
Releasing v0.11.0
1 parent 66ccbcd commit 934a8c1

File tree

209 files changed

+16815
-4051
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+16815
-4051
lines changed

.storybook/main.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
stories: ["../src/**/*.stories.@(tsx|mdx)"],
3+
addons: [
4+
"@storybook/preset-create-react-app",
5+
"@storybook/addon-docs",
6+
"@storybook/addon-controls"
7+
],
8+
typescript: {
9+
reactDocgenTypescriptOptions: {
10+
shouldExtractLiteralValuesFromEnum: true,
11+
shouldRemoveUndefinedFromOptional: true,
12+
propFilter: prop => {
13+
/**
14+
* This influences auto-generation of prop tables in the Docs pages
15+
* In this case I'm omitting props extended from node_modules packages,
16+
* and internal ones without the decscription doc-comment for cleaner look
17+
* Storybook v6 is required for this to work
18+
*/
19+
if (prop.parent && /node_modules/.test(prop.parent.fileName))
20+
return false;
21+
if (!prop.description) return false;
22+
return true;
23+
}
24+
}
25+
}
26+
};

.storybook/preview-head.html

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<style>
2+
body {
3+
margin: 0;
4+
}
5+
6+
#root {
7+
align-items: center;
8+
background: #ddd;
9+
display: flex;
10+
height: 100vh;
11+
justify-content: center;
12+
}
13+
14+
.preview-box {
15+
border: 1px solid #bbb;
16+
height: 200px;
17+
width: 400px;
18+
line-height: 1.5;
19+
text-align: justify;
20+
}
21+
</style>
22+
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet" />

.storybook/preview.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React, { useEffect } from "react";
2+
import { ThemeProvider } from "styled-components";
3+
import { appTheme } from "main/Theme";
4+
import GlobalStyles from "main/styles/GlobalStyles";
5+
import Normalize from "main/styles/Normalize";
6+
7+
const App = storyFn => {
8+
return (
9+
<ThemeProvider theme={appTheme}>
10+
<Normalize />
11+
<GlobalStyles />
12+
{storyFn()}
13+
</ThemeProvider>
14+
);
15+
};
16+
17+
export const decorators = [App];
18+
19+
export const parameters = {
20+
options: {
21+
storySort: {
22+
order: [
23+
"About",
24+
"Chat Components",
25+
"Basic Presentation",
26+
"Basic Layout",
27+
"Style Utilities"
28+
]
29+
}
30+
}
31+
};
32+
33+
/* Uncomment in case Redux state is ever needed
34+
35+
import { Provider, useSelector } from "react-redux";
36+
import Pubnub from "pubnub";
37+
import { PubNubProvider } from "pubnub-react";
38+
import { createPubNubListener } from "pubnub-redux";
39+
import keyConfiguration from "config/pubnub-keys.json";
40+
import KnownIds from "config/knownUserIds.json";
41+
import { createAppStore } from "main/store";
42+
import { isUserLoggedIn } from "features/authentication/authenticationModel";
43+
import { useDispatch } from "main/useDispatch";
44+
import { login } from "features/authentication/loginCommand";
45+
import { createTypingIndicatorsListener } from "features/typingIndicator/typingIndicatorModel";
46+
47+
48+
const AppWithPubnub = props => {
49+
const pubnub = new Pubnub(keyConfiguration);
50+
const store = createAppStore({
51+
pubnub: {
52+
api: pubnub
53+
}
54+
});
55+
56+
useEffect(() => {
57+
pubnub.addListener(createPubNubListener(store.dispatch));
58+
pubnub.addListener(createTypingIndicatorsListener(store.dispatch));
59+
}, []);
60+
61+
useEffect(() => {
62+
window.addEventListener("beforeunload", pubnub.unsubscribeAll);
63+
}, []);
64+
65+
return (
66+
<ThemeProvider theme={appTheme}>
67+
<Provider store={store}>
68+
<PubNubProvider client={pubnub}>
69+
<Normalize />
70+
<GlobalStyles />
71+
{props.children}
72+
</PubNubProvider>
73+
</Provider>
74+
</ThemeProvider>
75+
);
76+
};
77+
78+
const Authorized = props => {
79+
if (useSelector(isUserLoggedIn)) return props.children;
80+
81+
const dispatch = useDispatch();
82+
const randomUserId = KnownIds[Math.floor(Math.random() * KnownIds.length)];
83+
dispatch(login(randomUserId));
84+
return null;
85+
};
86+
87+
const AppWithPubnubDecorator = storyFn => (
88+
<App>
89+
<Authorized>{storyFn()}</Authorized>
90+
</App>
91+
);
92+
93+
addDecorator(AppWithPubnubDecorator);
94+
95+
*/

docs/run-locally.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ Follow the instructions below to run the app in your local environment.
1515

1616
1. Clone the GitHub repository.
1717

18-
```bash
19-
git clone https://github.com/pubnub/typescript-ref-app-team-chat-private.git
20-
```
18+
```bash
19+
git clone https://github.com/pubnub/typescript-ref-app-team-chat.git
20+
```
2121

2222
1. Install the project.
2323

24-
```bash
25-
cd typescript-ref-app-team-chat
26-
npm install
27-
```
24+
```bash
25+
cd typescript-ref-app-team-chat
26+
npm install
27+
```
2828

2929
1. Start the project. You'll be asked to enter your chat app keys from the PubNub Dashboard. Note that Objects should be enabled and a region should be selected on the key.
3030

31-
```bash
32-
npm start
33-
```
31+
```bash
32+
npm start
33+
```
3434

35-
A web browser should automatically open [http://localhost:3000](http://localhost:3000), and you can explore your very own Team Chat app!
35+
A web browser should automatically open [http://localhost:3000](http://localhost:3000), and you can explore your very own Team Chat app!

docs/tutorial/login.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ title: Log in with a User
44
sidebar_label: Login
55
---
66

7-
While the splash screen displays, the app is selecting a user for you, and retrieving the conversations to which your user is subscribed.
7+
While the splash screen displays, the app is selecting a user for you, and retrieving the conversations to which your user is subscribed.
88

99
![splash screen](assets/team-chat-loading-screen.png)
1010

1111
## Select a User
1212

13-
The `authentication/login/Login.tsx` component displays a login screen and selects a random user to log into the application.
14-
The user is selected from the list of IDs defined in the `knownUserIds.json` file.
13+
The `authentication/login/Login.tsx` component displays a login screen and selects a random user to log into the application.
14+
The user is selected from the list of IDs defined in the `knownUserIds.json` file.
1515
These are the same users that were initially populated on your key.
1616

1717
```tsx
@@ -48,10 +48,10 @@ export { Login };
4848

4949
## Set the User
5050

51-
Once the app selects a user, the following code (in `authentication/loginCommand.ts`) calls [pubnub.api.setUUID()](https://www.pubnub.com/docs/chat/reference/users#set-a-user) to set the user’s ID on the pubnub object.
52-
This ID will be passed in all API calls to PubNub so that the network can identify the user who performs these operations.
51+
Once the app selects a user, the following code (in `authentication/loginCommand.ts`) calls [pubnub.api.setUUID()](https://www.pubnub.com/docs/chat/reference/users#set-a-user) to set the user’s ID on the pubnub object.
52+
This ID will be passed in all API calls to PubNub so that the network can identify the user who performs these operations.
5353

54-
We then call the [fetchUserById()](https://www.pubnub.com/docs/chat/redux/users#fetchuserbyid) command to fetch user details from PubNub and store the logged in user in the local store.
54+
We then call the [fetchUserData()](https://www.pubnub.com/docs/chat/redux/users#fetchuserdata) command to fetch user details from PubNub and store the logged in user in the local store.
5555

5656
```tsx
5757
export const login = (userId: string): ThunkAction<Promise<void>> => {
@@ -62,22 +62,22 @@ export const login = (userId: string): ThunkAction<Promise<void>> => {
6262
// Set the UUID of the current user
6363
context.pubnub.api.setUUID(userId);
6464
// Fetch user from PubNub
65-
const isLoginSuccessful = dispatch(fetchUserById({ userId }))
65+
const isLoginSuccessful = dispatch(fetchUserData({ userId }))
6666
});
6767
```
6868
6969
## Connect To Conversations
7070
71-
Once the login is successful, we call the [fetchMemberships()](https://www.pubnub.com/docs/chat/redux/memberships#fetchmemberships) command to retrieve the user’s conversations from PubNub.
71+
Once the login is successful, we call the [fetchMemberships()](https://www.pubnub.com/docs/chat/redux/memberships#fetchmemberships) command to retrieve the user’s conversations from PubNub.
7272
The method returns a list of space memberships that were initially populated by the `setup/populate.js` script and stores these conversations in the local store.
7373
74-
Next, we call [pubnub.api.subscribe()](https://www.pubnub.com/docs/chat/reference/spaces#subscribe-to-channels) to open a realtime connection with PubNub and subscribe the user to the conversation channels.
74+
Next, we call [pubnub.api.subscribe()](https://www.pubnub.com/docs/chat/reference/spaces#subscribe-to-channels) to open a realtime connection with PubNub and subscribe the user to the conversation channels.
7575
If a client is subscribed to one or more channels, it will start receiving the messages and events published on those channels.
76-
Subscribing with presence also subscribes you to presence channels so you can receive join and leave events, which allow you to show other users as online or offline on the app.
76+
Subscribing with presence also subscribes you to presence channels so you can receive join and leave events, which allow you to show other users as online or offline on the app.
7777
(We’ll dive into detail on presence in the next part of the tutorial.)
7878
7979
```tsx
80-
const isLoginSuccessful = dispatch(fetchUserById({ userId }))
80+
const isLoginSuccessful = dispatch(fetchUserData({ userId }))
8181
.then(() => {
8282
return dispatch(
8383
// Fetch the user’s conversations from PubNub
@@ -104,4 +104,4 @@ const isLoginSuccessful = dispatch(fetchUserById({ userId }))
104104
withPresence: true
105105
});
106106
});
107-
```
107+
```

0 commit comments

Comments
 (0)