You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.7 KiB
TypeScript

// SPDX-FileCopyrightText: © 2017 EteSync Authors
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from "react";
4 years ago
import { useSelector, useDispatch } from "react-redux";
import { Route, Switch, Redirect, useHistory } from "react-router";
import moment from "moment";
import "moment/locale/en-gb";
import { List, Map } from "immutable";
import { routeResolver } from "./App";
import AppBarOverride from "./widgets/AppBarOverride";
import LoadingIndicator from "./widgets/LoadingIndicator";
import ContactsMain from "./Contacts/Main";
import CalendarsMain from "./Calendars/Main";
import Journals from "./Journals";
import Settings from "./Settings";
import Debug from "./Debug";
import * as EteSync from "etesync";
4 years ago
import { SyncManager } from "./sync/SyncManager";
import { StoreState } from "./store";
import { performSync } from "./store/actions";
import { useCredentials } from "./credentials";
export interface SyncInfoJournal {
journal: EteSync.Journal;
journalEntries: List<EteSync.Entry>;
collection: EteSync.CollectionInfo;
entries: List<EteSync.SyncEntry>;
}
export type SyncInfo = Map<string, SyncInfoJournal>;
4 years ago
export default function SyncGate() {
const etebase = useCredentials();
const settings = useSelector((state: StoreState) => state.settings);
const userInfo = useSelector((state: StoreState) => state.cache.userInfo);
const journals = useSelector((state: StoreState) => state.cache.journals);
4 years ago
const dispatch = useDispatch();
const [loading, setLoading] = React.useState(true);
// Doing this so we refresh on route changes
useHistory();
React.useEffect(() => {
4 years ago
(async () => {
const syncManager = SyncManager.getManager(etebase!);
const sync = syncManager.sync();
dispatch(performSync(sync));
await sync;
setLoading(false);
})();
}, []);
4 years ago
if (loading) {
return (<LoadingIndicator style={{ display: "block", margin: "40px auto" }} />);
}
// FIXME: Shouldn't be here
moment.locale(settings.locale);
// FIXME: remove
4 years ago
const etesync = etebase as any;
return (
<Switch>
<Route
path={routeResolver.getRoute("home")}
exact
render={() => (
<Redirect to={routeResolver.getRoute("pim")} />
)}
/>
4 years ago
<Route
path={routeResolver.getRoute("pim")}
>
<AppBarOverride title="EteSync" />
<Switch>
4 years ago
<Route
path={routeResolver.getRoute("pim")}
4 years ago
exact
>
<Redirect to={routeResolver.getRoute("pim.events")} />
</Route>
<Route
path={routeResolver.getRoute("pim.contacts")}
>
<ContactsMain />
4 years ago
</Route>
<Route
path={routeResolver.getRoute("pim.events")}
>
<CalendarsMain />
4 years ago
</Route>
<Route
path={routeResolver.getRoute("pim.tasks")}
>
tasks
</Route>
</Switch>
</Route>
{false && (
<>
4 years ago
<Route
path={routeResolver.getRoute("journals")}
render={({ location, history }) => (
<Journals
etesync={etesync}
userInfo={userInfo}
syncInfo={false as any}
journals={journals}
location={location}
history={history}
/>
)}
/>
</>
)}
<Route
path={routeResolver.getRoute("settings")}
exact
render={() => (
<Settings />
)}
/>
<Route
path={routeResolver.getRoute("debug")}
exact
render={() => (
<Debug
etesync={etesync}
userInfo={userInfo}
/>
)}
/>
</Switch>
);
4 years ago
}