1+ # Application Bar
2+
3+ ## Using Hooks
4+
5+ ``` js
6+ import { useContext , useState } from ' react' ;
7+ import { IconButton , Badge , List , ListItem , ListItemIcon , ListItemText } from ' @material-ui/core' ;
8+ import { Mail , Notifications , Inbox } from ' @material-ui/icons' ;
9+
10+ import {
11+ useAuthentication ,
12+ useRepository ,
13+ useFile ,
14+ ApplicationBar ,
15+ } from ' gitea-react-toolkit' ;
16+
17+ const config = {
18+ server: " https://bg.door43.org" ,
19+ tokenid: " PlaygroundTesting" ,
20+ };
21+
22+ const urls = [
23+ " https://bg.door43.org/api/v1/repos/door43-catalog/en_ta" ,
24+ " https://bg.door43.org/api/v1/repos/door43-catalog/en_tw" ,
25+ " https://bg.door43.org/api/v1/repos/door43-catalog/en_tn" ,
26+ " https://bg.door43.org/api/v1/repos/door43-catalog/en_obs" ,
27+ ];
28+
29+ function Component () {
30+ const [authentication , setAuthentication ] = useState ();
31+ const [repository , setRepository ] = useState ();
32+ const [filepath , setFilepath ] = useState ();
33+
34+ const auth = useAuthentication ({ config, authentication, onAuthentication: setAuthentication});
35+ const repo = useRepository ({ authentication, repository, config, onRepository: setRepository, urls });
36+ const file = useFile ({ authentication, repository, config, filepath, onFilepath: setFilepath });
37+
38+ const buttons = (
39+ < IconButton color= " inherit" >
40+ < Badge badgeContent= {17 } color= " secondary" >
41+ < Notifications / >
42+ < / Badge>
43+ < / IconButton>
44+ );
45+ const drawerMenu = (
46+ < List>
47+ {[' Inbox' , ' Sent' ].map ((text , index ) => (
48+ < ListItem button key= {text}>
49+ < ListItemIcon style= {{margin: 0 }}>
50+ {index % 2 === 0 ? < Inbox / > : < Mail / > }
51+ < / ListItemIcon>
52+ < ListItemText primary= {text} / >
53+ < / ListItem>
54+ ))}
55+ < / List>
56+ );
57+
58+ return (
59+ < ApplicationBar
60+ title= ' Application Title'
61+ buttons= {buttons}
62+ drawerMenu= {drawerMenu}
63+ auth= {auth}
64+ repo= {repo}
65+ file= {file}
66+ filepath= {filepath}
67+ / >
68+ );
69+ };
70+
71+ < Component / >
72+ ```
73+
74+
75+ ## Using Contexts
76+
177``` js
278import { useContext , useState } from ' react' ;
379import {
@@ -16,6 +92,8 @@ import {
1692} from ' gitea-react-toolkit' ;
1793
1894function Component () {
95+ const { state: file } = useContext (FileContext);
96+
1997 const buttons = (
2098 < IconButton color= " inherit" >
2199 < Badge badgeContent= {17 } color= " secondary" >
@@ -41,6 +119,7 @@ function Component() {
41119 title= ' Application Title'
42120 buttons= {buttons}
43121 drawerMenu= {drawerMenu}
122+ filepath= {file && file .filepath }
44123 / >
45124 );
46125};
0 commit comments