generated from digitallyinduced/thin-typescript-react-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.tsx
49 lines (41 loc) · 1.92 KB
/
app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React, { useState, useEffect } from 'react';
import * as ReactDOM from 'react-dom'
import { query, initIHPBackend, DataSubscription, createRecord, updateRecord, deleteRecord, createRecords } from 'ihp-datasync';
import { useQuery } from 'ihp-datasync/react';
import { ensureIsUser, useCurrentUser, logout, getCurrentUserId } from 'ihp-backend';
function App() {
// With `useQuery()` you can access your database:
//
// const todos = useQuery(query('todos').orderBy('createdAt'));
//
return <div className="container">
<AppNavbar/>
</div>
}
function AppNavbar() {
// Use the `useCurrentUser()` react hook to access the current logged in user
const user = useCurrentUser();
// This navbar requires bootstrap js helpers for the dropdown
// If the dropdown is not working, you like removed the bootstrap JS from your index.html
return <nav className="navbar navbar-expand-lg navbar-light bg-light mb-5">
<div className="collapse navbar-collapse" id="navbarSupportedContent">
<ul className="navbar-nav ml-auto">
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{user?.email}
</a>
<div className="dropdown-menu" aria-labelledby="navbarDropdown">
<a className="dropdown-item" href="#" onClick={() => logout()}>Logout</a>
</div>
</li>
</ul>
</div>
</nav>
}
// This needs to be run before any calls to `query`, `createRecord`, etc.
initIHPBackend({ host: process.env.BACKEND_URL });
// Redirects to the login page if not logged in already
ensureIsUser().then(() => {
// Start the React app
ReactDOM.render(<App/>, document.getElementById('app'));
});