Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/icons/pause.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const PauseIcon = () => (
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="6" y="4" width="2" height="12" rx="1" fill="currentColor" />
<rect x="12" y="4" width="2" height="12" rx="1" fill="currentColor" />
</svg>
);
5 changes: 5 additions & 0 deletions src/components/icons/play.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const PlayIcon = () => (
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M7 4L15 10L7 16V4Z" fill="currentColor" />
</svg>
);
24 changes: 17 additions & 7 deletions src/hooks/sync-sites/sync-sites-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ export function SyncSitesProvider( { children }: { children: React.ReactNode } )
} );

const [ pushStates, setPushStates ] = useState< PushStates >( {} );
const { pushSite, isAnySitePushing, isSiteIdPushing, clearPushState, getPushState, cancelPush } =
useSyncPush( {
pushStates,
setPushStates,
onPushSuccess: ( remoteSiteId, localSiteId ) =>
updateSiteTimestamp( { siteId: remoteSiteId, localSiteId, type: 'push' } ),
} );
const {
pushSite,
isAnySitePushing,
isSiteIdPushing,
clearPushState,
getPushState,
cancelPush,
pauseUpload,
resumeUpload,
} = useSyncPush( {
pushStates,
setPushStates,
onPushSuccess: ( remoteSiteId, localSiteId ) =>
updateSiteTimestamp( { siteId: remoteSiteId, localSiteId, type: 'push' } ),
} );

useListenDeepLinkConnection();

Expand Down Expand Up @@ -145,6 +153,8 @@ export function SyncSitesProvider( { children }: { children: React.ReactNode } )
isSiteIdPushing,
clearPushState,
cancelPush,
pauseUpload,
resumeUpload,
getLastSyncTimeText,
} }
>
Expand Down
34 changes: 33 additions & 1 deletion src/hooks/sync-sites/use-sync-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type UseSyncPushProps = {
};

type CancelPush = ( selectedSiteId: string, remoteSiteId: number ) => void;
type PauseUpload = ( selectedSiteId: string, remoteSiteId: number ) => Promise< boolean >;
type ResumeUpload = ( selectedSiteId: string, remoteSiteId: number ) => Promise< boolean >;

export type UseSyncPush = {
pushStates: PushStates;
Expand All @@ -60,6 +62,8 @@ export type UseSyncPush = {
isSiteIdPushing: IsSiteIdPushing;
clearPushState: ClearState;
cancelPush: CancelPush;
pauseUpload: PauseUpload;
resumeUpload: ResumeUpload;
};

/**
Expand Down Expand Up @@ -349,6 +353,13 @@ export function useSyncPush( {
throw response;
}
} catch ( error ) {
if ( error instanceof Error && error.message === 'Export aborted' ) {
updatePushState( selectedSite.id, remoteSiteId, {
status: pushStatesProgressInfo.cancelled,
} );
return;
}

Sentry.captureException( error );
updatePushState( selectedSite.id, remoteSiteId, {
status: pushStatesProgressInfo.failed,
Expand Down Expand Up @@ -401,14 +412,25 @@ export function useSyncPush( {
] );

useIpcListener(
'sync-upload-paused',
'sync-upload-network-paused',
( _event, payload: { selectedSiteId: string; remoteSiteId: number; error: string } ) => {
updatePushState( payload.selectedSiteId, payload.remoteSiteId, {
status: pushStatesProgressInfo.uploadingPaused,
} );
}
);

useIpcListener(
'sync-upload-manually-paused',
( _event, payload: { selectedSiteId: string; remoteSiteId: number } ) => {
const currentState = getPushState( payload.selectedSiteId, payload.remoteSiteId );
updatePushState( payload.selectedSiteId, payload.remoteSiteId, {
status: pushStatesProgressInfo.uploadingManuallyPaused,
uploadProgress: currentState?.uploadProgress,
} );
}
);

useIpcListener(
'sync-upload-resumed',
( _event, payload: { selectedSiteId: string; remoteSiteId: number } ) => {
Expand Down Expand Up @@ -477,6 +499,14 @@ export function useSyncPush( {
[ __, pushStatesProgressInfo.cancelled, updatePushState ]
);

const pauseUpload = useCallback< PauseUpload >( async ( selectedSiteId, remoteSiteId ) => {
return getIpcApi().pauseSyncUpload( selectedSiteId, remoteSiteId );
}, [] );

const resumeUpload = useCallback< ResumeUpload >( async ( selectedSiteId, remoteSiteId ) => {
return getIpcApi().resumeSyncUpload( selectedSiteId, remoteSiteId );
}, [] );

return {
pushStates,
getPushState,
Expand All @@ -485,5 +515,7 @@ export function useSyncPush( {
isSiteIdPushing,
clearPushState,
cancelPush,
pauseUpload,
resumeUpload,
};
}
2 changes: 2 additions & 0 deletions src/hooks/tests/use-add-site.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ describe( 'useAddSite', () => {
getPushState: jest.fn(),
getLastSyncTimeText: jest.fn(),
cancelPush: jest.fn(),
pauseUpload: jest.fn(),
resumeUpload: jest.fn(),
} as SyncSitesContextType );

mockSetSelectedTab.mockReset();
Expand Down
13 changes: 12 additions & 1 deletion src/hooks/use-sync-states-progress-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export type PushStateProgressInfo = {
| 'finished'
| 'failed'
| 'cancelled'
| 'uploadingPaused';
| 'uploadingPaused'
| 'uploadingManuallyPaused';
progress: number;
message: string;
};
Expand Down Expand Up @@ -87,6 +88,10 @@ function isKeyUploadingPaused( key: PushStateProgressInfo[ 'key' ] | undefined )
return key === 'uploadingPaused';
}

function isKeyUploadingManuallyPaused( key: PushStateProgressInfo[ 'key' ] | undefined ): boolean {
return key === 'uploadingManuallyPaused';
}

function isKeyUploading( key: PushStateProgressInfo[ 'key' ] | undefined ): boolean {
return key === 'uploading';
}
Expand Down Expand Up @@ -186,6 +191,11 @@ export function useSyncStatesProgressInfo() {
progress: 45,
message: __( 'Uploading paused' ),
},
uploadingManuallyPaused: {
key: 'uploadingManuallyPaused',
progress: 45,
message: __( 'Uploading paused' ),
},
creatingRemoteBackup: {
key: 'creatingRemoteBackup',
progress: 50,
Expand Down Expand Up @@ -354,5 +364,6 @@ export function useSyncStatesProgressInfo() {
getPushUploadMessage,
mapUploadProgressToOverallProgress,
isKeyUploadingPaused,
isKeyUploadingManuallyPaused,
};
}
2 changes: 2 additions & 0 deletions src/ipc-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ export {
downloadSyncBackup,
exportSiteForPush,
getConnectedWpcomSites,
pauseSyncUpload,
pushArchive,
removeExportedSiteTmpFile,
removeSyncBackup,
resumeSyncUpload,
updateConnectedWpcomSites,
updateSingleConnectedWpcomSite,
} from 'src/modules/sync/lib/ipc-handlers';
Expand Down
3 changes: 2 additions & 1 deletion src/ipc-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ export interface IpcEvents {
'on-site-create-progress': [ { siteId: string; message: string } ];
'site-context-menu-action': [ { action: string; siteId: string } ];
'site-event': [ SiteEvent ];
'sync-upload-paused': [ { error: string; selectedSiteId: string; remoteSiteId: number } ];
'sync-upload-network-paused': [ { error: string; selectedSiteId: string; remoteSiteId: number } ];
'sync-upload-resumed': [ { selectedSiteId: string; remoteSiteId: number } ];
'sync-upload-progress': [ { selectedSiteId: string; remoteSiteId: number; progress: number } ];
'sync-upload-manually-paused': [ { selectedSiteId: string; remoteSiteId: number } ];
'snapshot-error': [ { operationId: crypto.UUID; data: SnapshotEventData } ];
'snapshot-fatal-error': [ { operationId: crypto.UUID; data: { message: string } } ];
'snapshot-output': [ { operationId: crypto.UUID; data: SnapshotEventData } ];
Expand Down
12 changes: 10 additions & 2 deletions src/lib/active-sync-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export function canCancelPull( key: PullStateProgressInfo[ 'key' ] | undefined )
* Check if a push operation can be cancelled based on its current state.
*/
export function canCancelPush( key: PushStateProgressInfo[ 'key' ] | undefined ): boolean {
const cancellableStateKeys: PushStateProgressInfo[ 'key' ][] = [ 'creatingBackup' ];
const cancellableStateKeys: PushStateProgressInfo[ 'key' ][] = [
'creatingBackup',
'uploading',
'uploadingManuallyPaused',
];
if ( ! key ) {
return false;
}
Expand All @@ -44,7 +48,11 @@ export function canCancelPush( key: PushStateProgressInfo[ 'key' ] | undefined )
* Check if a push operation has finished uploading the backup file.
*/
export function pushBackupIsUploading( key: PushStateProgressInfo[ 'key' ] | undefined ): boolean {
const uploadingStateKeys: PushStateProgressInfo[ 'key' ][] = [ 'creatingBackup', 'uploading' ];
const uploadingStateKeys: PushStateProgressInfo[ 'key' ][] = [
'creatingBackup',
'uploading',
'uploadingManuallyPaused',
];
if ( ! key ) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/modules/add-site/tests/add-site.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ beforeEach( () => {
getPushState: jest.fn(),
getLastSyncTimeText: jest.fn(),
cancelPush: jest.fn(),
pauseUpload: jest.fn(),
resumeUpload: jest.fn(),
} as SyncSitesContextType );
mockSetSelectedTab.mockReset();

Expand Down
Loading