Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New quick command UI and support quick command export/import
- Loading branch information
Showing
7 changed files
with
302 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@require '../../css/includes/theme-default' | ||
.qm-list-wrap | ||
max-height calc(100vh - 100px) | ||
overflow-y scroll | ||
.qm-trigger | ||
color text-disabled | ||
background main-dark |
31 changes: 31 additions & 0 deletions
31
src/client/components/quick-commands/quick-command-item.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* quick commands footer selection | ||
*/ | ||
|
||
import { | ||
PureComponent | ||
} from 'react' | ||
import { | ||
Button | ||
} from 'antd' | ||
|
||
export default class QuickCommandsItem extends PureComponent { | ||
onSelect = (id) => { | ||
this.props.onSelect( | ||
this.props.item.id | ||
) | ||
} | ||
|
||
render () { | ||
const { name, id } = this.props.item | ||
return ( | ||
<Button | ||
key={id} | ||
className='mg1r mg1b' | ||
onClick={this.onSelect} | ||
> | ||
{name} | ||
</Button> | ||
) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/client/components/quick-commands/quick-command-transport-mod.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import BookmarkTransport from '../setting-panel/bookmark-transport' | ||
import download from '../../common/download' | ||
import time from '../../../app/common/time' | ||
import copy from 'json-deep-copy' | ||
|
||
export default class QmTransport extends BookmarkTransport { | ||
beforeUpload = (file) => { | ||
const { store } = this.props | ||
const txt = window.pre | ||
.readFileSync(file.path).toString() | ||
try { | ||
const quickCommands = JSON.parse(txt) | ||
const quickCommandsOld = copy(store.quickCommands) | ||
const bmTreeOld = quickCommandsOld.reduce((p, v) => { | ||
return { | ||
...p, | ||
[v.id]: v | ||
} | ||
}, {}) | ||
const add = [] | ||
const dbAdd = [] | ||
quickCommands.forEach(bg => { | ||
if (!bmTreeOld[bg.id]) { | ||
quickCommandsOld.push(bg) | ||
add.push(bg) | ||
dbAdd.push({ | ||
db: 'quickCommands', | ||
obj: bg | ||
}) | ||
} | ||
}) | ||
store.storeAssign({ | ||
quickCommands: quickCommandsOld | ||
}) | ||
store.batchDbAdd(dbAdd) | ||
} catch (e) { | ||
store.onError(e) | ||
} | ||
return false | ||
} | ||
|
||
down = () => { | ||
const { store } = this.props | ||
const { | ||
quickCommands | ||
} = store | ||
const txt = JSON.stringify(quickCommands, null, 2) | ||
const stamp = time(undefined, 'YYYY-MM-DD-HH-mm-ss') | ||
download('quickCommands-' + stamp + '.json', txt) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/client/components/quick-commands/quick-command-transport.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import QmTransportMod from './quick-command-transport-mod' | ||
import { Component } from '../common/react-subx' | ||
|
||
export default class QmTransport extends Component { | ||
render () { | ||
return ( | ||
<div className='pd1b'> | ||
<QmTransportMod store={this.props.store} /> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.