Skip to content

Commit

Permalink
[components] Make duplicate types of Snackbars to be disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
saasen committed May 19, 2020
1 parent c756e0f commit f58525a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/@sanity/base/src/components/DevServerStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class DevServerStatus extends PureComponent {
title={<strong>Reload required!</strong>}
subtitle={<div>To see your latest changes, you need to reload the browser window.</div>}
action={{title: 'Reload', callback: () => window.location.reload()}}
allowDuplicateSnackbarType
/>
)
}
Expand All @@ -104,6 +105,7 @@ class DevServerStatus extends PureComponent {
</div>
</Spinner>
}
allowDuplicateSnackbarType
/>
)
}
Expand Down Expand Up @@ -135,6 +137,7 @@ class DevServerStatus extends PureComponent {
project folder.
</div>
}
allowDuplicateSnackbarType
/>
)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@sanity/components/src/snackbar/DefaultSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class DefaultSnackbar extends React.PureComponent {
onAction: PropTypes.func,
actionTitle: PropTypes.string,
timeout: PropTypes.number,
preventDuplicate: PropTypes.bool
allowDuplicateSnackbarType: PropTypes.bool
}

static contextTypes = {
Expand All @@ -45,7 +45,7 @@ export default class DefaultSnackbar extends React.PureComponent {
onAction,
isPersisted,
isCloseable,
preventDuplicate
allowDuplicateSnackbarType
} = this.props

return {
Expand All @@ -61,7 +61,7 @@ export default class DefaultSnackbar extends React.PureComponent {
isPersisted,
isCloseable,
autoDismissTimeout: timeout,
preventDuplicate
allowDuplicateSnackbarType
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class SnackbarProvider extends React.Component {
...contextSnack
}

if (newSnack.preventDuplicate) {
if (!newSnack.allowDuplicateSnackbarType) {
const isInQueue = this.snackQueue.findIndex(snack => snack.kind === newSnack.kind) > -1
const isInActive = activeSnacks.findIndex(snack => snack.kind === newSnack.kind) > -1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ export const DocumentOperationResults = React.memo((props: Props) => {
{event.error.message}
</details>
}
preventDuplicate
/>
)
}

if (event && event.type === 'success' && !IGNORE_OPS.includes(event.op)) {
return <Snackbar key={Math.random()} kind="success" title={getOpSuccessTitle(event.op)} preventDuplicate />
return <Snackbar key={Math.random()} kind="success" title={getOpSuccessTitle(event.op)} />
}

return null
Expand Down

0 comments on commit f58525a

Please sign in to comment.