mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Improved accepting a folder share
This commit is contained in:
parent
0175348868
commit
8ada059401
@ -75,6 +75,7 @@ interface Props {
|
||||
shareInvitations: ShareInvitation[];
|
||||
isSafeMode: boolean;
|
||||
needApiAuth: boolean;
|
||||
processingShareInvitationResponse: boolean;
|
||||
}
|
||||
|
||||
interface ShareFolderDialogOptions {
|
||||
@ -197,6 +198,7 @@ class MainScreenComponent extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
private showShareInvitationNotification(props: Props): boolean {
|
||||
if (props.processingShareInvitationResponse) return false;
|
||||
return !!props.shareInvitations.find(i => i.status === 0);
|
||||
}
|
||||
|
||||
@ -546,8 +548,16 @@ class MainScreenComponent extends React.Component<Props, State> {
|
||||
};
|
||||
|
||||
const onInvitationRespond = async (shareUserId: string, accept: boolean) => {
|
||||
await ShareService.instance().respondInvitation(shareUserId, accept);
|
||||
await ShareService.instance().refreshShareInvitations();
|
||||
// The below functions can take a bit of time to complete so in the
|
||||
// meantime we hide the notification so that the user doesn't click
|
||||
// multiple times on the Accept link.
|
||||
ShareService.instance().setProcessingShareInvitationResponse(true);
|
||||
try {
|
||||
await ShareService.instance().respondInvitation(shareUserId, accept);
|
||||
await ShareService.instance().refreshShareInvitations();
|
||||
} finally {
|
||||
ShareService.instance().setProcessingShareInvitationResponse(false);
|
||||
}
|
||||
void reg.scheduleSync(1000);
|
||||
};
|
||||
|
||||
@ -853,6 +863,7 @@ const mapStateToProps = (state: AppState) => {
|
||||
mainLayout: state.mainLayout,
|
||||
startupPluginsLoaded: state.startupPluginsLoaded,
|
||||
shareInvitations: state.shareService.shareInvitations,
|
||||
processingShareInvitationResponse: state.shareService.processingShareInvitationResponse,
|
||||
isSafeMode: state.settings.isSafeMode,
|
||||
needApiAuth: state.needApiAuth,
|
||||
showInstallTemplatesPlugin: state.hasLegacyTemplates && !state.pluginService.plugins['joplin.plugin.templates'],
|
||||
|
@ -200,6 +200,13 @@ export default class ShareService {
|
||||
return this.api().exec('GET', 'api/share_users');
|
||||
}
|
||||
|
||||
public setProcessingShareInvitationResponse(v: boolean) {
|
||||
this.store.dispatch({
|
||||
type: 'SHARE_INVITATION_RESPONSE_PROCESSING',
|
||||
value: v,
|
||||
});
|
||||
}
|
||||
|
||||
public async respondInvitation(shareUserId: string, accept: boolean) {
|
||||
if (accept) {
|
||||
await this.api().exec('PATCH', `api/share_users/${shareUserId}`, null, { status: 1 });
|
||||
|
@ -38,6 +38,7 @@ export interface State {
|
||||
shares: StateShare[];
|
||||
shareUsers: Record<string, StateShareUser>;
|
||||
shareInvitations: ShareInvitation[];
|
||||
processingShareInvitationResponse: boolean;
|
||||
}
|
||||
|
||||
export const stateRootKey = 'shareService';
|
||||
@ -46,6 +47,7 @@ export const defaultState: State = {
|
||||
shares: [],
|
||||
shareUsers: {},
|
||||
shareInvitations: [],
|
||||
processingShareInvitationResponse: false,
|
||||
};
|
||||
|
||||
export function isSharedFolderOwner(state: RootState, folderId: string): boolean {
|
||||
@ -82,6 +84,11 @@ const reducer = (draftRoot: Draft<RootState>, action: any) => {
|
||||
draft.shareInvitations = action.shareInvitations;
|
||||
break;
|
||||
|
||||
case 'SHARE_INVITATION_RESPONSE_PROCESSING':
|
||||
|
||||
draft.processingShareInvitationResponse = action.value;
|
||||
break;
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
error.message = `In share reducer: ${error.message} Action: ${JSON.stringify(action)}`;
|
||||
|
Loading…
Reference in New Issue
Block a user