Skip to content

Commit e2e124b

Browse files
committed
prettier
1 parent 27a63fe commit e2e124b

File tree

12 files changed

+12
-90
lines changed

12 files changed

+12
-90
lines changed

apps/loom-importer-extension/src/background.ts

+2-24
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { getServerBaseUrl, CapUrls } from "./utils/urls";
1717

1818
const baseUrl = getServerBaseUrl();
1919

20-
// Check for authentication token
2120
async function checkAuthToken(): Promise<string | null> {
2221
try {
2322
const cookie = await chrome.cookies.get({
@@ -41,13 +40,11 @@ async function checkAuthToken(): Promise<string | null> {
4140
}
4241
}
4342

44-
// Verify token freshness and update if needed
4543
async function verifyTokenFreshness(): Promise<void> {
4644
try {
4745
const data = await chrome.storage.local.get("authData");
4846
const authData = data.authData as AuthResponse | undefined;
4947

50-
// If no token exists or token is older than 1 minute, refresh it
5148
if (!authData?.timestamp || Date.now() - authData.timestamp > 60000) {
5249
await checkAuthToken();
5350
}
@@ -56,7 +53,6 @@ async function verifyTokenFreshness(): Promise<void> {
5653
}
5754
}
5855

59-
// Redirect to login if needed
6056
async function redirectToLogin(): Promise<void> {
6157
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
6258
const currentTab = tabs[0];
@@ -65,7 +61,6 @@ async function redirectToLogin(): Promise<void> {
6561
}
6662
}
6763

68-
// Listen for cookie changes
6964
chrome.cookies.onChanged.addListener(async (changeInfo: CookieChangeInfo) => {
7065
if (
7166
changeInfo.cookie.domain.includes(baseUrl) &&
@@ -83,13 +78,9 @@ chrome.cookies.onChanged.addListener(async (changeInfo: CookieChangeInfo) => {
8378
}
8479
});
8580

86-
// Check token freshness periodically
87-
setInterval(verifyTokenFreshness, 30000); // Check every 30 seconds
88-
89-
// Forward checklist messages to popup
81+
setInterval(verifyTokenFreshness, 30000);
9082
function forwardToPopup(message: ImportMessage): void {
9183
try {
92-
// chrome.runtime.sendMessage returns void in MV3, not a Promise
9384
chrome.runtime.sendMessage(message, (response) => {
9485
if (chrome.runtime.lastError) {
9586
console.warn(
@@ -106,17 +97,14 @@ function forwardToPopup(message: ImportMessage): void {
10697
}
10798
}
10899

109-
// Store message listeners to avoid duplication
110100
const messageListeners = new Map();
111101

112-
// Handle messages from content scripts and popup
113102
chrome.runtime.onMessage.addListener(
114103
(
115104
request: { action?: string; type?: string; [key: string]: any },
116105
sender: chrome.runtime.MessageSender,
117106
sendResponse: (response: any) => void
118107
) => {
119-
// Handle auth status requests from popup
120108
if (request.action === "getAuthStatus") {
121109
verifyTokenFreshness()
122110
.then(() => checkAuthToken())
@@ -130,26 +118,21 @@ chrome.runtime.onMessage.addListener(
130118
console.error("Error getting auth status:", error);
131119
sendResponse({ token: null, error: String(error) });
132120
});
133-
return true; // Required for async response
121+
return true;
134122
}
135123

136-
// Handle checklist messages from content scripts
137124
if (request.type && request.type.startsWith("CAP_")) {
138-
// Log all Cap messages for debugging
139125
console.log(`Received Cap message: ${request.type}`, request);
140126

141-
// Store selected videos in local storage
142127
if (request.type === "CAP_LOOM_VIDEOS_SELECTED" && request.videos) {
143128
chrome.storage.local.set({ selectedVideos: request.videos });
144129

145-
// Create a copy of the message to avoid mutation issues
146130
const capMessage: ImportMessage = {
147131
type: request.type,
148132
videos: [...request.videos],
149133
};
150134
forwardToPopup(capMessage);
151135
} else if (request.type) {
152-
// Forward all other Cap messages to the popup, ensuring type is defined
153136
const capMessage: ImportMessage = {
154137
type: request.type,
155138
...request,
@@ -165,18 +148,13 @@ chrome.runtime.onMessage.addListener(
165148
}
166149
);
167150

168-
// Allow external extensions to communicate with this extension
169151
chrome.runtime.onMessageExternal.addListener(
170152
(
171153
request: { type: string; [key: string]: any },
172154
sender: chrome.runtime.MessageSender,
173155
sendResponse: (response: any) => void
174156
) => {
175-
// Verify the sender is trusted if needed
176-
// if (sender.id !== TRUSTED_EXTENSION_ID) return false;
177-
178157
if (request.type && request.type.startsWith("CAP_")) {
179-
// Make a copy of the message with a guaranteed type property
180158
const capMessage: ImportMessage = {
181159
...request,
182160
};

apps/loom-importer-extension/src/content_scripts/App.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import "./App.css";
33
import { ImportProvider, useImport } from "../context/ImportContext";
44
import ImportProgress from "../components/ImportProgress";
55

6-
// The inner App component that uses context
76
const AppContent: React.FC = () => {
87
const { importState, processVideos } = useImport();
98
const { currentPage } = importState;
109

11-
// Don't render anything if we're not on a relevant page
1210
if (currentPage === "other") return null;
1311

1412
return (
@@ -23,7 +21,6 @@ const AppContent: React.FC = () => {
2321
);
2422
};
2523

26-
// The main App component that provides context
2724
function App() {
2825
return (
2926
<ImportProvider>

apps/loom-importer-extension/src/context/ImportContext.tsx

+1-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { LoomExportData } from "../types/loom";
33
import * as LoomScraper from "../services/loomScraper";
44
import { ImportStep, useImportStore } from "../store/importStore";
55

6-
export { ImportStep }; // Re-export for backward compatibility
7-
6+
export { ImportStep };
87
export interface ImportState {
98
currentStep: ImportStep;
109
error: string | null;
@@ -22,44 +21,36 @@ interface ImportContextType {
2221
resetImport: () => void;
2322
}
2423

25-
// Create context with a default undefined value
2624
const ImportContext = createContext<ImportContextType | undefined>(undefined);
2725

2826
export const ImportProvider: React.FC<{ children: ReactNode }> = ({
2927
children,
3028
}) => {
31-
// Use the Zustand store
3229
const store = useImportStore();
3330

34-
// Initialize page detection
3531
useEffect(() => {
3632
store.initializePageDetection();
3733
}, []);
3834

39-
// Load existing data
4035
useEffect(() => {
4136
store.loadExistingData();
4237
}, [store.currentPage]);
4338

44-
// Setup member scraping
4539
useEffect(() => {
4640
const cleanup = store.setupMemberScraping();
4741
return cleanup;
4842
}, [store.currentPage, store.currentStep, store.data]);
4943

50-
// Setup workspace detection
5144
useEffect(() => {
5245
const cleanup = store.setupWorkspaceDetection();
5346
return cleanup;
5447
}, [store.currentPage, store.currentStep]);
5548

56-
// Setup video selection
5749
useEffect(() => {
5850
const cleanup = store.setupVideoSelection();
5951
return cleanup;
6052
}, [store.currentPage, store.currentStep]);
6153

62-
// Create an object that matches the original context shape
6354
const importContextValue: ImportContextType = {
6455
importState: {
6556
currentStep: store.currentStep,
@@ -80,7 +71,6 @@ export const ImportProvider: React.FC<{ children: ReactNode }> = ({
8071
);
8172
};
8273

83-
// Hook to use the import context
8474
export const useImport = (): ImportContextType => {
8575
const context = useContext(ImportContext);
8676
if (context === undefined) {

apps/loom-importer-extension/src/hooks/useAuth.ts

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export function useAuth() {
2020
user: null,
2121
});
2222

23-
// Memoize the API instance to prevent it from causing re-renders
2423
const api = useMemo(() => new CapApi(), []);
2524

2625
const fetchUserData = useCallback(async () => {
@@ -103,7 +102,6 @@ export function useAuth() {
103102
console.error("Error in useAuth:", error);
104103
}
105104

106-
// Cleanup function to prevent state updates if the component unmounts
107105
return () => {
108106
isMounted = false;
109107
};

apps/loom-importer-extension/src/hooks/useWorkspaces.ts

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export function useWorkspaces(isAuthenticated: boolean) {
1212
const [isError, setIsError] = useState(false);
1313
const [status, setStatus] = useState("");
1414

15-
// Memoize the API instance to prevent it from causing re-renders
1615
const api = useMemo(() => new CapApi(), []);
1716

1817
useEffect(() => {
@@ -35,7 +34,6 @@ export function useWorkspaces(isAuthenticated: boolean) {
3534

3635
fetchWorkspaces();
3736

38-
// Cleanup function to prevent state updates if the component unmounts
3937
return () => {
4038
isMounted = false;
4139
};

apps/loom-importer-extension/src/popup/popup.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ const PopupContent = () => {
5757
};
5858

5959
const handleEmailSelected = (email: string) => {
60-
// Call setSelectedUserEmail directly
6160
setSelectedUserEmail(email);
6261
};
6362

@@ -75,7 +74,6 @@ const PopupContent = () => {
7574
}
7675
};
7776

78-
// Get the checklist items using the centralized utility
7977
const checklistItems = getChecklistItemsForStep(importState.currentStep);
8078

8179
return (

apps/loom-importer-extension/src/services/loomScraper.ts

-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { LoomExportData, Video, WorkspaceMember } from "../types/loom";
22
import { waitForElement } from "../utils/dom";
33
import JSConfetti from "js-confetti";
44

5-
// Page types
65
export type LoomPage = "members" | "workspace" | "other";
76

87
/**
@@ -39,13 +38,11 @@ export const loadExistingData = (): Promise<LoomExportData | null> => {
3938
* Scrapes workspace members from the Loom members page
4039
*/
4140
export const scrapeWorkspaceMembers = async (): Promise<WorkspaceMember[]> => {
42-
// Wait for the table to load
4341
const tableElement = await waitForElement('div[role="table"]');
4442
if (!tableElement) {
4543
throw new Error("Table element not found");
4644
}
4745

48-
// Give it a bit more time to ensure data is fully loaded
4946
await new Promise((resolve) => setTimeout(resolve, 1000));
5047

5148
const members: WorkspaceMember[] = [];
@@ -119,20 +116,17 @@ export const saveMembersToStorage = async (
119116
export const setupVideoSelection = async (
120117
onSelectionChange: (hasSelectedVideos: boolean) => void
121118
): Promise<() => void> => {
122-
// Wait for video elements
123119
const videoElement = await waitForElement("article[data-videoid]");
124120
if (!videoElement) {
125121
throw new Error("No videos found on page");
126122
}
127123

128-
// Use Loom's native checkboxes
129124
const articles = document.querySelectorAll<HTMLElement>(
130125
"article[data-videoid]"
131126
);
132127

133128
const listeners: { element: HTMLElement; listener: EventListener }[] = [];
134129

135-
// Add event listeners to all checkboxes
136130
articles.forEach((article) => {
137131
const videoId = article.getAttribute("data-videoid");
138132
if (!videoId) return;
@@ -143,20 +137,17 @@ export const setupVideoSelection = async (
143137
if (!checkbox) return;
144138

145139
const listener = () => {
146-
// Check if any videos are selected
147140
const anyVideoSelected = Array.from(
148141
document.querySelectorAll<HTMLInputElement>('input[id^="bulk-action-"]')
149142
).some((cb) => cb.checked);
150143

151-
// Call the callback with the result
152144
onSelectionChange(anyVideoSelected);
153145
};
154146

155147
checkbox.addEventListener("change", listener);
156148
listeners.push({ element: checkbox, listener });
157149
});
158150

159-
// Return a cleanup function to remove all event listeners
160151
return () => {
161152
listeners.forEach(({ element, listener }) => {
162153
element.removeEventListener("change", listener);
@@ -215,7 +206,6 @@ export const processVideos = (
215206
workspaceMembers: WorkspaceMember[]
216207
): Video[] => {
217208
return rawVideos.map((video) => {
218-
// Find the workspace member that matches the owner name
219209
const owner = workspaceMembers.find((member) =>
220210
member.name.includes(video.ownerName)
221211
) || { name: video.ownerName, email: "" };
@@ -242,7 +232,6 @@ export const saveProcessedVideos = async (
242232

243233
return new Promise((resolve) => {
244234
chrome.storage.local.set({ loomImportData: updatedData }, () => {
245-
// Notify extension that import is complete
246235
chrome.runtime.sendMessage({
247236
type: "CAP_LOOM_IMPORT_COMPLETE",
248237
data: updatedData,
@@ -263,16 +252,13 @@ export const completeVideoImport = async (
263252
currentData: LoomExportData
264253
): Promise<LoomExportData> => {
265254
try {
266-
// Get selected videos
267255
const rawVideos = getSelectedVideos();
268256

269-
// Process videos
270257
const processedVideos = processVideos(
271258
rawVideos,
272259
currentData.workspaceMembers
273260
);
274261

275-
// Save videos
276262
return await saveProcessedVideos(currentData, processedVideos);
277263
} catch (error) {
278264
console.error("Failed to process videos:", error);

0 commit comments

Comments
 (0)