Skip to content

Commit

Permalink
[desk-tool] Make loading state dependent on connection state
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Feb 19, 2020
1 parent 6415ee7 commit 832b66b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function DocumentStatusBarActionsInner(props: Props) {

export function DocumentStatusBarActions(props: {id: string; type: string}) {
const editState = useEditState(props.id, props.type)
const {isConnected} = useConnectionState(props.id, props.type)
const connectionState = useConnectionState(props.id, props.type)

const [isMenuOpen, setMenuOpen] = React.useState(false)

Expand All @@ -105,7 +105,7 @@ export function DocumentStatusBarActions(props: {id: string; type: string}) {
onActionComplete={() => setMenuOpen(false)}
actions={actions}
actionProps={editState}
disabled={!isConnected}
disabled={connectionState !== 'connected'}
/>
) : null
}
Expand All @@ -120,7 +120,7 @@ const historyActions = [HistoryRestoreAction]

export function HistoryStatusBarActions(props: HistoryStatusBarActionsProps) {
const editState: any = useEditState(props.id, props.type)
const {isConnected} = useConnectionState(props.id, props.type)
const connectionState = useConnectionState(props.id, props.type)

if (!editState) {
return null
Expand All @@ -137,7 +137,7 @@ export function HistoryStatusBarActions(props: HistoryStatusBarActionsProps) {
onActionComplete={() => {
/*todo: make optional*/
}}
disabled={!isConnected || Boolean(disabled)}
disabled={connectionState !== 'connected' || Boolean(disabled)}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ interface Props {

export function SyncState(props: Props) {
const {isSyncing} = useSyncState(props.id, props.type)
const {isConnected} = useConnectionState(props.id, props.type)
const connectionState = useConnectionState(props.id, props.type)

const isConnected = connectionState === 'connected'

const icon = isSyncing || !isConnected ? <SyncIcon /> : <CheckIcon />
const className = isSyncing
Expand Down
14 changes: 6 additions & 8 deletions packages/@sanity/desk-tool/src/pane/DocumentPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ interface Props {
published: null | Doc
draft: null | Doc
value: null | Doc
isLoading: boolean
isConnected: boolean
connectionState: 'connecting' | 'connected' | 'reconnecting'
isSelected: boolean
isCollapsed: boolean
markers: any[]
Expand Down Expand Up @@ -702,7 +701,7 @@ export default class DocumentPane extends React.PureComponent<Props, State> {

renderCurrentView() {
const initialValue = this.getInitialValue()
const {views, options, urlParams, value, onChange, isConnected, markers} = this.props
const {views, options, urlParams, value, onChange, connectionState, markers} = this.props
const {historical, historyState} = this.state

const selectedHistoryEvent = this.findSelectedHistoryEvent()
Expand Down Expand Up @@ -739,7 +738,7 @@ export default class DocumentPane extends React.PureComponent<Props, State> {
const formProps = {
...viewProps,
value: value,
isConnected,
connectionState,
markers,
history: {
isOpen: this.historyIsOpen(),
Expand Down Expand Up @@ -769,12 +768,11 @@ export default class DocumentPane extends React.PureComponent<Props, State> {
render() {
const {
isSelected,
isLoading,
value,
isCollapsed,
isClosable,
onCollapse,
isConnected,
connectionState,
onExpand,
menuItemGroups,
views,
Expand All @@ -790,7 +788,7 @@ export default class DocumentPane extends React.PureComponent<Props, State> {
return this.renderUnknownSchemaType()
}

if (isLoading) {
if (connectionState === 'connecting') {
return (
<div className={documentPaneStyles.loading}>
<Spinner center message={`Loading ${schemaType.title}…`} delay={600} />
Expand Down Expand Up @@ -863,7 +861,7 @@ export default class DocumentPane extends React.PureComponent<Props, State> {
{inspect && !this.historyIsOpen() && value && (
<InspectView value={value} onClose={this.handleHideInspector} />
)}
{!isConnected && (
{connectionState === 'reconnecting' && (
<Snackbar kind="warning" isPersisted title="Connection lost. Reconnecting…" />
)}
<DocumentOperationResults id={options.id} type={options.type} />
Expand Down
5 changes: 2 additions & 3 deletions packages/@sanity/desk-tool/src/pane/DocumentPaneProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const DocumentPaneProvider = withInitialValue((props: Props) => {
const {patch}: any = useDocumentOperation(props.options.id, props.options.type)
const editState: any = useEditState(props.options.id, props.options.type)
const {markers} = useValidationStatus(props.options.id, props.options.type)
const {isConnected} = useConnectionState(props.options.id, props.options.type)
const connectionState = useConnectionState(props.options.id, props.options.type)

const onChange = React.useCallback(
patches => {
Expand All @@ -59,11 +59,10 @@ export const DocumentPaneProvider = withInitialValue((props: Props) => {
{...props}
onChange={onChange}
markers={markers}
isConnected={isConnected}
connectionState={connectionState}
value={value}
draft={editState && editState.draft}
published={editState && editState.published}
isLoading={!editState}
/>
)
})

0 comments on commit 832b66b

Please sign in to comment.