Commit 48ddbc9a authored by Giovanni's avatar Giovanni

the one with wikis!

parent 65f12c41
Pipeline #57184978 passed with stage
in 1 minute and 14 seconds
......@@ -101,8 +101,8 @@ android {
applicationId "com.puskin.glasnost"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 128
versionName "1.2.8"
versionCode 129
versionName "1.2.9"
ndk {
abiFilters 'armeabi-v7a', 'x86'
......
{
"name": "Glasnost",
"version": "1.2.8",
"version": "1.2.9",
"license": "GPL-3.0",
"scripts": {
"clearCache": "rm -fr $TMPDIR/react-* /tmp/metro-cache-* /tmp/haste-map-metro-3-*",
......@@ -12,12 +12,9 @@
"fix": "eslint --fix src"
},
"dependencies": {
"api": "file:src/node_modules/api",
"axios": "^0.18.0",
"axios-extensions": "^3.0.5",
"babel-plugin-module-resolver": "^3.2.0",
"elements": "file:src/node_modules/elements",
"headerFooter": "file:src/node_modules/headerFooter",
"lodash": "^4.17.11",
"moment": "^2.24.0",
"momentjs": "^2.0.0",
......@@ -30,12 +27,9 @@
"react-native-side-menu": "^1.1.3",
"react-native-syntax-highlighter": "^2.0.0",
"react-native-vector-icons": "^6.4.2",
"react-redux": "^7.0.1",
"react-redux": "^7.0.2",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"router": "file:src/node_modules/router",
"store": "file:src/node_modules/store",
"utils": "file:src/node_modules/utils"
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "^7.4.3",
......@@ -46,7 +40,7 @@
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4"
}
......
......@@ -14,3 +14,5 @@ export * from './branches';
export * from './commits';
export * from './todos';
export * from './pipelines';
export * from './wikis';
export * from './wiki';
......@@ -61,6 +61,9 @@ function FooterComponent({repository = {}, mrs, branches, navigate}) {
<IconWithCounter route={'FileList'}>
<Icon name={'folder-o'} size={30} onPress={() => navigate('FileList')}/>
</IconWithCounter>
<IconWithCounter route={'Wikis'}>
<Icon name={'book'} size={30} onPress={() => navigate('Wikis')}/>
</IconWithCounter>
</View>
);
}
......
import {View} from 'react-native';
import React, {Component} from 'react';
import {connect} from 'react-redux';
import _ from 'lodash';
import {registerRoute} from 'router';
import {
EmptyData,
FormattedText, Markdown,
ScrollableAppContainer
} from 'elements';
import {getGitlabUrl} from 'utils';
import {getWiki} from './selectors';
import {requestWiki} from './actions';
import {getRepository} from '../repository/selectors';
class WikiComponent extends Component {
componentDidMount() {
const {wikiSlug, requestWiki} = this.props;
requestWiki(wikiSlug);
}
render() {
const {wikiSlug, requestWiki, wiki, gitlabUrl, repo} = this.props;
if (_.isEmpty(wiki)) {
return <EmptyData/>;
}
const baseUrl = `${gitlabUrl}/${repo.path_with_namespace}`;
return (
<ScrollableAppContainer style={{flexDirection: 'column'}} refresh={() => requestWiki(wikiSlug)}>
<View style={{marginBottom: 20}}>
<FormattedText style={{textAlign: 'center', fontSize: 20, fontWeight: 'bold'}}>{wiki.title}</FormattedText>
<FormattedText style={{textAlign: 'center', fontSize: 14, fontStyle: 'italic'}}>{wiki.slug}</FormattedText>
</View>
<Markdown baseUrl={baseUrl} text={wiki.content}/>
</ScrollableAppContainer>
);
}
}
const Wiki = connect(state => ({
wiki: getWiki(state),
gitlabUrl: getGitlabUrl(state),
repo: getRepository(state)
}), {requestWiki})(WikiComponent);
registerRoute({Wiki});
import _ from 'lodash';
import {get} from 'api';
import {getRepository} from '../repository/selectors';
export function requestWiki(slug) {
return async (dispatch, getState) => {
const repo = getRepository(getState());
if (_.isEmpty(repo)) {
return;
}
const {data} = await get({path: `projects/${repo.id}/wikis/${slug}`});
if (data) {
dispatch({type: 'WIKI_RECEIVED', data});
}
};
}
export * from './Wiki';
export * from './reducers';
import {registerReducer} from 'store';
function wiki() {
return {
WIKI_RECEIVED: (state, {data}) => ({...state, wiki: data})
};
}
registerReducer('wiki', wiki());
import _ from 'lodash';
export const getWiki = state => _.get(state, ['wiki', 'wiki']);
import {FlatList, TextInput, View} from 'react-native';
import React, {Component} from 'react';
import {connect} from 'react-redux';
import _ from 'lodash';
import {setFooter, setHeaderLeftButton, setHeaderRightButton} from 'headerFooter';
import {navigate, getPreviousRouteName, registerRoute} from 'router';
import {
Icon,
mainInputStyle,
ItemList,
FormattedText,
ScrollableAppContainer, EmptyData, LoadMore
} from 'elements';
import {setPagination, shouldKeepRepoFooter} from 'utils';
import {getWikis} from './selectors';
import {clearWikis, requestWikis} from './actions';
import {Footer} from '../repository/Footer';
class WikisComponent extends Component {
constructor() {
super();
this.state = {searchText: '', isSearchVisible: false, filteredData: []};
}
componentDidMount() {
const {requestWikis, setHeaderRightButton, setHeaderLeftButton, setFooter} = this.props;
requestWikis();
setHeaderRightButton(this.headerRightButton());
setHeaderLeftButton(this.headerLeftButton());
setFooter(this.footer());
}
headerRightButton() {
return <Icon name={'search'} size={30} onPress={() => this.toggleSearch()}/>;
}
headerLeftButton() {
return <Icon name={'angle-left'} size={25} style={{padding: 5}} onPress={() => this.props.navigate('Repository')}/>;
}
footer() {
const {previousRouteName} = this.props;
return shouldKeepRepoFooter(previousRouteName) ? <Footer/> : null;
}
componentWillUnmount() {
this.props.clearWikis();
this.props.setPagination('wikis', {'x-page': 0});
}
toggleSearch() {
const {isSearchVisible} = this.state;
this.setState({isSearchVisible: !isSearchVisible});
}
filterData(searchText) {
const {wikis} = this.props;
if (!searchText) {
return wikis;
}
const searchRegex = new RegExp(searchText, 'i');
const filteredData = _.filter(wikis, wiki => searchRegex.test(wiki.title));
return filteredData;
}
render() {
const {requestWikis, navigate} = this.props;
const {isSearchVisible, searchText} = this.state;
const wikis = this.filterData(searchText);
return (
<ScrollableAppContainer refresh={() => requestWikis(true)}>
{isSearchVisible && <TextInput
autoFocus={true}
placeholder={'Search'}
style={{...mainInputStyle, marginVertical: 10, marginHorizontal: 10}}
underlineColorAndroid={'transparent'}
value={searchText}
onChangeText={text => this.setState({searchText: text})}/>}
{!_.size(wikis) && <EmptyData/>}
<FlatList
ListFooterComponent={<LoadMore entityName={'wikis'} onPress={() => requestWikis(false)}/>}
keyExtractor={item => item.slug}
data={wikis}
renderItem={({item}) => <SingleWiki wiki={item} navigate={navigate}/>}/>
</ScrollableAppContainer>
);
}
}
function SingleWiki({wiki, navigate}) {
const {title, slug} = wiki;
return (
<ItemList onPress={() => navigate('Wiki', {wikiSlug: encodeURIComponent(slug)})}>
<View style={{flexDirection: 'column'}}>
<FormattedText>{title}</FormattedText>
<FormattedText style={{fontStyle: 'italic', fontSize: 12}}>{slug}</FormattedText>
</View>
</ItemList>
);
}
const Wikis = connect(state => ({wikis: getWikis(state), previousRouteName: getPreviousRouteName(state)}), {
requestWikis,
clearWikis,
setHeaderRightButton,
setHeaderLeftButton,
setFooter,
navigate,
setPagination
})(WikisComponent);
registerRoute({Wikis});
import _ from 'lodash';
import {get} from 'api';
import {getPagination, setPagination} from 'utils';
import {getRepository} from '../repository/selectors';
export function clearWikis() {
return {type: 'CLEAR_WIKIS'};
}
export function requestWikis(page0) {
return async (dispatch, getState) => {
const repo = getRepository(getState());
if (_.isEmpty(repo)) {
return;
}
const {pageToLoad = 0} = getPagination(getState(), 'commits');
const {data, headers} = await get({
page: page0 ? 0 : pageToLoad,
path: `projects/${repo.id}/wikis`,
cached: !page0
});
if (data) {
dispatch({type: 'WIKIS_RECEIVED', data});
dispatch(setPagination('wikis', headers));
}
};
}
export * from './Wikis';
export * from './reducers';
import {registerReducer} from 'store';
import _ from 'lodash';
function wikis() {
return {
WIKIS_RECEIVED: (state, {data}) => ({...state, wikis: _.uniqBy([...(state.wikis || []), ...data], 'slug')}),
SET_WIKIS_PAGINATION: (state, {pagination}) => ({...state, pagination}),
CLEAR_WIKIS: state => ({...state, wikis: []})
};
}
registerReducer('wikis', wikis());
import _ from 'lodash';
export const getWikis = state => _.get(state, ['wikis', 'wikis']);
......@@ -2250,27 +2250,28 @@ eslint-import-resolver-node@^0.3.2:
debug "^2.6.9"
resolve "^1.5.0"
eslint-module-utils@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.3.0.tgz#546178dab5e046c8b562bbb50705e2456d7bda49"
eslint-module-utils@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.4.0.tgz#8b93499e9b00eab80ccb6614e69f03678e84e09a"
dependencies:
debug "^2.6.8"
pkg-dir "^2.0.0"
eslint-plugin-import@^2.16.0:
version "2.16.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.16.0.tgz#97ac3e75d0791c4fac0e15ef388510217be7f66f"
eslint-plugin-import@^2.17.2:
version "2.17.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.17.2.tgz#d227d5c6dc67eca71eb590d2bb62fb38d86e9fcb"
dependencies:
array-includes "^3.0.3"
contains-path "^0.1.0"
debug "^2.6.9"
doctrine "1.5.0"
eslint-import-resolver-node "^0.3.2"
eslint-module-utils "^2.3.0"
eslint-module-utils "^2.4.0"
has "^1.0.3"
lodash "^4.17.11"
minimatch "^3.0.4"
read-pkg-up "^2.0.0"
resolve "^1.9.0"
resolve "^1.10.0"
eslint-plugin-jsx-a11y@^6.2.1:
version "6.2.1"
......@@ -4686,9 +4687,9 @@ react-proxy@^1.1.7:
lodash "^4.6.1"
react-deep-force-update "^1.0.0"
react-redux@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.0.1.tgz#321285e6c85c3586d11cc066ab33dc580da599fb"
react-redux@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.0.2.tgz#34b280a3482aaf60e7d4a504b1295165cbe6b86a"
dependencies:
"@babel/runtime" "^7.4.3"
hoist-non-react-statics "^3.3.0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment