Set header title to match currently selected group

This commit is contained in:
Arnaud Vergnet 2020-04-16 10:31:51 +02:00
parent 28168aacf8
commit b6b87b6c06
3 changed files with 15 additions and 6 deletions

View file

@ -18,8 +18,6 @@ type State = {
const LIST_ITEM_HEIGHT = 64; const LIST_ITEM_HEIGHT = 64;
const REPLACE_REGEX = /_/g;
export default class GroupListAccordion extends React.Component<Props, State> { export default class GroupListAccordion extends React.Component<Props, State> {
state = { state = {
@ -43,7 +41,7 @@ export default class GroupListAccordion extends React.Component<Props, State> {
const onPress = () => this.props.onGroupPress(item); const onPress = () => this.props.onGroupPress(item);
return ( return (
<List.Item <List.Item
title={item.name.replace(REPLACE_REGEX, " ")} title={item.name}
onPress={onPress} onPress={onPress}
left={props => left={props =>
<List.Icon <List.Icon

View file

@ -30,6 +30,7 @@ function sortName(a, b) {
} }
const GROUPS_URL = 'http://planex.insa-toulouse.fr/wsAdeGrp.php?projectId=1'; const GROUPS_URL = 'http://planex.insa-toulouse.fr/wsAdeGrp.php?projectId=1';
const REPLACE_REGEX = /_/g;
/** /**
* Class defining proximo's article list of a certain category. * Class defining proximo's article list of a certain category.
@ -126,12 +127,19 @@ class GroupSelectionScreen extends React.Component<Props, State> {
generateData(fetchedData: Object) { generateData(fetchedData: Object) {
let data = []; let data = [];
for (let key in fetchedData) { for (let key in fetchedData) {
this.formatGroupNames(fetchedData[key]);
data.push(fetchedData[key]); data.push(fetchedData[key]);
} }
data.sort(sortName); data.sort(sortName);
return data; return data;
} }
formatGroupNames(item: Object) {
for (let i = 0; i < item.content.length; i++) {
item.content[i].name = item.content[i].name.replace(REPLACE_REGEX, " ")
}
}
/** /**
* Creates the dataset to be used in the FlatList * Creates the dataset to be used in the FlatList
* *

View file

@ -137,16 +137,18 @@ class PlanexScreen extends React.Component<Props, State> {
/** /**
* Defines custom injected JavaScript to improve the page display on mobile * Defines custom injected JavaScript to improve the page display on mobile
*/ */
constructor() { constructor(props) {
super(); super(props);
this.webScreenRef = React.createRef(); this.webScreenRef = React.createRef();
this.barRef = React.createRef(); this.barRef = React.createRef();
let currentGroup = AsyncStorageManager.getInstance().preferences.planexCurrentGroup.current; let currentGroup = AsyncStorageManager.getInstance().preferences.planexCurrentGroup.current;
if (currentGroup === '') if (currentGroup === '')
currentGroup = {name: "SELECT GROUP", id: -1}; currentGroup = {name: "SELECT GROUP", id: -1};
else else {
currentGroup = JSON.parse(currentGroup); currentGroup = JSON.parse(currentGroup);
props.navigation.setOptions({title: currentGroup.name})
}
this.state = { this.state = {
bannerVisible: bannerVisible:
AsyncStorageManager.getInstance().preferences.planexShowBanner.current === '1' && AsyncStorageManager.getInstance().preferences.planexShowBanner.current === '1' &&
@ -183,6 +185,7 @@ class PlanexScreen extends React.Component<Props, State> {
AsyncStorageManager.getInstance().savePref( AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.planexCurrentGroup.key, AsyncStorageManager.getInstance().preferences.planexCurrentGroup.key,
JSON.stringify(group)); JSON.stringify(group));
this.props.navigation.setOptions({title: group.name})
this.generateInjectedJS(group.id); this.generateInjectedJS(group.id);
} }