Skip to content

Commit 7cd1777

Browse files
Add menu refresh functionality to Selection Tools settings
Co-authored-by: PeterDaveHello <[email protected]>
1 parent 06179d9 commit 7cd1777

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/popup/sections/SelectionTools.jsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
44
import { useState } from 'react'
55
import { defaultConfig } from '../../config/index.mjs'
66
import { PencilIcon, TrashIcon } from '@primer/octicons-react'
7+
import Browser from 'webextension-polyfill'
78

89
SelectionTools.propTypes = {
910
config: PropTypes.object.isRequired,
@@ -36,7 +37,7 @@ export function SelectionTools({ config, updateConfig }) {
3637
{t('Cancel')}
3738
</button>
3839
<button
39-
onClick={(e) => {
40+
onClick={async (e) => {
4041
e.preventDefault()
4142
if (!editingTool.name) {
4243
setErrorMessage(t('Name is required'))
@@ -47,14 +48,17 @@ export function SelectionTools({ config, updateConfig }) {
4748
return
4849
}
4950
if (editingIndex === -1) {
50-
updateConfig({
51+
await updateConfig({
5152
customSelectionTools: [...config.customSelectionTools, editingTool],
5253
})
5354
} else {
5455
const customSelectionTools = [...config.customSelectionTools]
5556
customSelectionTools[editingIndex] = editingTool
56-
updateConfig({ customSelectionTools })
57+
await updateConfig({ customSelectionTools })
5758
}
59+
Browser.runtime.sendMessage({
60+
type: 'REFRESH_MENU',
61+
})
5862
setEditing(false)
5963
}}
6064
>
@@ -102,11 +106,14 @@ export function SelectionTools({ config, updateConfig }) {
102106
<input
103107
type="checkbox"
104108
checked={config.activeSelectionTools.includes(key)}
105-
onChange={(e) => {
109+
onChange={async (e) => {
106110
const checked = e.target.checked
107111
const activeSelectionTools = config.activeSelectionTools.filter((i) => i !== key)
108112
if (checked) activeSelectionTools.push(key)
109-
updateConfig({ activeSelectionTools })
113+
await updateConfig({ activeSelectionTools })
114+
Browser.runtime.sendMessage({
115+
type: 'REFRESH_MENU',
116+
})
110117
}}
111118
/>
112119
{t(toolsConfig[key].label)}
@@ -122,10 +129,13 @@ export function SelectionTools({ config, updateConfig }) {
122129
<input
123130
type="checkbox"
124131
checked={tool.active}
125-
onChange={(e) => {
132+
onChange={async (e) => {
126133
const customSelectionTools = [...config.customSelectionTools]
127134
customSelectionTools[index] = { ...tool, active: e.target.checked }
128-
updateConfig({ customSelectionTools })
135+
await updateConfig({ customSelectionTools })
136+
Browser.runtime.sendMessage({
137+
type: 'REFRESH_MENU',
138+
})
129139
}}
130140
/>
131141
{tool.name}
@@ -145,11 +155,14 @@ export function SelectionTools({ config, updateConfig }) {
145155
</div>
146156
<div
147157
style={{ cursor: 'pointer' }}
148-
onClick={(e) => {
158+
onClick={async (e) => {
149159
e.preventDefault()
150160
const customSelectionTools = [...config.customSelectionTools]
151161
customSelectionTools.splice(index, 1)
152-
updateConfig({ customSelectionTools })
162+
await updateConfig({ customSelectionTools })
163+
Browser.runtime.sendMessage({
164+
type: 'REFRESH_MENU',
165+
})
153166
}}
154167
>
155168
<TrashIcon />

0 commit comments

Comments
 (0)