diff --git a/app/background/background.ts b/app/background/background.ts index 9af710f..472f500 100644 --- a/app/background/background.ts +++ b/app/background/background.ts @@ -126,6 +126,7 @@ class BackgroundWorker { this.data[this.currentTab].enabled = false; store.dispatch(toggleListeningRequests(tabId, false)); }; + clearData = (tabId: number) => { this.data[this.currentTab].requests = []; this.updateBadgeText(tabId, 0); diff --git a/app/containers/Popup.tsx b/app/containers/Popup.tsx index 00a22aa..bca14c4 100644 --- a/app/containers/Popup.tsx +++ b/app/containers/Popup.tsx @@ -76,9 +76,8 @@ export class Popup extends React.Component { this.props.clearFields(this.props.currentTab); }; - handleCheckedRequests = (requests: Array): void => { - console.log("handleCheckedRequests :: ", this.props.currentTab, requests); - MessageService.interceptChecked(this.props.currentTab, requests); + handleCheckedRequests = (): void => { + MessageService.interceptChecked(this.props.currentTab); }; disableInterceptor = (tabId: number): void => { diff --git a/app/content/content.ts b/app/content/content.ts index 5445a5a..61e1ff2 100644 --- a/app/content/content.ts +++ b/app/content/content.ts @@ -17,10 +17,10 @@ export interface contentType { [contentType: number]: string; } interface selectedReqs { - interceptEnabledForTab: boolean; + interceptEnabledForTab?: boolean; checkedTabRecords: any; requestsToIntercept: Array; - tabId: number; + tabId?: number; } export type GenericCallbackWithoutParams = () => void; class Intercept { @@ -35,11 +35,25 @@ class Intercept { startMessageListener = () => { this.store.ready().then(() => { chrome.runtime.onMessage.addListener(request => { - this.interceptSelected(request.message, request.tabId); + switch (request.message) { + case "CLEAR_DATA": + this.clearAll(); + break; + + default: + this.interceptSelected(request.message, request.tabId); + } }); }); }; + clearAll = () => { + this.runInterceptor({ + requestsToIntercept: [], + checkedTabRecords: [] + }); + }; + interceptSelected = (message: string, tabId: number) => { const presentState = this.store.getState().rootReducer.tabRecord[tabId]; if (!presentState) { diff --git a/app/message_service.ts b/app/message_service.ts index bf8d546..03a4f72 100644 --- a/app/message_service.ts +++ b/app/message_service.ts @@ -11,12 +11,12 @@ export function disableLogging(tabId: number) { export function clearData(tabId: number) { chrome.runtime.sendMessage({ message: "CLEAR_DATA", tabId }); + chrome.tabs.sendMessage(tabId, { message: "CLEAR_DATA" }); } -export function interceptChecked(tabId: number, requests: Array) { +export function interceptChecked(tabId: number) { chrome.tabs.sendMessage(tabId, { message: "INTERCEPT_CHECKED", - requestsToIntercept: requests, tabId }); } diff --git a/app/reducers/rootReducer.ts b/app/reducers/rootReducer.ts index 5ac2b5d..00768fc 100644 --- a/app/reducers/rootReducer.ts +++ b/app/reducers/rootReducer.ts @@ -126,7 +126,8 @@ export const reducer = (state = INITIAL_POPUP_STATE, action: Action) => { }); case actionType.CLEAR_REQUESTS: return extendTabRecords(state, action.payload, { - requests: [] + requests: [], + requestRecords: {} }); case actionType.TOGGLE_CHECKBOX: return extendTabRecords(state, action.payload, {