This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MessageRate } from "../../types/message.types" | |
import { ratingMessageHandler } from "./onMessageHandlers/ratingMessageHandler" | |
export function messageHandler( | |
message: Message, | |
sender: chrome.runtime.MessageSender, | |
sendResponse: SendResponseCallback, | |
) { | |
if (sender.tab && message.type) { | |
switch (message.type) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MessageRate } from "../../../types/message.types" | |
async function updateCacheRating( | |
sendResponse: SendResponseCallback, | |
data?: MessageRate, | |
): Promise<void> { | |
if (typeof data?.url === "string") { | |
try { | |
await chrome.storage.local.set({ [data.url]: data.rate }) | |
return sendResponse({ statusCode: 200 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable @typescript-eslint/no-explicit-any */ | |
import { JestChrome } from "jest-chrome/types/jest-chrome" | |
import { sendMessage } from "./sendMessage" | |
describe("sendMessage", () => { | |
it("should send the message correctly", async () => { | |
const message: Message = { type: "rating", subType: "get" } | |
const response: MessageResponse = { statusCode: 200, data: 2 } | |
const jestChrome = chrome as any as JestChrome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MessageRate } from "../../../types/message.types" | |
import { sendMessage } from "../../messages/sendMessage" | |
import { clearUrlParams } from "../..//utils/url" | |
import "./Rating.css" | |
import { useCallback, useEffect, useState } from "react" | |
const totalRating = Array.from({ length: 5 }, (_, index) => index + 1) | |
export function Rating() { | |
const [rating, setRating] = useState<number>(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initMessageHandler() { | |
// ... | |
useEffect(() => { | |
// Listening for updates by the service worker | |
chrome.runtime.onMessage.addListener(handleMessageListener); | |
return () => { | |
chrome.runtime.onMessage.removeListener(handleMessageListener); | |
}; | |
}, []); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function updateLanguage(language: LanguagesSupported) { | |
chrome.storage.local.set({ language }); | |
broadcastMessageAllTabs({ | |
type: "languageUpdated", | |
data: { | |
language: language, | |
translations: i18n.getDataByLanguage(language), | |
}, | |
}); | |
} |