Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Sync integrity
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed May 15, 2019
1 parent 933f48b commit 0aa1648
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/models/extend/item.js
Expand Up @@ -16,11 +16,16 @@ SFItem.prototype.updateFromJSON = function(json) {
}
}

const original_dateToLocalizedString = SFItem.prototype.dateToLocalizedString;
SFItem.prototype.dateToLocalizedString = function(date) {
return moment(date).format('llll');
}

SFItem.prototype.updatedAtTimestamp = function() {
// date is a moment date
// in the base class we do date.getTime(), but that doesn't work with moment dates.
return this.updated_at.valueOf();
}

// Define these getters

Object.defineProperty(SFItem.prototype, "key", {
Expand Down
3 changes: 2 additions & 1 deletion src/screens/Notes/Notes.js
Expand Up @@ -332,7 +332,8 @@ export default class Notes extends Abstract {
_onRefresh() {
this.setSubTitle("Syncing...");
this.setState({refreshing: true});
Sync.get().sync().then(() => {
// Perform integrity checks for hard reloads
Sync.get().sync({performIntegrityCheck: true}).then(() => {
setTimeout(() => {
this.setSubTitle(null);
}, 100);
Expand Down
4 changes: 3 additions & 1 deletion src/screens/Root.js
Expand Up @@ -123,6 +123,7 @@ export default class Root extends Abstract {
componentWillUnmount() {
super.componentWillUnmount();
ApplicationState.get().removeStateObserver(this.stateObserver);
Sync.get().removeEventHandler(this.syncEventHandler);
Sync.get().removeSyncStatusObserver(this.syncStatusObserver);
clearInterval(this.syncTimer);
}
Expand Down Expand Up @@ -182,8 +183,9 @@ export default class Root extends Abstract {
Sync.get().unlockSyncing();
this.setSubTitle("Syncing...");
this.dataLoaded = true;

// perform initial sync
Sync.get().sync().then(() => {
Sync.get().sync({performIntegrityCheck: true}).then(() => {
this.setSubTitle(null);
});
}
Expand Down
20 changes: 19 additions & 1 deletion src/screens/SideMenu/MainSideMenu.js
Expand Up @@ -9,6 +9,7 @@ import ActionSheet from 'react-native-actionsheet'
import Abstract from "@Screens/Abstract"
import AlertManager from "@SFJS/alertManager"
import Auth from "@SFJS/authManager"
import Sync from '@SFJS/syncManager'

import SectionHeader from "@Components/SectionHeader";
import TableSection from "@Components/TableSection";
Expand Down Expand Up @@ -37,17 +38,30 @@ export default class MainSideMenu extends AbstractSideMenu {
this.forceUpdate();
}
});

this.syncEventHandler = Sync.get().addEventHandler((event, data) => {
if(event == "enter-out-of-sync") {
this.setState({outOfSync: true});
} else if(event == "exit-out-of-sync") {
this.setState({outOfSync: false});
}
})
}

componentWillUnmount() {
super.componentWillUnmount();
Auth.get().removeEventHandler(this.signoutObserver);
Sync.get().removeEventHandler(this.syncEventHandler);
}

presentSettings() {
this.props.navigation.navigate("Settings");
}

presentOutOfSyncResolution() {

}

get handler() {
return SideMenuManager.get().getHandlerForLeftSideMenu();
}
Expand Down Expand Up @@ -151,7 +165,11 @@ export default class MainSideMenu extends AbstractSideMenu {
<SafeAreaView style={this.styles.firstSafeArea} />
<SafeAreaView style={[viewStyles, this.styles.secondSafeArea]}>

<SideMenuHero onPress={() => {this.presentSettings()}}/>
<SideMenuHero
outOfSync={this.state.outOfSync}
onPress={() => {this.presentSettings()}}
onOutOfSyncPress={() => {this.presentOutOfSyncResolution()}}
/>

<ScrollView style={this.styles.scrollView} removeClippedSubviews={false}>

Expand Down
28 changes: 28 additions & 0 deletions src/screens/SideMenu/SideMenuHero.js
Expand Up @@ -7,6 +7,7 @@ import ModelManager from "@SFJS/modelManager"

import StyleKit from "@Style/StyleKit"
import ThemedComponent from "@Components/ThemedComponent";
import Circle from "@Components/Circle"


export default class SideMenuHero extends ThemedComponent {
Expand Down Expand Up @@ -43,6 +44,15 @@ export default class SideMenuHero extends ThemedComponent {
<TouchableOpacity onPress={this.props.onPress}>
<Text style={this.styles.subtitle}>{textData.text}</Text>
</TouchableOpacity>

{this.props.outOfSync &&
<TouchableOpacity style={this.styles.outOfSyncContainer} onPress={this.props.onOutOfSyncPress}>
<View style={this.styles.iconCircle}>
<Circle backgroundColor={StyleKit.variables.stylekitWarningColor} borderColor={StyleKit.variables.stylekitWarningColor} />
</View>
<Text style={this.styles.outOfSync}>Potentially Out of Sync</Text>
</TouchableOpacity>
}
</View>
)
}
Expand Down Expand Up @@ -70,6 +80,24 @@ export default class SideMenuHero extends ThemedComponent {
fontSize: 13,
color: StyleKit.variables.stylekitContrastForegroundColor,
opacity: 0.6
},

outOfSyncContainer: {
flex: 0,
flexDirection: 'row',
alignItems: "center"
},

iconCircle: {
marginTop: 10,
width: 20,
},

outOfSync: {
marginTop: 10,
fontSize: 13,
color: StyleKit.variables.stylekitWarningColor,
fontWeight: "bold"
}
}
}
Expand Down

0 comments on commit 0aa1648

Please sign in to comment.