mirror of
https://github.com/koodo-reader/koodo-reader.git
synced 2025-12-23 23:17:55 -05:00
feat: Refactor cloud sync handling and add user info fetching in relevant components
This commit is contained in:
@@ -461,6 +461,7 @@ class Header extends React.Component<HeaderProps, HeaderState> {
|
||||
default_sync_option: this.props.defaultSyncOption,
|
||||
default_sync_token: encryptedToken || "",
|
||||
});
|
||||
await this.props.handleFetchUserInfo();
|
||||
toast.success(this.props.t("Setup successful"));
|
||||
this.handleCloudSync();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
formatTimestamp,
|
||||
getServerRegion,
|
||||
getWebsiteUrl,
|
||||
handleCloudSync,
|
||||
handleAutoCloudSync,
|
||||
handleContextMenu,
|
||||
openInBrowser,
|
||||
reloadManager,
|
||||
@@ -190,7 +190,7 @@ class AccountSetting extends React.Component<
|
||||
});
|
||||
this.props.handleFetchAuthed();
|
||||
this.props.handleFetchLoginOptionList();
|
||||
let result = await handleCloudSync();
|
||||
let result = await handleAutoCloudSync();
|
||||
if (result) {
|
||||
this.props.cloudSyncFunc();
|
||||
} else {
|
||||
|
||||
@@ -242,12 +242,13 @@ class SyncSetting extends React.Component<SettingInfoProps, SettingInfoState> {
|
||||
let encryptToken = await TokenService.getToken(
|
||||
this.props.defaultSyncOption + "_token"
|
||||
);
|
||||
updateUserConfig({
|
||||
await updateUserConfig({
|
||||
is_enable_koodo_sync:
|
||||
ConfigService.getReaderConfig("isEnableKoodoSync"),
|
||||
default_sync_option: this.props.defaultSyncOption,
|
||||
default_sync_token: encryptToken || "",
|
||||
});
|
||||
await this.props.handleFetchUserInfo();
|
||||
if (
|
||||
ConfigService.getReaderConfig("isEnableKoodoSync") ===
|
||||
"yes"
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
handleLoadingDialog,
|
||||
handleFetchAuthed,
|
||||
handleLoginOptionList,
|
||||
handleFetchUserInfo,
|
||||
} from "../../../store/actions";
|
||||
import { stateType } from "../../../store";
|
||||
import { withRouter } from "react-router-dom";
|
||||
@@ -48,6 +49,7 @@ const actionCreator = {
|
||||
handleLoadingDialog,
|
||||
handleFetchAuthed,
|
||||
handleLoginOptionList,
|
||||
handleFetchUserInfo,
|
||||
};
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface SettingInfoProps extends RouteComponentProps<any> {
|
||||
handleFetchBooks: () => void;
|
||||
handleFetchPlugins: () => void;
|
||||
cloudSyncFunc: () => Promise<void>;
|
||||
handleFetchUserInfo: () => Promise<void>;
|
||||
bookmarks: BookmarkModel[];
|
||||
notes: NoteModel[];
|
||||
isOpenTokenDialog: boolean;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { loginList } from "../../constants/loginList";
|
||||
import {
|
||||
generateSyncRecord,
|
||||
getServerRegion,
|
||||
handleCloudSync,
|
||||
handleAutoCloudSync,
|
||||
handleContextMenu,
|
||||
openInBrowser,
|
||||
removeSearchParams,
|
||||
@@ -89,7 +89,7 @@ class Login extends React.Component<LoginProps, LoginState> {
|
||||
let res = await loginRegister(service, code);
|
||||
if (res.code === 200) {
|
||||
this.props.handleLoadingDialog(false);
|
||||
let result = await handleCloudSync();
|
||||
let result = await handleAutoCloudSync();
|
||||
if (result) {
|
||||
this.props.cloudSyncFunc();
|
||||
} else {
|
||||
|
||||
@@ -1006,13 +1006,25 @@ export const resetKoodoSync = async () => {
|
||||
});
|
||||
}, 1000);
|
||||
};
|
||||
export const handleCloudSync = async () => {
|
||||
export const handleAutoCloudSync = async () => {
|
||||
let syncRes = await getCloudSyncToken();
|
||||
if (
|
||||
syncRes.code === 200 &&
|
||||
syncRes.data.default_sync_option &&
|
||||
syncRes.data.default_sync_token
|
||||
) {
|
||||
let supportedSources = driveList
|
||||
.filter((item) => {
|
||||
if (isElectron) {
|
||||
return item.support.includes("desktop");
|
||||
} else {
|
||||
return item.support.includes("browser");
|
||||
}
|
||||
})
|
||||
.map((item) => item.value);
|
||||
if (!supportedSources.includes(syncRes.data.default_sync_option)) {
|
||||
return false;
|
||||
}
|
||||
ConfigService.setItem(
|
||||
"defaultSyncOption",
|
||||
syncRes.data.default_sync_option
|
||||
|
||||
Reference in New Issue
Block a user