Skip to content

Commit ea72d11

Browse files
authored
Fix/spa navigation (#4)
* fix: support SPA navigation by matching all GitHub repo pages * refactor: remove redundant Promise return type annotations * style: simplify mount calls and arrow function syntax
1 parent f3c36f4 commit ea72d11

6 files changed

Lines changed: 23 additions & 27 deletions

File tree

src/entrypoints/content.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ import "../app.css";
22
import { mount } from "svelte";
33
import GithubPrFilter from "@/entrypoints/content/GithubPRFilter.svelte";
44
import { logger } from "@/lib/utils/logger";
5+
import { GITHUB_PATTERNS } from "@/lib/constants";
56

67
export default defineContentScript({
7-
matches: ["https://github.com/*/*/pulls*"],
8+
matches: [GITHUB_PATTERNS.REPO_PAGE_PATTERN],
89
main() {
910
logger.info("GitHub PR Filters Content Script activated");
1011

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

16-
// Mount the Svelte component
17-
mount(GithubPrFilter, {
18-
target: container,
19-
});
16+
mount(GithubPrFilter, { target: container });
2017
},
2118
});

src/entrypoints/options/options.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ if (!appElement) {
88
throw new Error("Failed to find app element. Cannot mount options page.");
99
}
1010

11-
mount(Options, {
12-
target: appElement,
13-
});
11+
mount(Options, { target: appElement });

src/entrypoints/popup/Popup.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
55
const filterManager = useFilters();
66
7-
function openOptions() {
8-
browser.runtime.openOptionsPage();
9-
}
7+
const openOptions = () => browser.runtime.openOptionsPage();
108
</script>
119

1210
<main class="bg-bg-primary w-72 p-4">

src/entrypoints/popup/popup.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ if (!appElement) {
88
throw new Error("Failed to find app element. Cannot mount popup.");
99
}
1010

11-
mount(Popup, {
12-
target: appElement,
13-
});
11+
mount(Popup, { target: appElement });

src/lib/constants.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
export const STORAGE_KEYS = {
2-
PR_FILTERS: "prFilters",
2+
PR_FILTERS: "pr_filters",
33
} as const;
44

55
export const GITHUB_PATTERNS = {
6+
// Used by isGitHubPRPage() for PR page validation
67
PR_PAGE_REGEX: /^https:\/\/github\.com\/[^/]+\/[^/]+\/pulls(\/.*|\?.*)?$/,
8+
9+
// Used by context menu in background.ts so it only shows on PR pages
710
PR_PAGE_QUERY: "*://github.com/*/*/pulls*",
11+
12+
// Used by content script, matches all github pages to avoid issues with SPA navigation
13+
REPO_PAGE_PATTERN: "https://github.com/*/*",
14+
15+
// Used in background.ts for simple URL checks
816
PR_PAGE_PARTIAL: "github.com",
917
PR_PATH_PARTIAL: "/pulls",
1018
} as const;
1119

1220
export const MESSAGE_ACTIONS = {
13-
APPLY_FILTERS: "applyFilters",
14-
APPLY_FILTERS_NOW: "applyFiltersNow",
15-
TOGGLE_FILTER: "toggleFilter",
21+
APPLY_FILTERS: "apply_filters",
22+
APPLY_FILTERS_NOW: "apply_filters_now",
23+
TOGGLE_FILTER: "toggle_filter",
1624
} as const;
1725

1826
export const TOAST_DURATION = {

src/lib/storage.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { PRFilter, NewPRFilter } from "@/lib/types/filter";
22
import { logger } from "@/lib/utils/logger";
33
import { STORAGE_KEYS } from "@/lib/constants";
44

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

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

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

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

32-
/**
33-
* Update an existing filter
34-
*/
35-
export async function updateFilter(filter: PRFilter): Promise<PRFilter[]> {
32+
export async function updateFilter(filter: PRFilter) {
3633
logger.debug("updateFilter", filter);
3734

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

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

5047
await saveFilters(updatedFilters);
5148
return updatedFilters;
5249
}
5350

54-
export async function toggleFilter(id: string): Promise<PRFilter[]> {
51+
export async function toggleFilter(id: string) {
5552
logger.debug("toggleFilter", id);
5653

5754
const updatedFilters = (await getFilters()).map((f) =>

0 commit comments

Comments
 (0)