mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 18:03:50 +00:00
fix bug of not dispatching when type in the field in FilterInput component
This commit is contained in:
parent
6def195743
commit
ac66678b4d
@ -42,7 +42,9 @@ describe('option actions', () => {
|
|||||||
describe('sendUpdate', () => {
|
describe('sendUpdate', () => {
|
||||||
|
|
||||||
it('should handle error', async () => {
|
it('should handle error', async () => {
|
||||||
global.fetch = () => Promise.reject("fooerror");
|
let mockResponse = { status: 404, text: "fooerror" },
|
||||||
|
promise = Promise.resolve(mockResponse)
|
||||||
|
global.fetch = r => { return promise }
|
||||||
await store.dispatch(OptionsActions.pureSendUpdate("bar", "error"))
|
await store.dispatch(OptionsActions.pureSendUpdate("bar", "error"))
|
||||||
expect(store.getActions()).toEqual([
|
expect(store.getActions()).toEqual([
|
||||||
OptionsEditorActions.updateError("bar", "fooerror")
|
OptionsEditorActions.updateError("bar", "fooerror")
|
||||||
|
@ -10,7 +10,7 @@ type FilterInputProps = {
|
|||||||
color: any
|
color: any
|
||||||
placeholder: string
|
placeholder: string
|
||||||
value: string
|
value: string
|
||||||
onChange: (value) => void
|
onChange: (value) => { type: string, filter?: string, highlight?: string } | void
|
||||||
}
|
}
|
||||||
|
|
||||||
type FilterInputState = {
|
type FilterInputState = {
|
||||||
|
@ -43,24 +43,26 @@ function InterceptInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function FlowFilterInput() {
|
function FlowFilterInput() {
|
||||||
const value = useAppSelector(state => state.flows.filter)
|
const dispatch = useAppDispatch(),
|
||||||
|
value = useAppSelector(state => state.flows.filter)
|
||||||
return <FilterInput
|
return <FilterInput
|
||||||
value={value || ""}
|
value={value || ""}
|
||||||
placeholder="Search"
|
placeholder="Search"
|
||||||
type="search"
|
type="search"
|
||||||
color='black'
|
color='black'
|
||||||
onChange={setFilter}
|
onChange={value => dispatch(setFilter(value))}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
function HighlightInput() {
|
function HighlightInput() {
|
||||||
const value = useAppSelector(state => state.flows.highlight)
|
const dispatch = useAppDispatch(),
|
||||||
|
value = useAppSelector(state => state.flows.highlight)
|
||||||
return <FilterInput
|
return <FilterInput
|
||||||
value={value || ""}
|
value={value || ""}
|
||||||
placeholder="Highlight"
|
placeholder="Highlight"
|
||||||
type="tag"
|
type="tag"
|
||||||
color='hsl(48, 100%, 50%)'
|
color='hsl(48, 100%, 50%)'
|
||||||
onChange={setHighlight}
|
onChange={value => dispatch(setHighlight(value))}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,14 +36,14 @@ const reducer: Reducer<OptionsState> = (state = defaultState, action) => {
|
|||||||
}
|
}
|
||||||
export default reducer
|
export default reducer
|
||||||
|
|
||||||
export function pureSendUpdate(option: Option, value, dispatch) {
|
export function pureSendUpdate(option: Option, value) {
|
||||||
return async dispatch => {
|
return async dispatch => {
|
||||||
try {
|
try {
|
||||||
const response = await fetchApi.put('/options', {[option]: value});
|
const response = await fetchApi.put('/options', {[option]: value});
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
dispatch(optionsEditorActions.updateSuccess(option))
|
dispatch(optionsEditorActions.updateSuccess(option))
|
||||||
} else {
|
} else {
|
||||||
throw await response.text()
|
throw await response.text
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return dispatch(optionsEditorActions.updateError(option, error))
|
return dispatch(optionsEditorActions.updateError(option, error))
|
||||||
@ -51,12 +51,12 @@ export function pureSendUpdate(option: Option, value, dispatch) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sendUpdate = _.throttle(pureSendUpdate, 500, {leading: true, trailing: true})
|
|
||||||
|
|
||||||
export function update(name: Option, value: any): AppThunk {
|
export function update(name: Option, value: any): AppThunk {
|
||||||
|
let sendUpdate = _.throttle(pureSendUpdate(name, value), 500, {leading: true, trailing: true})
|
||||||
|
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(optionsEditorActions.startUpdate(name, value))
|
dispatch(optionsEditorActions.startUpdate(name, value))
|
||||||
sendUpdate(name, value, dispatch);
|
sendUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ export function fetchApi(url: string, options: RequestInit = {}): Promise<Respon
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchApi.put = (url: string, json: any, options: RequestInit) => fetchApi(
|
fetchApi.put = (url: string, json: any, options: RequestInit = {}) => fetchApi(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
Loading…
Reference in New Issue
Block a user