Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/entrypoints/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ import "../app.css";
import { mount } from "svelte";
import GithubPrFilter from "@/entrypoints/content/GithubPRFilter.svelte";
import { logger } from "@/lib/utils/logger";
import { GITHUB_PATTERNS } from "@/lib/constants";

export default defineContentScript({
matches: ["https://github.com/*/*/pulls*"],
matches: [GITHUB_PATTERNS.REPO_PAGE_PATTERN],
main() {
logger.info("GitHub PR Filters Content Script activated");

// Create a container for our component
const container = document.createElement("div");
container.id = "github-pr-filters-container";
document.body.appendChild(container);

// Mount the Svelte component
mount(GithubPrFilter, {
target: container,
});
mount(GithubPrFilter, { target: container });
},
});
4 changes: 1 addition & 3 deletions src/entrypoints/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ if (!appElement) {
throw new Error("Failed to find app element. Cannot mount options page.");
}

mount(Options, {
target: appElement,
});
mount(Options, { target: appElement });
4 changes: 1 addition & 3 deletions src/entrypoints/popup/Popup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

const filterManager = useFilters();

function openOptions() {
browser.runtime.openOptionsPage();
}
const openOptions = () => browser.runtime.openOptionsPage();
</script>

<main class="bg-bg-primary w-72 p-4">
Expand Down
4 changes: 1 addition & 3 deletions src/entrypoints/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ if (!appElement) {
throw new Error("Failed to find app element. Cannot mount popup.");
}

mount(Popup, {
target: appElement,
});
mount(Popup, { target: appElement });
16 changes: 12 additions & 4 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
export const STORAGE_KEYS = {
PR_FILTERS: "prFilters",
PR_FILTERS: "pr_filters",
} as const;

export const GITHUB_PATTERNS = {
// Used by isGitHubPRPage() for PR page validation
PR_PAGE_REGEX: /^https:\/\/github\.com\/[^/]+\/[^/]+\/pulls(\/.*|\?.*)?$/,

// Used by context menu in background.ts so it only shows on PR pages
PR_PAGE_QUERY: "*://github.com/*/*/pulls*",

// Used by content script, matches all github pages to avoid issues with SPA navigation
REPO_PAGE_PATTERN: "https://github.com/*/*",

// Used in background.ts for simple URL checks
PR_PAGE_PARTIAL: "github.com",
PR_PATH_PARTIAL: "/pulls",
} as const;

export const MESSAGE_ACTIONS = {
APPLY_FILTERS: "applyFilters",
APPLY_FILTERS_NOW: "applyFiltersNow",
TOGGLE_FILTER: "toggleFilter",
APPLY_FILTERS: "apply_filters",
APPLY_FILTERS_NOW: "apply_filters_now",
TOGGLE_FILTER: "toggle_filter",
} as const;

export const TOAST_DURATION = {
Expand Down
13 changes: 5 additions & 8 deletions src/lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PRFilter, NewPRFilter } from "@/lib/types/filter";
import { logger } from "@/lib/utils/logger";
import { STORAGE_KEYS } from "@/lib/constants";

export async function saveFilters(filters: PRFilter[]): Promise<void> {
export async function saveFilters(filters: PRFilter[]) {
await browser.storage.sync.set({ [STORAGE_KEYS.PR_FILTERS]: filters });
}

Expand All @@ -13,7 +13,7 @@ export async function getFilters(): Promise<PRFilter[]> {
return data[STORAGE_KEYS.PR_FILTERS] || [];
}

export async function addFilter(filter: NewPRFilter): Promise<PRFilter[]> {
export async function addFilter(filter: NewPRFilter) {
logger.debug("addFilter", filter);

const updatedFilters = [
Expand All @@ -29,10 +29,7 @@ export async function addFilter(filter: NewPRFilter): Promise<PRFilter[]> {
return updatedFilters;
}

/**
* Update an existing filter
*/
export async function updateFilter(filter: PRFilter): Promise<PRFilter[]> {
export async function updateFilter(filter: PRFilter) {
logger.debug("updateFilter", filter);

const filters = await getFilters();
Expand All @@ -44,14 +41,14 @@ export async function updateFilter(filter: PRFilter): Promise<PRFilter[]> {
return updatedFilters;
}

export async function deleteFilter(id: string): Promise<PRFilter[]> {
export async function deleteFilter(id: string) {
const updatedFilters = (await getFilters()).filter((f) => f.id !== id);

await saveFilters(updatedFilters);
return updatedFilters;
}

export async function toggleFilter(id: string): Promise<PRFilter[]> {
export async function toggleFilter(id: string) {
logger.debug("toggleFilter", id);

const updatedFilters = (await getFilters()).map((f) =>
Expand Down
Loading