kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Improve selectProtocol logic
rodzic
0d69d27b1c
commit
4c765990f6
|
@ -108,12 +108,25 @@ const search_filter = createSlice({
|
||||||
selectProtocol: (state, action: PayloadAction<string>) => {
|
selectProtocol: (state, action: PayloadAction<string>) => {
|
||||||
const protocol = action.payload;
|
const protocol = action.payload;
|
||||||
return state.map((currentState) => {
|
return state.map((currentState) => {
|
||||||
const newStatus = !currentState.status;
|
|
||||||
if (currentState.value.toLowerCase() !== protocol) return currentState;
|
if (currentState.value.toLowerCase() !== protocol) return currentState;
|
||||||
|
|
||||||
|
const newStatus = !currentState.status;
|
||||||
|
let newValue = currentState.value;
|
||||||
|
|
||||||
|
if (newStatus) {
|
||||||
|
newValue = currentState.value.startsWith('-')
|
||||||
|
? currentState.value.slice(1)
|
||||||
|
: currentState.value;
|
||||||
|
} else {
|
||||||
|
newValue = currentState.value.startsWith('-')
|
||||||
|
? currentState.value
|
||||||
|
: `-${currentState.value}`;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...currentState,
|
...currentState,
|
||||||
status: newStatus,
|
status: newStatus,
|
||||||
value: newStatus ? currentState.value.slice(1) : `-${currentState.value}`,
|
value: newValue,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Ładowanie…
Reference in New Issue