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
478 changes: 35 additions & 443 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion entrypoints/options/hooks/useToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const useToast = () => {

// Auto-dismiss after 4 seconds
useEffect(() => {
if (toasts.length === 0) return;
const latest = toasts[toasts.length - 1];
if (!latest) return;
const timer = setTimeout(() => remove(latest.id), 4000);
return () => clearTimeout(timer);
}, [toasts, remove]);
Expand Down
8 changes: 5 additions & 3 deletions lib/bookmarks/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export const getAllFolders = async (): Promise<BookmarkFolder[]> => {
export const getFolderById = async (id: string): Promise<BookmarkFolder | null> => {
try {
const nodes = await browser.bookmarks.get(id);
if (nodes.length === 0 || nodes[0].url) return null;
return { id: nodes[0].id, title: nodes[0].title, path: nodes[0].title };
const node = nodes[0];
if (!node || node.url) return null;
return { id: node.id, title: node.title, path: node.title };
} catch {
return null;
}
Expand All @@ -56,7 +57,8 @@ export const getFolderById = async (id: string): Promise<BookmarkFolder | null>
export const folderExists = async (id: string): Promise<boolean> => {
try {
const nodes = await browser.bookmarks.get(id);
return nodes.length > 0 && !nodes[0].url;
const node = nodes[0];
return node !== undefined && !node.url;
} catch {
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/github/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ export const fetchLatestCommitSha = async (

const raw: unknown = await response.json();
const commits = v.parse(v.array(CommitListItemSchema), raw);
if (commits.length === 0) {
const latest = commits[0];
if (!latest) {
throw new Error("No commits found for the specified path");
}

return commits[0].sha;
return latest.sha;
};

export type ManifestLocation = {
Expand Down
17 changes: 10 additions & 7 deletions lib/storage/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export const getConnections = async (): Promise<Connection[]> => {
.then((r) => (r[LOCAL_STATE_KEY] ?? {}) as LocalConnectionStateStore),
]);

return Object.entries(configs)
.filter(([id]) => id in states)
.map(([id, config]) => ({ ...config, ...states[id] }));
return Object.entries(configs).flatMap(([id, config]) => {
const state = states[id];
return state ? [{ ...config, ...state }] : [];
});
};

export const saveConnection = async (connection: Connection): Promise<void> => {
Expand Down Expand Up @@ -109,17 +110,19 @@ const omitKeys = <T extends Record<string, unknown>, K extends keyof T>(
const updateSyncConfig = async (id: string, updates: Partial<ConnectionConfig>): Promise<void> => {
await browser.storage.sync.get(SYNC_KEY).then((result) => {
const configs = (result[SYNC_KEY] ?? {}) as SyncConnectionsStore;
if (!(id in configs)) return;
configs[id] = { ...configs[id], ...updates };
const current = configs[id];
if (!current) return;
configs[id] = { ...current, ...updates };
return browser.storage.sync.set({ [SYNC_KEY]: configs });
});
};

const updateLocalState = async (id: string, updates: Partial<ConnectionState>): Promise<void> => {
await browser.storage.local.get(LOCAL_STATE_KEY).then((result) => {
const states = (result[LOCAL_STATE_KEY] ?? {}) as LocalConnectionStateStore;
if (!(id in states)) return;
states[id] = { ...states[id], ...updates };
const current = states[id];
if (!current) return;
states[id] = { ...current, ...updates };
return browser.storage.local.set({ [LOCAL_STATE_KEY]: states });
});
};
Expand Down
11 changes: 6 additions & 5 deletions lib/storage/orphan-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ const createFolderAtPath = async (pathString: string): Promise<string> => {
const parts = pathString.split(" > ").filter(Boolean);
if (parts.length === 0) throw new Error("Invalid folder path");

const rootChildren = tree[0].children ?? [];
const rootFolder = rootChildren.find((c) => c.title === parts[0]);
const [rootTitle, ...subfolderNames] = parts;
const rootChildren = tree[0]?.children ?? [];
const rootFolder = rootChildren.find((c) => c.title === rootTitle);

if (!rootFolder?.id) {
throw new Error(`Root folder not found: ${parts[0]}`);
throw new Error(`Root folder not found: ${rootTitle}`);
}

let currentId = rootFolder.id;

for (let i = 1; i < parts.length; i++) {
currentId = await getOrCreateFolder(currentId, parts[i]);
for (const name of subfolderNames) {
currentId = await getOrCreateFolder(currentId, name);
}

return currentId;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"oxlint": "1.83.0",
"oxlint-tsgolint": "7.0.2002",
"typescript": "7.0.2",
"wxt": "0.20.26"
"wxt": "0.21.4"
}
}