Improve structure and flow types

This commit is contained in:
Arnaud Vergnet 2020-09-09 17:12:23 +02:00
parent 3eabd84b58
commit 182360aabd

View file

@ -13,6 +13,7 @@ import type {
ListIconPropsType, ListIconPropsType,
} from '../../constants/PaperStyles'; } from '../../constants/PaperStyles';
import OptionsDialog from '../../components/Dialogs/OptionsDialog'; import OptionsDialog from '../../components/Dialogs/OptionsDialog';
import type {OptionsDialogButtonType} from '../../components/Dialogs/OptionsDialog';
type ListItemType = { type ListItemType = {
onPressCallback: () => void, onPressCallback: () => void,
@ -21,12 +22,13 @@ type ListItemType = {
showChevron: boolean, showChevron: boolean,
}; };
type AthorsItemType = { type MemberItemType = {
name: string, name: string,
message: string, message: string,
btnTrool: OptionsDialogButtonType, icon: string,
btnLinkedin: OptionsDialogButtonType, trollLink?: string,
btnMail: OptionsDialogButtonType, linkedin?: string,
mail?: string,
}; };
const links = { const links = {
@ -39,28 +41,20 @@ const links = {
'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/Changelog.md', 'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/Changelog.md',
license: license:
'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/LICENSE', 'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/LICENSE',
arnaudMail:
'mailto:vergnet@etud.insa-toulouse.fr?' +
'subject=' +
'Application Amicale INSA Toulouse' +
'&body=' +
'Coucou !\n\n',
arnaudLinkedin: 'https://www.linkedin.com/in/arnaud-vergnet-434ba5179/',
yohanMail:
'mailto:ysimard@etud.insa-toulouse.fr?' +
'subject=' +
'Application Amicale INSA Toulouse' +
'&body=' +
'Coucou !\n\n',
yohanLinkedin: 'https://www.linkedin.com/in/yohan-simard',
react: 'https://facebook.github.io/react-native/', react: 'https://facebook.github.io/react-native/',
meme: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
}; };
type PropsType = { type PropsType = {
navigation: StackNavigationProp, navigation: StackNavigationProp,
}; };
type StateType = {
dialogVisible: boolean,
dialogTitle: string,
dialogMessage: string,
dialogButtons: Array<OptionsDialogButtonType>,
};
/** /**
* Opens a link in the device's browser * Opens a link in the device's browser
* @param link The link to open * @param link The link to open
@ -70,110 +64,75 @@ function openWebLink(link: string) {
} }
/** /**
* Class defining an about screen. This screen shows the user information about the app and it's author. * Object containing data relative to major contributors
*/ */
class AboutScreen extends React.Component<PropsType> { const majorContributors: {[key: string]: MemberItemType} = {
/**
* Data team
*/
teamUsers = {
arnaud: { arnaud: {
name: 'Arnaud Vergnrt', name: 'Arnaud Vergnet',
message: i18n.t('screens.about.user.arnaud'), message: i18n.t('screens.about.user.arnaud'),
icon: 'crown', icon: 'crown',
btnTrool: { trollLink: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
title: 'SWAG', linkedin: 'https://www.linkedin.com/in/arnaud-vergnet-434ba5179/',
onPress: () => { mail:
openWebLink(links.meme); 'mailto:vergnet@etud.insa-toulouse.fr?' +
}, 'subject=' +
}, 'Application Amicale INSA Toulouse' +
btnLinkedin: { '&body=' +
title: '', 'Coucou !\n\n',
icon: 'linkedin',
onPress: () => {
openWebLink(links.arnaudMail);
},
},
btnMail: {
title: '',
icon: 'email-edit',
onPress: () => {
openWebLink(links.arnaudLinkedin);
},
},
}, },
yohan: { yohan: {
name: 'Yohan Simard', name: 'Yohan Simard',
message: i18n.t('screens.about.user.yohan'), message: i18n.t('screens.about.user.yohan'),
icon: 'xml', icon: 'xml',
btnTrool: null, linkedin: 'https://www.linkedin.com/in/yohan-simard',
btnLinkedin: { mail: 'mailto:ysimard@etud.insa-toulouse.fr?' +
title: '', 'subject=' +
icon: 'linkedin', 'Application Amicale INSA Toulouse' +
onPress: () => { '&body=' +
openWebLink(links.yohanLinkedin); 'Coucou !\n\n',
},
},
btnMail: {
title: '',
icon: 'email-edit',
onPress: () => {
openWebLink(links.yohanMail);
},
},
}, },
}; };
/** /**
* Data thanks * Object containing data relative to users who helped during development
*/ */
thanksUsers = { const helpfulUsers: {[key: string]: MemberItemType} = {
beranger: { beranger: {
name: 'Béranger Quintana Y Arciosana', name: 'Béranger Quintana Y Arciosana',
message: i18n.t('screens.about.user.beranger'), message: i18n.t('screens.about.user.beranger'),
icon: 'account-heart', icon: 'account-heart',
btnTrool: null,
btnLinkedin: null,
btnMail: null,
}, },
celine: { celine: {
name: 'Céline Tassin', name: 'Céline Tassin',
message: i18n.t('screens.about.user.celine'), message: i18n.t('screens.about.user.celine'),
icon: 'brush', icon: 'brush',
btnTrool: null,
btnLinkedin: null,
btnMail: null,
}, },
damien: { damien: {
name: 'Damien Molina', name: 'Damien Molina',
message: i18n.t('screens.about.user.damien'), message: i18n.t('screens.about.user.damien'),
icon: 'web', icon: 'web',
btnTrool: null,
btnLinkedin: null,
btnMail: null,
}, },
titouan: { titouan: {
name: 'Titouan Labourdette', name: 'Titouan Labourdette',
message: i18n.t('screens.about.user.titouan'), message: i18n.t('screens.about.user.titouan'),
icon: 'shield-bug', icon: 'shield-bug',
btnTrool: null,
btnLinkedin: null,
btnMail: null,
}, },
theo: { theo: {
name: 'Théo Tami', name: 'Théo Tami',
message: i18n.t('screens.about.user.theo'), message: i18n.t('screens.about.user.theo'),
icon: 'food-apple', icon: 'food-apple',
btnTrool: null,
btnLinkedin: null,
btnMail: null,
}, },
}; };
/**
* Class defining an about screen. This screen shows the user information about the app and it's author.
*/
class AboutScreen extends React.Component<PropsType, StateType> {
/** /**
* Data to be displayed in the app card * Data to be displayed in the app card
*/ */
appData = [ appData: Array<ListItemType> = [
{ {
onPressCallback: () => { onPressCallback: () => {
openWebLink(Platform.OS === 'ios' ? links.appstore : links.playstore); openWebLink(Platform.OS === 'ios' ? links.appstore : links.playstore);
@ -221,23 +180,23 @@ class AboutScreen extends React.Component<PropsType> {
]; ];
/** /**
* Data to be displayed in the additional developer card * Data to be displayed in the team card
*/ */
teamData = [ teamData: Array<ListItemType> = [
{ {
onPressCallback: () => { onPressCallback: () => {
this.onListItemPress(this.teamUsers.arnaud); this.onContributorListItemPress(majorContributors.arnaud);
}, },
icon: this.teamUsers.arnaud.icon, icon: majorContributors.arnaud.icon,
text: this.teamUsers.arnaud.name, text: majorContributors.arnaud.name,
showChevron: false, showChevron: false,
}, },
{ {
onPressCallback: () => { onPressCallback: () => {
this.onListItemPress(this.teamUsers.yohan); this.onContributorListItemPress(majorContributors.yohan);
}, },
icon: this.teamUsers.yohan.icon, icon: majorContributors.yohan.icon,
text: this.teamUsers.yohan.name, text: majorContributors.yohan.name,
showChevron: false, showChevron: false,
}, },
{ {
@ -254,45 +213,45 @@ class AboutScreen extends React.Component<PropsType> {
/** /**
* Data to be displayed in the thanks card * Data to be displayed in the thanks card
*/ */
thanksData = [ thanksData: Array<ListItemType> = [
{ {
onPressCallback: () => { onPressCallback: () => {
this.onListItemPress(this.thanksUsers.beranger); this.onContributorListItemPress(helpfulUsers.beranger);
}, },
icon: this.thanksUsers.beranger.icon, icon: helpfulUsers.beranger.icon,
text: this.thanksUsers.beranger.name, text: helpfulUsers.beranger.name,
showChevron: false, showChevron: false,
}, },
{ {
onPressCallback: () => { onPressCallback: () => {
this.onListItemPress(this.thanksUsers.celine); this.onContributorListItemPress(helpfulUsers.celine);
}, },
icon: this.thanksUsers.celine.icon, icon: helpfulUsers.celine.icon,
text: this.thanksUsers.celine.name, text: helpfulUsers.celine.name,
showChevron: false, showChevron: false,
}, },
{ {
onPressCallback: () => { onPressCallback: () => {
this.onListItemPress(this.thanksUsers.damien); this.onContributorListItemPress(helpfulUsers.damien);
}, },
icon: this.thanksUsers.damien.icon, icon: helpfulUsers.damien.icon,
text: this.thanksUsers.damien.name, text: helpfulUsers.damien.name,
showChevron: false, showChevron: false,
}, },
{ {
onPressCallback: () => { onPressCallback: () => {
this.onListItemPress(this.thanksUsers.titouan); this.onContributorListItemPress(helpfulUsers.titouan);
}, },
icon: this.thanksUsers.titouan.icon, icon: helpfulUsers.titouan.icon,
text: this.thanksUsers.titouan.name, text: helpfulUsers.titouan.name,
showChevron: false, showChevron: false,
}, },
{ {
onPressCallback: () => { onPressCallback: () => {
this.onListItemPress(this.thanksUsers.theo); this.onContributorListItemPress(helpfulUsers.theo);
}, },
icon: this.thanksUsers.theo.icon, icon: helpfulUsers.theo.icon,
text: this.thanksUsers.theo.name, text: helpfulUsers.theo.name,
showChevron: false, showChevron: false,
}, },
]; ];
@ -345,35 +304,48 @@ class AboutScreen extends React.Component<PropsType> {
dialogTitle: '', dialogTitle: '',
dialogMessage: '', dialogMessage: '',
dialogButtons: [], dialogButtons: [],
onDialogDismiss: () => {
this.setState({dialogVisible: false});
},
}; };
} }
/** /**
* Callback used when clicking an article in the list. * Callback used when clicking a member in the list
* It opens the modal to show detailed information about the article * It opens a dialog to show detailed information this member
* *
* @param user A user key * @param user The member to show information for
*/ */
onListItemPress(user: AthorsItemType) { onContributorListItemPress(user: MemberItemType) {
const dialogBtn: Array<IconOptionsDialogButtonType> = [ const dialogBtn = [
{ {
title: 'OK', title: 'OK',
onPress: () => { onPress: this.onDialogDismiss,
this.setState({dialogVisible: false});
},
}, },
]; ];
if (user.btnMail != null) { const {linkedin, trollLink, mail} = user;
dialogBtn.push(user.btnMail); if (linkedin != null) {
dialogBtn.push({
title: '',
icon: 'linkedin',
onPress: () => {
openWebLink(linkedin);
},
});
} }
if (user.btnLinkedin != null) { if (mail) {
dialogBtn.push(user.btnLinkedin); dialogBtn.push({
title: '',
icon: 'email-edit',
onPress: () => {
openWebLink(mail);
},
});
} }
if (user.btnTrool != null) { if (trollLink) {
dialogBtn.push(user.btnTrool); dialogBtn.push({
title: 'SWAG',
onPress: () => {
openWebLink(trollLink);
},
});
} }
this.setState({ this.setState({
dialogVisible: true, dialogVisible: true,
@ -561,6 +533,10 @@ class AboutScreen extends React.Component<PropsType> {
} }
}; };
onDialogDismiss = () => {
this.setState({dialogVisible: false});
};
/** /**
* Extracts a key from the given item * Extracts a key from the given item
* *
@ -586,7 +562,7 @@ class AboutScreen extends React.Component<PropsType> {
title={state.dialogTitle} title={state.dialogTitle}
message={state.dialogMessage} message={state.dialogMessage}
buttons={state.dialogButtons} buttons={state.dialogButtons}
onDismiss={state.onDialogDismiss} onDismiss={this.onDialogDismiss}
/> />
</View> </View>
); );