Refresh lists on focus and every minute for proxiwash
This commit is contained in:
parent
0201b9a389
commit
054d8f4a33
4 changed files with 42 additions and 5 deletions
|
@ -24,9 +24,14 @@ export default class FetchedDataSectionList extends React.Component<Props, State
|
|||
|
||||
webDataManager: WebDataManager;
|
||||
|
||||
constructor(fetchUrl: string) {
|
||||
willFocusSubscription : function;
|
||||
willBlurSubscription : function;
|
||||
refreshInterval: IntervalID;
|
||||
|
||||
constructor(fetchUrl: string, refreshTime : number) {
|
||||
super();
|
||||
this.webDataManager = new WebDataManager(fetchUrl);
|
||||
this.refreshTime = refreshTime;
|
||||
}
|
||||
|
||||
state = {
|
||||
|
@ -48,10 +53,40 @@ export default class FetchedDataSectionList extends React.Component<Props, State
|
|||
* Refresh the FetchedData on first screen load
|
||||
*/
|
||||
componentDidMount() {
|
||||
this._onRefresh();
|
||||
this.willFocusSubscription = this.props.navigation.addListener(
|
||||
'willFocus',
|
||||
payload => {
|
||||
this.onScreenFocus();
|
||||
}
|
||||
);
|
||||
this.willBlurSubscription = this.props.navigation.addListener(
|
||||
'willBlur',
|
||||
payload => {
|
||||
this.onScreenBlur();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onScreenFocus() {
|
||||
this._onRefresh();
|
||||
if (this.refreshTime > 0)
|
||||
this.refreshInterval = setInterval(() => this._onRefresh(), this.refreshTime)
|
||||
}
|
||||
|
||||
onScreenBlur() {
|
||||
clearInterval(this.refreshInterval);
|
||||
}
|
||||
|
||||
|
||||
componentWillUnmount() {
|
||||
this.willBlurSubscription.remove();
|
||||
this.willFocusSubscription.remove();
|
||||
|
||||
}
|
||||
|
||||
|
||||
_onRefresh = () => {
|
||||
console.log('refresh');
|
||||
this.setState({refreshing: true});
|
||||
this.webDataManager.readData().then((fetchedData) => {
|
||||
this.setState({
|
||||
|
|
|
@ -27,7 +27,7 @@ function openWebLink(link) {
|
|||
export default class HomeScreen extends FetchedDataSectionList {
|
||||
|
||||
constructor() {
|
||||
super(DATA_URL);
|
||||
super(DATA_URL, 0);
|
||||
}
|
||||
|
||||
getHeaderTranslation() {
|
||||
|
|
|
@ -24,7 +24,7 @@ const typesIcons = {
|
|||
export default class ProximoMainScreen extends FetchedDataSectionList {
|
||||
|
||||
constructor() {
|
||||
super(DATA_URL);
|
||||
super(DATA_URL, 0);
|
||||
}
|
||||
|
||||
getHeaderTranslation() {
|
||||
|
|
|
@ -35,11 +35,13 @@ let stateColors = {};
|
|||
*/
|
||||
export default class ProxiwashScreen extends FetchedDataSectionList {
|
||||
|
||||
refreshInterval : IntervalID;
|
||||
|
||||
/**
|
||||
* Creates machine state parameters using current theme and translations
|
||||
*/
|
||||
constructor() {
|
||||
super(DATA_URL);
|
||||
super(DATA_URL, 1000 * 60); // Refresh every minute
|
||||
let colors = ThemeManager.getCurrentThemeVariables();
|
||||
stateColors[MACHINE_STATES.TERMINE] = colors.proxiwashFinishedColor;
|
||||
stateColors[MACHINE_STATES.DISPONIBLE] = colors.proxiwashReadyColor;
|
||||
|
|
Loading…
Reference in a new issue