hooks#useResolved JavaScript Examples
The following examples show how to use
hooks#useResolved.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.jsx From react-chatengine-demo with MIT License | 6 votes |
App = () => {
const history = useHistory();
const { authUser } = useAuth();
const authResolved = useResolved(authUser);
// If the user is logged in it will prevent the
// user from seeing the login/signup screens
// by always redirecting to chat on auth change.
useEffect(() => {
if (authResolved) {
history.push(!!authUser ? '/' : '/login');
}
}, [authResolved, authUser, history]);
return authResolved ? (
<ChatProvider authUser={authUser}>
<div className="app">
<Switch>
<Route path="/" exact component={Chat} />
<Route path="/login" component={Login} />
<Route path="/signup" component={Signup} />
</Switch>
</div>
</ChatProvider>
) : (
<>Loading...</>
);
}
Example #2
Source File: LeftRail.jsx From react-chatengine-demo with MIT License | 6 votes |
LeftRail = () => {
const { myChats, createChatClick } = useChat();
const chatsResolved = useResolved(myChats);
return (
<div className="left-rail">
<RailHeader />
{chatsResolved ? (
<>
{!!myChats.length ? (
<div className="chat-list-container">
<ChatList />
</div>
) : (
<div className="chat-list-container no-chats-yet">
<h3>No Chats Yet</h3>
</div>
)}
<button className="create-chat-button" onClick={createChatClick}>
Create Chat
</button>
</>
) : (
<div className="chats-loading">
<Loader active size="huge" />
</div>
)}
</div>
);
}
Example #3
Source File: RailHeader.jsx From react-chatengine-demo with MIT License | 4 votes |
RailHeader = () => {
const { chatConfig } = useChat();
const configResolved = useResolved(chatConfig);
const inputRef = useRef(null);
const [image, setImage] = useState();
const onFileAttach = file => {
setImage(file);
};
return (
<>
<input
type="file"
ref={inputRef}
className="file-input"
accept="image/jpeg,image/png"
onChange={e => {
const file = e.target?.files?.[0];
if (file) {
onFileAttach(file);
}
}}
/>
{!!image && (
<ImageUpload
crop
file={image}
header="Set Your Avatar"
mode="message"
onSubmit={croppedImage => {
const storageRef = fb.storage.ref();
const uploadRef = storageRef.child(
`${chatConfig.userSecret}_avatar.jpg`,
);
uploadRef.put(croppedImage).then(() => {
uploadRef.getDownloadURL().then(url => {
fb.firestore
.collection('chatUsers')
.doc(chatConfig.userSecret)
.update({ avatar: url })
.then(() => {
setImage(null);
});
});
});
}}
close={() => setImage(null)}
/>
)}
<div className="left-rail-header">
<Icon
onClick={() => fb.auth.signOut()}
className="sign-out"
name="sign out"
/>
{configResolved && !!chatConfig ? (
<div className="current-user-info">
<IconGroup
onClick={() => {
const input = inputRef.current;
if (input) {
input.value = '';
input.click();
}
}}
className="user-avatar"
size="large"
>
{chatConfig.avatar ? (
<Image src={chatConfig.avatar} avatar />
) : (
<div className="empty-avatar">
{chatConfig.userName[0].toUpperCase()}
</div>
)}
<Icon corner name="camera" inverted circular />
</IconGroup>
<div className="current-username">@{chatConfig.userName}</div>
</div>
) : (
<div className="user-loading">
<Loader active size="small" />
</div>
)}
</div>
</>
);
}