Skip to content

Commit 99c13ae

Browse files
committed
final cleanup I think
1 parent f76fadc commit 99c13ae

15 files changed

Lines changed: 152 additions & 298 deletions

File tree

entrypoints/popup-app/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Degree Audit Plus</title>
7-
<meta name="manifest.type" content="browser_action" />
87
</head>
98
<body
109
style="

entrypoints/popup-ui.content.tsx

Lines changed: 0 additions & 180 deletions
This file was deleted.

features/audit-scraping/background-controller.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ export class AuditBatchController {
110110
} finally {
111111
await this.dependencies.closeWindow();
112112
await this.dependencies.broadcast("complete");
113-
console.log(
114-
`Audit batch complete: ${result.succeeded.length} succeeded, ${result.failed.length} failed`,
115-
result,
116-
);
113+
const summary = `Audit batch complete: ${result.succeeded.length} succeeded, ${result.failed.length} failed`;
114+
if (result.failed.length) {
115+
console.warn(summary, result);
116+
} else if (import.meta.env.DEV) {
117+
console.log(summary, result);
118+
}
117119
}
118120

119121
return result;
@@ -238,12 +240,6 @@ function clickRunAuditButton(retry = false): void {
238240
}
239241

240242
function registerAuditNavigationHandlers(): void {
241-
browser.action.onClicked.addListener((tab) => {
242-
if (tab.id !== undefined) {
243-
void sendTabMessage(tab.id, { type: "TOGGLE_POPUP" }).catch(() => {});
244-
}
245-
});
246-
247243
browser.runtime.onMessage.addListener(
248244
(message: ExtensionMessage, _sender, sendResponse) => {
249245
if (message.type === "OPEN_DEGREE_AUDIT") {

features/audit-scraping/scraper-window.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@ export async function getOrCreateScraperWindow(): Promise<number> {
8888
}
8989
}
9090

91-
console.log(`[Scraper] Created minimized window: ${scraperWindowId}`);
91+
if (import.meta.env.DEV) {
92+
console.log(`[Scraper] Created minimized window: ${scraperWindowId}`);
93+
}
9294
return scraperWindowId;
9395
}
9496

9597
export async function closeScraperWindow(): Promise<void> {
9698
if (scraperWindowId !== null) {
97-
console.log(`[Scraper] Closing window: ${scraperWindowId}`);
99+
if (import.meta.env.DEV) {
100+
console.log(`[Scraper] Closing window: ${scraperWindowId}`);
101+
}
98102
await browser.windows.remove(scraperWindowId).catch(() => {});
99103
scraperWindowId = null;
100104
}
@@ -145,7 +149,7 @@ export async function createScraperTab(
145149
// Safety timeout
146150
const timeoutId = setTimeout(() => {
147151
if (!isResolved) {
148-
console.log(`[Scraper] Timeout for tab ${tabId}, closing`);
152+
console.warn(`[Scraper] Timeout for tab ${tabId}, closing`);
149153
cleanup();
150154
if (tabId) {
151155
browser.tabs.remove(tabId).catch(() => {});

features/audit/audit-provider.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import {
1717
calculateWeightedDegreeCompletion,
1818
getCompositeAuditRequirements,
1919
} from "@/lib/audit-calculations";
20-
import { formatMajorLabel } from "@/lib/utils";
2120
import {
2221
getAuditData,
2322
getAuditHistory,
2423
renameAudit,
2524
saveAuditData,
25+
watchAuditHistory,
2626
} from "@/lib/storage/audit-storage";
2727
import { createContext, useContext, useEffect, useMemo, useState } from "react";
2828
import LoadingPage from "./components/loading-page";
@@ -84,7 +84,7 @@ export function AuditContextProvider({
8484
[currentAuditId, history],
8585
);
8686
const currentAuditName =
87-
currentAudit.majors?.map(formatMajorLabel).join("; ") ??
87+
currentAudit.majors?.join("; ") ??
8888
currentAudit.title ??
8989
"Degree Requirements";
9090
const compositeAuditData = useMemo<CompositeAuditData>(
@@ -122,6 +122,12 @@ export function AuditContextProvider({
122122
[courseMap],
123123
);
124124

125+
useEffect(() => {
126+
return watchAuditHistory((storedHistory) => {
127+
if (storedHistory) setHistory(storedHistory);
128+
});
129+
}, []);
130+
125131
useEffect(() => {
126132
let cancelled = false;
127133
setLoaded(false);
@@ -203,7 +209,12 @@ export function AuditContextProvider({
203209
},
204210
addPlannedCourse: async (course, requirementTitle, ruleTitle) => {
205211
if (!auditData || !currentAuditId) return null;
206-
const result = addCourse(auditData, course, requirementTitle, ruleTitle);
212+
const result = addCourse(
213+
auditData,
214+
course,
215+
requirementTitle,
216+
ruleTitle,
217+
);
207218
if (!result) return null;
208219
await persist(currentAuditId, result.audit);
209220
return result.courseId;
@@ -224,7 +235,9 @@ export function AuditContextProvider({
224235

225236
if (!loaded || !currentAuditId || !history) return <LoadingPage />;
226237

227-
return <AuditContext.Provider value={value}>{children}</AuditContext.Provider>;
238+
return (
239+
<AuditContext.Provider value={value}>{children}</AuditContext.Provider>
240+
);
228241
}
229242

230243
export function useAuditContext(): AuditContextValue {

features/audit/components/navbar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IconButton } from "@/components/ui/button";
22
import { HStack, VStack } from "@/components/ui/stack";
33
import { usePreferences } from "@/features/preferences/preferences-provider";
44
import { useAuditContext } from "../audit-provider";
5-
import { cn, formatMajorLabel } from "@/lib/utils";
5+
import { cn } from "@/lib/utils";
66
import {
77
ExportIcon,
88
MoonIcon,
@@ -66,12 +66,12 @@ const Navbar = () => {
6666
<HStack gap={2} y="middle" className="flex-wrap">
6767
{majors.map((m, i) => (
6868
<span
69-
key={`${formatMajorLabel(m)}-${i}`}
69+
key={`${m}-${i}`}
7070
className={`inline-flex items-center rounded-[6px] px-2.5 py-[3px] text-[12px] font-medium leading-none ${
7171
MAJOR_TAG_STYLES[i % MAJOR_TAG_STYLES.length]
7272
}`}
7373
>
74-
{formatMajorLabel(m)}
74+
{m}
7575
</span>
7676
))}
7777
</HStack>

features/banner/try-dap-banner.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { getAuditHistory } from "@/lib/storage/audit-storage";
1+
import {
2+
getAuditHistory,
3+
watchAuditHistory,
4+
} from "@/lib/storage/audit-storage";
5+
import type { AuditHistoryData } from "@/domain/audit";
26
import { sendRuntimeMessage } from "@/lib/browser/messages";
37
import { XIcon } from "@phosphor-icons/react";
48
import { useEffect, useState } from "react";
@@ -14,24 +18,14 @@ const TryDAPBanner = () => {
1418
);
1519

1620
useEffect(() => {
17-
getAuditHistory()
18-
.then((data) => {
19-
setFirstAuditId(data?.audits?.[0]?.auditId);
20-
})
21-
.catch(() => {});
22-
23-
const storageListener = (
24-
changes: Record<string, { newValue?: unknown }>,
25-
) => {
26-
if (changes["auditHistory"]?.newValue) {
27-
const data = changes["auditHistory"].newValue as {
28-
audits?: { auditId?: string }[];
29-
};
30-
setFirstAuditId(data?.audits?.[0]?.auditId);
31-
}
21+
const updateFirstAudit = (data: AuditHistoryData | null) => {
22+
setFirstAuditId(data?.audits[0]?.auditId);
3223
};
33-
browser.storage.onChanged.addListener(storageListener);
34-
return () => browser.storage.onChanged.removeListener(storageListener);
24+
25+
void getAuditHistory()
26+
.then(updateFirstAudit)
27+
.catch(() => {});
28+
return watchAuditHistory(updateFirstAudit);
3529
}, []);
3630

3731
const handleClose = () => {

0 commit comments

Comments
 (0)