Skip to content

feat(starred-count): show starred count #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@
"contributions": [
"code"
]
},
{
"login": "adrianhartanto0",
"name": "adrianhartanto0",
"avatar_url": "https://avatars1.githubusercontent.com/u/11606323?v=4",
"profile": "https://github.com/adrianhartanto0",
"contributions": [
"code"
]
}
]
}
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
## Introduction

[![Build Status](https://img.shields.io/travis/gitpoint/git-point.svg?style=flat-square)](https://travis-ci.org/gitpoint/git-point)
[![All Contributors](https://img.shields.io/badge/all_contributors-25-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-28-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Gitter chat](https://img.shields.io/badge/chat-on_gitter-008080.svg?style=flat-square)](https://gitter.im/git-point)
Expand Down Expand Up @@ -83,6 +83,5 @@ Please take a look at the [contributing guidelines](./CONTRIBUTING.md) for a det
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars3.githubusercontent.com/u/3055294?v=3" width="100px;"/><br /><sub>Patrick Wang</sub>](https://patw.me)<br />[💻](https://github.com/gitpoint/git-point/commits?author=patw0929 "Code") [🐛](https://github.com/gitpoint/git-point/issues?q=author%3Apatw0929 "Bug reports") | [<img src="https://avatars5.githubusercontent.com/u/627794?v=4" width="100px;"/><br /><sub>Mike Kavouras</sub>](https://github.com/mikekavouras)<br />[💻](https://github.com/gitpoint/git-point/commits?author=mikekavouras "Code") [🐛](https://github.com/gitpoint/git-point/issues?q=author%3Amikekavouras "Bug reports") | [<img src="https://avatars4.githubusercontent.com/u/4848554?v=4" width="100px;"/><br /><sub>Peter Lazar</sub>](https://github.com/peterlazar1993)<br />[💻](https://github.com/gitpoint/git-point/commits?author=peterlazar1993 "Code") | [<img src="https://avatars6.githubusercontent.com/u/5106887?v=4" width="100px;"/><br /><sub>June Domingo</sub>](https://github.com/junedomingo)<br />[💻](https://github.com/gitpoint/git-point/commits?author=junedomingo "Code") [🐛](https://github.com/gitpoint/git-point/issues?q=author%3Ajunedomingo "Bug reports") | [<img src="https://avatars7.githubusercontent.com/u/9287184?v=4" width="100px;"/><br /><sub>Antoine Boisadam</sub>](https://github.com/Antoine38660)<br />[💻](https://github.com/gitpoint/git-point/commits?author=Antoine38660 "Code") [🐛](https://github.com/gitpoint/git-point/issues?q=author%3AAntoine38660 "Bug reports") | [<img src="https://avatars6.githubusercontent.com/u/13142418?v=4" width="100px;"/><br /><sub>Wang Shidong</sub>](https://wsdjeg.github.io)<br />[💻](https://github.com/gitpoint/git-point/commits?author=wsdjeg "Code") | [<img src="https://avatars4.githubusercontent.com/u/2190589?v=4" width="100px;"/><br /><sub>Swapnil Joshi</sub>](http://swapnilmj.users.sourceforge.net/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=swapnilmj "Code") |
| [<img src="https://avatars5.githubusercontent.com/u/408959?v=4" width="100px;"/><br /><sub>Rolf Koenders</sub>](https://github.com/RolfKoenders)<br />[💻](https://github.com/gitpoint/git-point/commits?author=RolfKoenders "Code") [🐛](https://github.com/gitpoint/git-point/issues?q=author%3ARolfKoenders "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/10191084?v=4" width="100px;"/><br /><sub>Andrew Dassonville</sub>](https://andrewda.me)<br />[💻](https://github.com/gitpoint/git-point/commits?author=andrewda "Code") [💬](#question-andrewda "Answering Questions") [🐛](https://github.com/gitpoint/git-point/issues?q=author%3Aandrewda "Bug reports") [👀](#review-andrewda "Reviewed Pull Requests") | [<img src="https://avatars0.githubusercontent.com/u/2076088?v=4" width="100px;"/><br /><sub>Anton</sub>](https://medium.com/@antondomashnev)<br />[💻](https://github.com/gitpoint/git-point/commits?author=Antondomashnev "Code") | [<img src="https://avatars0.githubusercontent.com/u/14795799?v=4" width="100px;"/><br /><sub>Xuezheng Ma</sub>](https://github.com/xuezhma)<br />[💻](https://github.com/gitpoint/git-point/commits?author=xuezhma "Code") | [<img src="https://avatars0.githubusercontent.com/u/8962228?v=4" width="100px;"/><br /><sub>Sammy Israwi</sub>](https://github.com/SammyIsra)<br />[💻](https://github.com/gitpoint/git-point/commits?author=SammyIsra "Code") [🐛](https://github.com/gitpoint/git-point/issues?q=author%3ASammyIsra "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/8122587?v=4" width="100px;"/><br /><sub>Chao Ren</sub>](https://github.com/RogerAbyss)<br />[🐛](https://github.com/gitpoint/git-point/issues?q=author%3ARogerAbyss "Bug reports") [💻](https://github.com/gitpoint/git-point/commits?author=RogerAbyss "Code") | [<img src="https://avatars0.githubusercontent.com/u/11228182?v=4" width="100px;"/><br /><sub>Harish Toshniwal</sub>](https://introwit.in)<br />[📖](https://github.com/gitpoint/git-point/commits?author=introwit "Documentation") |
| [<img src="https://avatars2.githubusercontent.com/u/774577?v=4" width="100px;"/><br /><sub>Ferran Negre</sub>](http://github.com/ferrannp)<br />[💻](https://github.com/gitpoint/git-point/commits?author=ferrannp "Code") | [<img src="https://avatars0.githubusercontent.com/u/4316908?v=4" width="100px;"/><br /><sub>Wanda Ichsanul Isra</sub>](https://www.linkedin.com/in/wlisrausr)<br />[💻](https://github.com/gitpoint/git-point/commits?author=wlisrausr "Code") | [<img src="https://avatars0.githubusercontent.com/u/25394678?v=4" width="100px;"/><br /><sub>Cameron Samuels</sub>](http://cameronsamuels.com)<br />[📖](https://github.com/gitpoint/git-point/commits?author=CameronSamuels "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/304450?v=4" width="100px;"/><br /><sub>Mehdi Achour</sub>](https://machour.idk.tn/)<br />[🐛](https://github.com/gitpoint/git-point/issues?q=author%3Amachour "Bug reports") [💻](https://github.com/gitpoint/git-point/commits?author=machour "Code") | [<img src="https://avatars2.githubusercontent.com/u/5353857?v=4" width="100px;"/><br /><sub>Reyhan Sofian</sub>](https://www.reyhan.tech/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=reyhansofian "Code") | [<img src="https://avatars2.githubusercontent.com/u/29695071?v=4" width="100px;"/><br /><sub>Ganesh Cauda Salim</sub>](https://github.com/caudaganesh)<br />[💻](https://github.com/gitpoint/git-point/commits?author=caudaganesh "Code") |

| [<img src="https://avatars2.githubusercontent.com/u/774577?v=4" width="100px;"/><br /><sub>Ferran Negre</sub>](http://github.com/ferrannp)<br />[💻](https://github.com/gitpoint/git-point/commits?author=ferrannp "Code") | [<img src="https://avatars2.githubusercontent.com/u/29695071?v=4" width="100px;"/><br /><sub>Ganesh Cauda Salim</sub>](https://github.com/caudaganesh)<br />[💻](https://github.com/gitpoint/git-point/commits?author=caudaganesh "Code") | [<img src="https://avatars0.githubusercontent.com/u/4316908?v=4" width="100px;"/><br /><sub>Wanda Ichsanul Isra</sub>](https://www.linkedin.com/in/wlisrausr)<br />[💻](https://github.com/gitpoint/git-point/commits?author=wlisrausr "Code") | [<img src="https://avatars0.githubusercontent.com/u/25394678?v=4" width="100px;"/><br /><sub>Cameron Samuels</sub>](http://cameronsamuels.com)<br />[📖](https://github.com/gitpoint/git-point/commits?author=CameronSamuels "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/304450?v=4" width="100px;"/><br /><sub>Mehdi Achour</sub>](https://machour.idk.tn/)<br />[🐛](https://github.com/gitpoint/git-point/issues?q=author%3Amachour "Bug reports") [💻](https://github.com/gitpoint/git-point/commits?author=machour "Code") | [<img src="https://avatars2.githubusercontent.com/u/5353857?v=4" width="100px;"/><br /><sub>Reyhan Sofian</sub>](https://www.reyhan.tech/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=reyhansofian "Code") | [<img src="https://avatars1.githubusercontent.com/u/11606323?v=4" width="100px;"/><br /><sub>adrianhartanto0</sub>](https://github.com/adrianhartanto0)<br />[💻](https://github.com/gitpoint/git-point/commits?author=adrianhartanto0 "Code") |
<!-- ALL-CONTRIBUTORS-LIST:END -->
28 changes: 28 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,34 @@ export async function fetchForkRepo(owner, repo, accessToken) {
return response;
}

export async function fetchStarCount(owner) {
const ENDPOINT = `https://api.github.com/users/${owner}/starred?per_page=1`;
const response = await fetch(ENDPOINT);

let linkHeader = response.headers.get('Link');
let output = '';

if (linkHeader == null) {
output = response.json().then(data => {
return data.length;
});
} else {
linkHeader = linkHeader.match(/page=(\d)+/g).pop();
output = linkHeader.split('=').pop();
}

// Add 'k' if star more than 1000

if (output > 1000) {
const outDecimal = (output / 1000).toString();
const dotIndex = outDecimal.indexOf('.');

output = `${outDecimal.substring(0, dotIndex + 3)}k`;
}

return output;
}

export async function watchRepo(isSubscribed, owner, repo, accessToken) {
const ENDPOINT = `https://api.github.com/repos/${owner}/${repo}/subscription`;
const response = await fetch(
Expand Down
24 changes: 24 additions & 0 deletions src/auth/auth.action.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
fetchAuthUserOrgs,
fetchUserOrgs,
fetchUserEvents,
fetchStarCount,
} from 'api';
import {
LOGIN,
Expand All @@ -18,6 +19,7 @@ import {
GET_AUTH_ORGS,
GET_EVENTS,
CHANGE_LANGUAGE,
GET_AUTH_STAR_COUNT,
} from './auth.type';

export const auth = (code, state, navigation) => {
Expand Down Expand Up @@ -83,6 +85,28 @@ export const getUser = () => {
};
};

export const getStarCount = () => {
return (dispatch, getState) => {
const user = getState().auth.user.name;

dispatch({ type: GET_AUTH_STAR_COUNT.PENDING });

fetchStarCount(user)
.then(data => {
dispatch({
type: GET_AUTH_STAR_COUNT.SUCCESS,
payload: data,
});
})
.catch(error => {
dispatch({
type: GET_AUTH_STAR_COUNT.ERROR,
payload: error,
});
});
};
};

export const getOrgs = () => {
return (dispatch, getState) => {
const accessToken = getState().auth.accessToken;
Expand Down
19 changes: 19 additions & 0 deletions src/auth/auth.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
GET_AUTH_ORGS,
GET_EVENTS,
CHANGE_LANGUAGE,
GET_AUTH_STAR_COUNT,
} from './auth.type';

const initialState = {
Expand Down Expand Up @@ -80,6 +81,24 @@ export const authReducer = (state = initialState, action = {}) => {
error: action.payload,
isPendingUser: false,
};
case GET_AUTH_STAR_COUNT.PENDING:
return {
...state,
starCount: ' ',
isPendingStarCount: true,
};
case GET_AUTH_STAR_COUNT.SUCCESS:
return {
...state,
starCount: action.payload,
isPendingStarCount: false,
};
case GET_AUTH_STAR_COUNT.ERROR:
return {
...state,
error: action.payload,
isPendingStarCount: false,
};
case GET_AUTH_ORGS.PENDING:
return {
...state,
Expand Down
1 change: 1 addition & 0 deletions src/auth/auth.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export const GET_AUTH_USER = createActionSet('GET_AUTH_USER');
export const GET_AUTH_ORGS = createActionSet('GET_AUTH_ORGS');
export const GET_EVENTS = createActionSet('GET_EVENTS');
export const CHANGE_LANGUAGE = createActionSet('CHANGE_LANGUAGE');
export const GET_AUTH_STAR_COUNT = createActionSet('GET_AUTH_STAR_COUNT');
9 changes: 8 additions & 1 deletion src/auth/screens/auth-profile.screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import {
EntityInfo,
} from 'components';
import { colors, fonts, normalize } from 'config';
import { getUser, getOrgs, signOut } from 'auth';
import { getUser, getOrgs, signOut, getStarCount } from 'auth';
import { emojifyText, openURLInView, translate } from 'utils';
import { version } from 'package.json';

const mapStateToProps = state => ({
user: state.auth.user,
orgs: state.auth.orgs,
language: state.auth.language,
starCount: state.auth.starCount,
isPendingUser: state.auth.isPendingUser,
isPendingOrgs: state.auth.isPendingOrgs,
hasInitialUser: state.auth.hasInitialUser,
Expand All @@ -37,6 +38,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch => ({
getUserByDispatch: () => dispatch(getUser()),
getOrgsByDispatch: () => dispatch(getOrgs()),
getStarCountByDispatch: () => dispatch(getStarCount()),
signOutByDispatch: () => dispatch(signOut()),
});

Expand Down Expand Up @@ -85,9 +87,11 @@ class AuthProfile extends Component {
props: {
getUserByDispatch: Function,
getOrgsByDispatch: Function,
getStarCountByDispatch: Function,
user: Object,
orgs: Array,
language: string,
starCount: string,
isPendingUser: boolean,
isPendingOrgs: boolean,
hasInitialUser: boolean,
Expand Down Expand Up @@ -139,6 +143,7 @@ class AuthProfile extends Component {
refreshProfile = () => {
this.props.getUserByDispatch();
this.props.getOrgsByDispatch();
this.props.getStarCountByDispatch();
};

render() {
Expand All @@ -148,6 +153,7 @@ class AuthProfile extends Component {
isPendingUser,
isPendingOrgs,
language,
starCount,
navigation,
hasInitialUser,
} = this.props;
Expand All @@ -162,6 +168,7 @@ class AuthProfile extends Component {
type="user"
initialUser={hasInitialUser ? user : {}}
user={hasInitialUser ? user : {}}
starCount={starCount}
language={language}
navigation={navigation}
/>}
Expand Down
15 changes: 13 additions & 2 deletions src/components/user-profile.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Props = {
type: string,
initialUser: Object,
user: Object,
starCount: string,
isFollowing: boolean,
isFollower: boolean,
language: string,
Expand Down Expand Up @@ -79,8 +80,8 @@ const styles = StyleSheet.create({
paddingTop: 3,
paddingBottom: 3,
marginTop: 5,
marginLeft: 35,
marginRight: 35,
marginLeft: 17,
marginRight: 17,
borderWidth: 0.5,
borderRadius: 5,
borderColor: colors.lighterBoldGreen,
Expand All @@ -95,6 +96,7 @@ export const UserProfile = ({
type,
initialUser,
user,
starCount,
isFollowing,
isFollower,
language,
Expand Down Expand Up @@ -141,6 +143,15 @@ export const UserProfile = ({
</Text>
</TouchableOpacity>

<TouchableOpacity style={styles.unit}>
<Text style={styles.unitNumber}>
{starCount}
</Text>
<Text style={styles.unitText}>
{translate('common.stars', language)}
</Text>
</TouchableOpacity>

{type !== 'org' &&
<TouchableOpacity
style={styles.unit}
Expand Down
1 change: 1 addition & 0 deletions src/locale/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export const en = {
},
common: {
bio: 'BIO',
stars: 'Stars',
orgs: 'ORGANIZATIONS',
noOrgsMessage: 'No organizations',
info: 'INFO',
Expand Down
1 change: 1 addition & 0 deletions src/locale/languages/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export const fr = {
},
common: {
bio: 'BIO',
stars: 'Favoris',
orgs: 'ORGANISATIONS',
noOrgsMessage: 'Aucune organisation',
info: 'INFO',
Expand Down
7 changes: 5 additions & 2 deletions src/locale/languages/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export const nl = {
pullRequestEvent: '{{action}} pull request',
pullRequestReviewEvent: '{{action}} pull request review',
pullRequestReviewCommentEvent: '{{action}} op pull request',
pullRequestReviewEditedEvent: 'heeft een opmerking {{action}} op pull request',
pullRequestReviewDeletedEvent: 'heeft een opmerking {{action}} op pull request',
pullRequestReviewEditedEvent:
'heeft een opmerking {{action}} op pull request',
pullRequestReviewDeletedEvent:
'heeft een opmerking {{action}} op pull request',
releaseEvent: '{{action}} release',
atConnector: 'op',
toConnector: 'bij',
Expand Down Expand Up @@ -282,6 +284,7 @@ export const nl = {
},
common: {
bio: 'BIO',
stars: 'Sterren',
orgs: 'ORGANISATIES',
noOrgsMessage: 'Geen organizations',
info: 'INFO',
Expand Down
16 changes: 15 additions & 1 deletion src/user/screens/profile.screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import {
} from 'components';
import { emojifyText, translate } from 'utils';
import { colors, fonts } from 'config';
import { getUserInfo, changeFollowStatus } from '../user.action';
import { getUserInfo, changeFollowStatus, getStarCount } from '../user.action';

const mapStateToProps = state => ({
auth: state.auth.user,
user: state.user.user,
followers: state.user.followers,
orgs: state.user.orgs,
starCount: state.user.starCount,
language: state.auth.language,
isFollowing: state.user.isFollowing,
isPendingUser: state.user.isPendingUser,
Expand All @@ -36,6 +37,7 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({
getUserInfoByDispatch: user => dispatch(getUserInfo(user)),
getUserStarCountByDispatch: user => dispatch(getStarCount(user)),
changeFollowStatusByDispatch: (user, isFollowing) =>
dispatch(changeFollowStatus(user, isFollowing)),
});
Expand All @@ -55,10 +57,12 @@ class Profile extends Component {
props: {
getUserInfoByDispatch: Function,
changeFollowStatusByDispatch: Function,
getUserStarCountByDispatch: Function,
auth: Object,
user: Object,
followers: Array,
orgs: Array,
starCount: string,
language: string,
isFollowing: boolean,
isPendingUser: boolean,
Expand All @@ -82,11 +86,19 @@ class Profile extends Component {
this.props.getUserInfoByDispatch(
this.props.navigation.state.params.user.login
);

this.props.getUserStarCountByDispatch(
this.props.navigation.state.params.user.login
);
}

getUserInfo = () => {
this.setState({ refreshing: true });

this.props.getUserStarCountByDispatch(
this.props.navigation.state.params.user.login
);

this.props
.getUserInfoByDispatch(this.props.navigation.state.params.user.login)
.then(() => {
Expand Down Expand Up @@ -116,6 +128,7 @@ class Profile extends Component {
const {
user,
orgs,
starCount,
language,
isFollowing,
isPendingUser,
Expand All @@ -139,6 +152,7 @@ class Profile extends Component {
<UserProfile
type="user"
initialUser={initialUser}
starCount={starCount}
isFollowing={
isPendingUser || isPendingCheckFollowing ? false : isFollowing
}
Expand Down
Loading