Improve reset state (#1043)

* add reset settings shortcut

* reset location too

* add integration test
main
Michael Fix 4 years ago committed by GitHub
parent e1225340db
commit 0f8c55e9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,6 @@
// Theirs
import React from 'react'
import Router from 'next/router'
import { useAsyncCallback } from 'actionsack'
import Editor from './Editor'
@ -13,6 +14,7 @@ import { getThemes, saveThemes, clearSettings, saveSettings } from '../lib/util'
function onReset() {
clearSettings()
updateRouteState(Router, {})
if (window.navigator && navigator.serviceWorker) {
navigator.serviceWorker.getRegistrations().then(registrations => {

@ -293,6 +293,13 @@ class Settings extends React.PureComponent {
this.setState({ previousSettings: null })
}
handleOpenAndFocus = () => {
this.props.toggleVisibility()
if (!this.props.isVisible) {
this.menuRef.current.focus()
}
}
handleReset = () => {
this.props.resetDefaultSettings()
this.setState({ previousSettings: null })
@ -413,15 +420,8 @@ class Settings extends React.PureComponent {
return (
<div className="settings-container" ref={this.settingsRef}>
<KeyboardShortcut
trigger="⌘-/"
handle={() => {
toggleVisibility()
if (!isVisible) {
this.menuRef.current.focus()
}
}}
/>
<KeyboardShortcut trigger="⌘-/" handle={this.handleOpenAndFocus} />
<KeyboardShortcut trigger="⇧-⌘-\" handle={this.handleReset} />
<Button
title="Settings Menu"
border

@ -20,6 +20,15 @@ describe('Basic', () => {
cy.contains('.container', '%')
})
it('Should clear editor state with Shift+Cmd+\\', () => {
cy.visit('/?bg=red')
cy.get('body').trigger('keydown', { key: '\\', metaKey: true, shiftKey: true })
cy.location().its('pathname').should('eq', '/')
cy.get('.container-bg .bg').should('have.css', 'background-color', 'rgb(171, 184, 195)')
})
it("Should contain id's for CLI integrations to use", () => {
cy.get('#export-container').should('have.length', 1)
cy.get('.export-container').should('have.length', 1)

Loading…
Cancel
Save