App: cleanup the component and make sync add to fetch count.

master
Tom Hacohen 4 years ago
parent 3ebaf35f49
commit 877171b2ea

@ -2,8 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import * as React from "react"; import * as React from "react";
import { List as ImmutableList } from "immutable"; import { useDispatch, useSelector } from "react-redux";
import { connect, useDispatch } from "react-redux";
import { useHistory, useLocation } from "react-router"; import { useHistory, useLocation } from "react-router";
import { BrowserRouter } from "react-router-dom"; import { BrowserRouter } from "react-router-dom";
import { MuiThemeProvider as ThemeProvider, createMuiTheme } from "@material-ui/core/styles"; // v1.x import { MuiThemeProvider as ThemeProvider, createMuiTheme } from "@material-ui/core/styles"; // v1.x
@ -36,7 +35,8 @@ import { RouteResolver } from "./routes";
import * as store from "./store"; import * as store from "./store";
import * as actions from "./store/actions"; import * as actions from "./store/actions";
import { credentialsSelector } from "./login"; import { useCredentials } from "./credentials";
import { SyncManager } from "./sync/SyncManager";
export const routeResolver = new RouteResolver({ export const routeResolver = new RouteResolver({
home: "", home: "",
@ -145,25 +145,24 @@ function AppBarWitHistory(props: AppBarPropsType) {
const IconRefreshWithSpin = withSpin(NavigationRefresh); const IconRefreshWithSpin = withSpin(NavigationRefresh);
interface PropsType { export default function App() {
credentials: store.CredentialsData;
entries: store.EntriesData;
fetchCount: number;
darkMode: boolean;
errors: ImmutableList<Error>;
}
function App(props: PropsType) {
const [drawerOpen, setDrawerOpen] = React.useState(false); const [drawerOpen, setDrawerOpen] = React.useState(false);
const [errorsDialog, setErrorsDialog] = React.useState(false); const [errorsDialog, setErrorsDialog] = React.useState(false);
const dispatch = useDispatch(); const dispatch = useDispatch();
const etebase = useCredentials();
const darkMode = useSelector((state: store.StoreState) => state.settings.darkMode);
const fetchCount = useSelector((state: store.StoreState) => state.fetchCount);
const errors = useSelector((state: store.StoreState) => state.errors);
function refresh() { async function refresh() {
dispatch(actions.fetchAll(props.credentials, props.entries)); const syncManager = SyncManager.getManager(etebase!);
const sync = syncManager.sync();
dispatch(actions.performSync(sync));
await sync;
} }
function autoRefresh() { function autoRefresh() {
if (navigator.onLine && props.credentials && if (navigator.onLine && etebase &&
!(window.location.pathname.match(/.*\/(new|edit|duplicate)$/))) { !(window.location.pathname.match(/.*\/(new|edit|duplicate)$/))) {
refresh(); refresh();
} }
@ -183,11 +182,9 @@ function App(props: PropsType) {
setDrawerOpen(false); setDrawerOpen(false);
} }
const credentials = props.credentials ?? null; const credentials = etebase ?? null;
const { darkMode } = props;
const errors = props.errors; const fetching = fetchCount > 0;
const fetching = props.fetchCount > 0;
const muiTheme = createMuiTheme({ const muiTheme = createMuiTheme({
palette: { palette: {
@ -269,17 +266,3 @@ function App(props: PropsType) {
</ThemeProvider> </ThemeProvider>
); );
} }
const mapStateToProps = (state: store.StoreState) => {
return {
credentials: credentialsSelector(state),
entries: state.cache.entries,
fetchCount: state.fetchCount,
darkMode: !!state.settings.darkMode,
errors: state.errors,
};
};
export default connect(
mapStateToProps
)(App as any);

@ -319,6 +319,7 @@ for (const func in actions) {
// Indicates network activity, not just fetch // Indicates network activity, not just fetch
export const fetchCount = handleAction( export const fetchCount = handleAction(
combineActions( combineActions(
actions.performSync.toString(),
...fetchActions ...fetchActions
), ),
(state: number, action: any) => { (state: number, action: any) => {

Loading…
Cancel
Save