diff --git a/src/components/button.tsx b/src/components/button.tsx index 806d8d8d..8c929977 100644 --- a/src/components/button.tsx +++ b/src/components/button.tsx @@ -17,7 +17,7 @@ export type ButtonProps = MappedOmit< ComponentProps< typeof Button >, 'variant' tooltipText?: string; }; -type ButtonVariant = 'primary' | 'secondary' | 'tertiary' | 'outlined' | 'link' | 'icon'; +export type ButtonVariant = 'primary' | 'secondary' | 'tertiary' | 'outlined' | 'link' | 'icon'; /** * The arbitrary Tailwind variants below (e.g., `[&.is-secondary]`) are used to diff --git a/src/components/connect-create-buttons.tsx b/src/components/connect-create-buttons.tsx new file mode 100644 index 00000000..b178fe6e --- /dev/null +++ b/src/components/connect-create-buttons.tsx @@ -0,0 +1,65 @@ +import { __ } from '@wordpress/i18n'; +import { cx } from '../lib/cx'; +import { getIpcApi } from '../lib/get-ipc-api'; +import { ArrowIcon } from './arrow-icon'; +import Button, { ButtonVariant } from './button'; +import offlineIcon from './offline-icon'; +import Tooltip from './tooltip'; + +interface ConnectCreateButtonsProps { + connectSite: () => void; + isOffline: boolean; + connectButtonVariant: ButtonVariant; + createButtonVariant: ButtonVariant; + disableConnectButtonStyle?: boolean; +} + +export const ConnectCreateButtons = ( { + connectSite, + isOffline, + createButtonVariant, + connectButtonVariant, + disableConnectButtonStyle, +}: ConnectCreateButtonsProps ) => { + return ( + <> + + + + + + + + ); +}; diff --git a/src/components/content-tab-sync.tsx b/src/components/content-tab-sync.tsx index c4923afd..978cac6b 100644 --- a/src/components/content-tab-sync.tsx +++ b/src/components/content-tab-sync.tsx @@ -6,10 +6,10 @@ import { useSyncSites } from '../hooks/sync-sites'; import { useAuth } from '../hooks/use-auth'; import { SyncSite } from '../hooks/use-fetch-wpcom-sites'; import { useOffline } from '../hooks/use-offline'; -import { cx } from '../lib/cx'; import { getIpcApi } from '../lib/get-ipc-api'; import { ArrowIcon } from './arrow-icon'; import Button from './button'; +import { ConnectCreateButtons } from './connect-create-buttons'; import offlineIcon from './offline-icon'; import { SyncConnectedSites } from './sync-connected-sites'; import { SyncSitesModalSelector } from './sync-sites-modal-selector'; @@ -60,42 +60,16 @@ function CreateConnectSite( { const { __ } = useI18n(); const isOffline = useOffline(); - const offlineMessageCreate = __( 'Creating new site requires an internet connection.' ); - const offlineMessageConnect = __( 'Connecting a site requires an internet connection.' ); - return (
- - - - - - +
); diff --git a/src/components/sync-connected-sites.tsx b/src/components/sync-connected-sites.tsx index ee1a86a8..bfc7bf8f 100644 --- a/src/components/sync-connected-sites.tsx +++ b/src/components/sync-connected-sites.tsx @@ -6,11 +6,15 @@ import { useMemo } from 'react'; import { useSyncSites } from '../hooks/sync-sites'; import { useConfirmationDialog } from '../hooks/use-confirmation-dialog'; import { SyncSite } from '../hooks/use-fetch-wpcom-sites'; +import { useOffline } from '../hooks/use-offline'; import { useSyncStatesProgressInfo } from '../hooks/use-sync-states-progress-info'; +import { cx } from '../lib/cx'; import { getIpcApi } from '../lib/get-ipc-api'; import { ArrowIcon } from './arrow-icon'; import { Badge } from './badge'; import Button from './button'; +import { ConnectCreateButtons } from './connect-create-buttons'; +import offlineIcon from './offline-icon'; import ProgressBar from './progress-bar'; import { SyncPullPushClear } from './sync-pull-push-clear'; import Tooltip from './tooltip'; @@ -35,6 +39,7 @@ export function SyncConnectedSites( { selectedSite: SiteDetails; } ) { const { __ } = useI18n(); + const isOffline = useOffline(); const { pullSite, clearPullState, @@ -224,7 +229,6 @@ export function SyncConnectedSites( { ) } - { pushState.status && pushState.hasFinished && ( clearPushState( selectedSite.id, connectedSite.id ) } @@ -238,37 +242,55 @@ export function SyncConnectedSites( { ! pushState.isInProgress && ! pushState.isError && ! pushState.hasFinished && ( -
- - -
+ +
+ + +
+
) } @@ -279,23 +301,12 @@ export function SyncConnectedSites( {
- - +
); diff --git a/src/components/sync-sites-modal-selector.tsx b/src/components/sync-sites-modal-selector.tsx index 3993c83f..59ea326e 100644 --- a/src/components/sync-sites-modal-selector.tsx +++ b/src/components/sync-sites-modal-selector.tsx @@ -1,13 +1,15 @@ -import { SearchControl as SearchControlWp } from '@wordpress/components'; -import { sprintf } from '@wordpress/i18n'; +import { Icon, SearchControl as SearchControlWp } from '@wordpress/components'; +import { __, sprintf } from '@wordpress/i18n'; import { useI18n } from '@wordpress/react-i18n'; import { useState, useEffect } from 'react'; import { SyncSite } from '../hooks/use-fetch-wpcom-sites'; +import { useOffline } from '../hooks/use-offline'; import { cx } from '../lib/cx'; import { getIpcApi } from '../lib/get-ipc-api'; import { Badge } from './badge'; import Button from './button'; import Modal from './modal'; +import offlineIcon from './offline-icon'; import { WordPressShortLogo } from './wordpress-short-logo'; const SearchControl = process.env.NODE_ENV === 'test' ? () => null : SearchControlWp; @@ -28,6 +30,7 @@ export function SyncSitesModalSelector( { const { __ } = useI18n(); const [ selectedSiteId, setSelectedSiteId ] = useState< number | null >( null ); const [ searchQuery, setSearchQuery ] = useState< string >( '' ); + const isOffline = useOffline(); const filteredSites = syncSites.filter( ( site ) => { const searchQueryLower = searchQuery.toLowerCase(); return ( @@ -49,39 +52,49 @@ export function SyncSitesModalSelector( { onRequestClose={ onRequestClose } title={ __( 'Connect a WordPress.com site' ) } > - -
- { isLoading && ( -
{ __( 'Loading sites…' ) }
- ) } +
+ +
+ { isLoading && ( +
+ { __( 'Loading sites…' ) } +
+ ) } - { ! isLoading && isEmpty && ( -
- { searchQuery - ? sprintf( __( 'No sites found for "%s"' ), searchQuery ) - : __( 'No sites found' ) } -
- ) } + { ! isLoading && isEmpty && ( +
+ { searchQuery + ? sprintf( __( 'No sites found for "%s"' ), searchQuery ) + : __( 'No sites found' ) } +
+ ) } + + { ! isLoading && ! isEmpty && ( + + ) } +
+
{ + if ( ! selectedSiteId ) { + return; + } + onConnect( selectedSiteId ); + onRequestClose(); + } } + disabled={ ! selectedSiteId } + /> - { ! isLoading && ! isEmpty && ( - + { isOffline && ( +
+ +
) }
-
{ - if ( ! selectedSiteId ) { - return; - } - onConnect( selectedSiteId ); - onRequestClose(); - } } - disabled={ ! selectedSiteId } - /> ); } @@ -258,3 +271,14 @@ function Footer( {
); } + +const SyncSitesOfflineView = () => { + const offlineMessage = __( 'Connecting a site requires an internet connection.' ); + + return ( +
+ + { offlineMessage } +
+ ); +};