1
0
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:
Laurent Cozic 2021-09-25 18:00:43 +01:00
parent 0175348868
commit 8ada059401
3 changed files with 27 additions and 2 deletions

View File

@ -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'],

View File

@ -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 });

View File

@ -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)}`;