Skip to content

Commit 9459a3c

Browse files
authored
Merge pull request #124 from unfoldingWord/bugfix-klappy-issue-123
Bugfix klappy issue 123
2 parents 11c466d + 5a22fe3 commit 9459a3c

17 files changed

+1200
-490
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitea-react-toolkit",
3-
"version": "2.0.2-rc.13",
3+
"version": "2.1.0-beta",
44
"license": "MIT",
55
"description": "A Gitea API React Toolkit Component Library",
66
"homepage": "https://gitea-react-toolkit.netlify.com/",
@@ -15,6 +15,7 @@
1515
"axios-cache-adapter": "2.4.1",
1616
"base-64": "0.1.0",
1717
"deep-equal": "^2.0.5",
18+
"js-base64": "^3.7.2",
1819
"jszip": "^3.5.0",
1920
"localforage": "1.7.3",
2021
"markdown-translatable": "1.3.1-rc.1",
@@ -86,7 +87,7 @@
8687
"react-docgen-typescript": "^1.16.2",
8788
"react-dom": "16.11.0",
8889
"react-scripts": "^3.4.0",
89-
"react-styleguidist": "^10.6.2",
90+
"react-styleguidist": "^11.1.7",
9091
"source-map-support": "0.5.16",
9192
"start-server-and-test": "1.10.6",
9293
"style-loader": "^1.0.0",

src/components/application-bar/ApplicationBar.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ import {
1010

1111
import { useStyles } from './useStyles';
1212
import {
13-
UserMenu, DrawerMenu, RepositoryMenu, FileContext,
13+
UserMenu, DrawerMenu, RepositoryMenu,
1414
} from '..';
1515

1616
function ApplicationBar({
1717
title,
1818
build,
1919
buttons,
20+
filepath,
2021
drawerMenu,
2122
drawerMenuProps,
2223
hideRepositoryMenu,
24+
auth,
25+
repo,
26+
file,
2327
}) {
2428
const classes = useStyles();
25-
const { state: file } = useContext(FileContext)
2629

2730
return (
2831
<div className={classes.root}>
@@ -31,7 +34,7 @@ function ApplicationBar({
3134
className={classes.appBar}>
3235
<Toolbar data-test="application-bar">
3336
<div className={classes.menuButton}>
34-
<DrawerMenu {...drawerMenuProps}>
37+
<DrawerMenu {...drawerMenuProps} file={file}>
3538
{drawerMenu}
3639
</DrawerMenu>
3740
</div>
@@ -40,12 +43,12 @@ function ApplicationBar({
4043
{build && <Typography variant="caption" color="inherit" > build {build}</Typography>}
4144
</Typography>
4245
<Typography variant="subtitle2" color="inherit" className={classes.grow} noWrap>
43-
{file ? file.filepath : ''}
46+
{filepath || ''}
4447
</Typography>
4548
<div className={classes.grow} />
4649
{buttons}
47-
{!hideRepositoryMenu ? <RepositoryMenu /> : null}
48-
<UserMenu />
50+
{!hideRepositoryMenu ? <RepositoryMenu repo={repo} /> : null}
51+
<UserMenu auth={auth} />
4952
</Toolbar>
5053
</AppBar>
5154
</div>

src/components/application-bar/ApplicationBar.md

+79
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,79 @@
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
278
import { useContext, useState } from 'react';
379
import {
@@ -16,6 +92,8 @@ import {
1692
} from 'gitea-react-toolkit';
1793

1894
function 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
};

src/components/application-bar/DrawerMenu.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ function DrawerMenu({
1717
children,
1818
hideRepoContents,
1919
closeOnListItemsClick,
20+
file: _file,
2021
}) {
2122
const classes = useStyles();
2223
const [openDrawer, setOpenDrawer] = useState(false);
23-
const { components } = useContext(FileContext) || {};
24+
const { components } = _file || useContext(FileContext) || {};
2425

2526
const toggleDrawer = () => {
2627
setOpenDrawer(!openDrawer);
@@ -29,10 +30,8 @@ function DrawerMenu({
2930
const drawerClasses = { paper: classes.drawerPaper };
3031

3132
const onDrawerItemClick = () => {
32-
if (closeOnListItemsClick) {
33-
toggleDrawer()
34-
}
35-
}
33+
closeOnListItemsClick && toggleDrawer();
34+
};
3635

3736
return (
3837
<div>
@@ -44,7 +43,8 @@ function DrawerMenu({
4443
variant="temporary" anchor="left"
4544
open={openDrawer}
4645
onClose={toggleDrawer}
47-
classes={drawerClasses}>
46+
classes={drawerClasses}
47+
>
4848
<div className={classes.drawerHeader}>
4949
<IconButton data-test="drawer-menu-close-button" onClick={toggleDrawer}>
5050
<ChevronLeft />

src/components/application-bar/DrawerMenu.md

+41
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
# DrawerMenu
2+
3+
## Using Hooks
4+
5+
The `DrawerMenu` component helps display the `drawerMenu` component passed in props via a modal.
6+
7+
```js
8+
import { Paper, List, ListItem, ListItemIcon, ListItemText } from '@material-ui/core';
9+
import { Mail, Inbox } from '@material-ui/icons';
10+
import { DrawerMenu, useRepository, useFile } from 'gitea-react-toolkit';
11+
12+
const config = {
13+
server: "https://bg.door43.org",
14+
tokenid:"PlaygroundTesting",
15+
};
16+
17+
const urls = [
18+
"https://bg.door43.org/api/v1/repos/door43-catalog/en_ta",
19+
"https://bg.door43.org/api/v1/repos/door43-catalog/en_tw",
20+
"https://bg.door43.org/api/v1/repos/door43-catalog/en_tn",
21+
"https://bg.door43.org/api/v1/repos/door43-catalog/en_obs",
22+
];
23+
24+
const [repository, setRepository] = React.useState();
25+
const [filepath, setFilepath] = React.useState();
26+
27+
const repo = useRepository({ config, urls, repository, onRepository: setRepository });
28+
const file = useFile({ config, repository, filepath, onFilepath: setFilepath });
29+
30+
const children = repo.component;
31+
32+
<Paper>
33+
<DrawerMenu file={file}>
34+
{children}
35+
</DrawerMenu>
36+
</Paper>
37+
```
38+
39+
## Using Contexts
40+
141
The `DrawerMenu` component helps display the `drawerMenu` component passed in props via a modal.
242

343
```js
@@ -33,3 +73,4 @@ const children = (
3373
</RepositoryContextProvider>
3474
</AuthenticationContextProvider>
3575
</Paper>
76+
```

src/components/application-bar/RepositoryMenu.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ import CancelIcon from '@material-ui/icons/Cancel';
1616
import { useStyles } from './useStyles';
1717
import { RepositoryContext, FileContext } from '..';
1818

19-
function RepositoryMenu() {
19+
function RepositoryMenu({
20+
repo,
21+
file: _file,
22+
}) {
2023
const classes = useStyles();
2124
const [modal, setModal] = useState(false);
22-
const {
23-
state: repository,
24-
actions,
25-
component: repositoryComponent,
26-
} = useContext(RepositoryContext) || {};
27-
28-
const { state: file, stateValues: fileStateValues, actions: fileActions } = useContext(FileContext) || {};
25+
const { state: repository, actions, component: repositoryComponent } = repo || useContext(RepositoryContext) || {};
26+
const { state: file, stateValues: fileStateValues, actions: fileActions } = _file || useContext(FileContext) || {};
2927

3028
const {
3129
name,

src/components/application-bar/UserMenu.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@ import { AccountCircle } from '@material-ui/icons';
1010
import { useStyles } from './useStyles';
1111
import { AuthenticationContext } from '..';
1212

13-
function UserMenu() {
13+
function UserMenu({ auth }) {
1414
const classes = useStyles();
15-
const { state: authentication, component } = useContext(AuthenticationContext) || {};
15+
const { state: authentication, component } = auth || useContext(AuthenticationContext) || {};
1616
const [modal, setModal] = useState(false);
1717
const closeModal = () => setModal(false);
1818
const openModal = () => setModal(true);
1919

2020
useEffect(() => {
21-
if (authentication && authentication.user) {
22-
closeModal();
23-
}
24-
}, [authentication])
21+
authentication?.user && closeModal();
22+
}, [authentication]);
2523

2624
const avatar = !(authentication && authentication.user) ? <AccountCircle fontSize="large" /> : (
2725
<Avatar data-test="user-menu-avatar" className={classes.avatar} src={authentication.user.avatar_url} />

src/components/file/File.context.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function FileContextProvider({
2525
releaseFlag,
2626
}) {
2727
const { state: contextAuthentication } = useContext(AuthenticationContext);
28-
const { state: contextRepository, config: contextConfig } = useContext(RepositoryContext);
28+
const { state: contextRepository, actions: { updateBranch }, config: contextConfig } = useContext(RepositoryContext);
2929

3030
const {
3131
state, stateValues, actions, component, components, config,
@@ -42,6 +42,7 @@ export function FileContextProvider({
4242
onLoadCache,
4343
onSaveCache,
4444
releaseFlag,
45+
updateBranch,
4546
});
4647

4748
const context = {

src/components/file/helpers.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const ensureFile = async ({
2121
content: defaultContent, message: _message, author,
2222
onOpenValidation,
2323
});
24+
2425
return file;
2526
};
2627

0 commit comments

Comments
 (0)