Skip to content

Commit

Permalink
feat(resources): copy storage, cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jan 19, 2023
1 parent 66a40dc commit 5dd2396
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/Resources/Cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import map from 'licia/map'
import trim from 'licia/trim'
import isNull from 'licia/isNull'
import each from 'licia/each'
import copy from 'licia/copy'
import LunaModal from 'luna-modal'
import LunaDataGrid from 'luna-data-grid'
import { setState, getState } from './util'
Expand Down Expand Up @@ -72,6 +73,9 @@ export default class Cookie {
<div class="btn show-detail btn-disabled">
<span class="icon icon-eye"></span>
</div>
<div class="btn copy-cookie btn-disabled">
<span class="icon icon-copy"></span>
</div>
<div class="btn delete-cookie btn-disabled">
<span class="icon icon-delete"></span>
</div>
Expand All @@ -93,14 +97,17 @@ export default class Cookie {
const $container = this._$container
const $showDetail = $container.find(c('.show-detail'))
const $deleteCookie = $container.find(c('.delete-cookie'))
const $copyCookie = $container.find(c('.copy-cookie'))
const btnDisabled = c('btn-disabled')

$showDetail.addClass(btnDisabled)
$deleteCookie.addClass(btnDisabled)
$copyCookie.addClass(btnDisabled)

if (this._selectedItem) {
$showDetail.rmClass(btnDisabled)
$deleteCookie.rmClass(btnDisabled)
$copyCookie.rmClass(btnDisabled)
}
}
_getVal(key) {
Expand Down Expand Up @@ -144,6 +151,11 @@ export default class Cookie {
showSources('raw', val)
}
})
.on('click', c('.copy-cookie'), () => {
const key = this._selectedItem
copy(this._getVal(key))
devtools.notify('Copied')
})
.on('click', c('.filter'), () => {
LunaModal.prompt('Filter').then((filter) => {
if (isNull(filter)) return
Expand Down
23 changes: 18 additions & 5 deletions src/Resources/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import LunaModal from 'luna-modal'
import LunaDataGrid from 'luna-data-grid'
import isNull from 'licia/isNull'
import trim from 'licia/trim'
import copy from 'licia/copy'
import { safeStorage, classPrefix as c } from '../lib/util'

export default class Storage {
Expand Down Expand Up @@ -87,14 +88,17 @@ export default class Storage {
const $container = this._$container
const $showDetail = $container.find(c('.show-detail'))
const $deleteStorage = $container.find(c('.delete-storage'))
const $copyStorage = $container.find(c('.copy-storage'))
const btnDisabled = c('btn-disabled')

$showDetail.addClass(btnDisabled)
$deleteStorage.addClass(btnDisabled)
$copyStorage.addClass(btnDisabled)

if (this._selectedItem) {
$showDetail.rmClass(btnDisabled)
$deleteStorage.rmClass(btnDisabled)
$copyStorage.rmClass(btnDisabled)
}
}
_initTpl() {
Expand All @@ -110,6 +114,9 @@ export default class Storage {
<div class="btn show-detail btn-disabled">
<span class="icon icon-eye"></span>
</div>
<div class="btn copy-storage btn-disabled">
<span class="icon icon-copy"></span>
</div>
<div class="btn delete-storage btn-disabled">
<span class="icon icon-delete"></span>
</div>
Expand All @@ -127,6 +134,11 @@ export default class Storage {
this._$dataGrid = $container.find(c('.data-grid'))
this._$filterText = $container.find(c('.filter-text'))
}
_getVal(key) {
return this._type === 'local'
? localStorage.getItem(key)
: sessionStorage.getItem(key)
}
_bindEvent() {
const type = this._type
const devtools = this._devtools
Expand All @@ -148,18 +160,19 @@ export default class Storage {
})
.on('click', c('.show-detail'), () => {
const key = this._selectedItem

const val =
type === 'local'
? localStorage.getItem(key)
: sessionStorage.getItem(key)
const val = this._getVal(key)

try {
showSources('object', JSON.parse(val))
} catch (e) {
showSources('raw', val)
}
})
.on('click', c('.copy-storage'), () => {
const key = this._selectedItem
copy(this._getVal(key))
devtools.notify('Copied')
})
.on('click', c('.filter'), () => {
LunaModal.prompt('Filter').then((filter) => {
if (isNull(filter)) return
Expand Down

0 comments on commit 5dd2396

Please sign in to comment.