Skip to content

Commit 4f15e5a

Browse files
committed
Data stays filtered after new actions get posted
1 parent fbe7e53 commit 4f15e5a

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/app/components/App.jsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,31 @@ class App extends Component {
6565
// adds listener to the effects that are gonna be sent from
6666
// our edited useReducer from the 'react' library.
6767
chrome.runtime.onConnect.addListener((port) => {
68-
if (port.name === 'injected-app') {
69-
this.portToExtension = port;
70-
71-
port.onMessage.addListener((msg) => {
72-
const newData = {
73-
action: msg.action,
74-
state: msg.state,
75-
id: this.state.data.length,
76-
};
77-
this.setState((state) => ({
68+
if (port.name !== 'injected-app') return;
69+
70+
this.portToExtension = port;
71+
72+
port.onMessage.addListener((msg) => {
73+
const newData = {
74+
action: msg.action,
75+
state: msg.state,
76+
id: this.state.data.length,
77+
};
78+
79+
const { searchField } = this.state;
80+
const newDataActionType = newData.action.type.toLowerCase();
81+
82+
if (newDataActionType.includes(searchField.toLowerCase())) {
83+
this.setState(state => ({
7884
data: [...state.data, newData],
7985
filteredData: [...state.data, newData],
8086
}));
81-
});
82-
}
87+
} else {
88+
this.setState(state => ({
89+
data: [...state.data, newData],
90+
}));
91+
}
92+
});
8393
});
8494

8595
// We listen to the message from devtools.js (sent originally from
@@ -94,8 +104,6 @@ class App extends Component {
94104
});
95105
}
96106

97-
98-
99107
// functionality to change 'play' button to 'stop'
100108
setIsPlaying() {
101109
if (this.state.isPlayingIndex > this.state.data.length - 1) {

0 commit comments

Comments
 (0)