Skip to content

Commit

Permalink
Fixing import order
Browse files Browse the repository at this point in the history
  • Loading branch information
justin13888 committed Oct 26, 2024
1 parent a0597f8 commit 67c8149
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
3 changes: 2 additions & 1 deletion shiba/entrypoints/index/routes/saved.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from "solid-js";
import { browser } from "wxt/browser";

// TODO: Make entire page layout not scrollable besides the interior list
// TODO: Implement style
// TODO: Implement search bar
const Saved: Component = () => {
Expand Down Expand Up @@ -121,7 +122,6 @@ interface TabGroupProps {
}

function TabGroupList({ tabGroup, tabGroupsRefetch }: TabGroupProps) {
console.log("tabGroup", tabGroup);
const tabsQuery = createQuery(() => ({
queryKey: ["tabs", tabGroup.id],
queryFn: () => getTabsById(tabGroup.id),
Expand Down Expand Up @@ -291,6 +291,7 @@ function TabGroupList({ tabGroup, tabGroupsRefetch }: TabGroupProps) {
{(tab) => (
// TODO: Make this draggable and optimistically update tab order (need to implement updateTab function)
<li class="group">
{/* TODO: move group to something tighter */}
<span class="flex flex-row items-center space-x-4">
<SuspenseImage
src={tab.favicon}
Expand Down
2 changes: 1 addition & 1 deletion shiba/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class TabGroup {
this.id = groupId || nanoid();
this.name = name;
this.timeCreated = timeCreated || Date.now();
this.timeModified = timeModified || this.timeCreated;
this.timeModified = timeModified || this.timeCreated; // TODO: make sure any function updating this also updates timeModified
this.categories = categories || [];
}
}
Expand Down
2 changes: 1 addition & 1 deletion shiba/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface TabDB extends DBSchema {
value: Tab;
indexes: {
byGroupId: string;
byGroupIdOrder: string;
byGroupIdOrder: [string, number];
};
// TODO: Enforce foreign key constraint for groupId
};
Expand Down
2 changes: 1 addition & 1 deletion shiba/utils/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export async function addSeedTabs() {

queryClient.invalidateQueries({
queryKey: ["tabgroups"],
});
}); // TODO: Figure out why dependent components are not re-rendering
tabDBRefetch(); // TODO: Replace this
await switchToOrOpenTab(URLS.SAVED);
}
15 changes: 13 additions & 2 deletions shiba/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,20 @@ export const getTabsById = async (tabGroupId: string): Promise<Tab[]> => {
const db = await dbPromise;
const tx = db.transaction("tabs", "readonly");
const store = tx.objectStore("tabs");
const index = store.index("byGroupId");
const index = store.index("byGroupIdOrder");
const range = IDBKeyRange.bound([tabGroupId, -Infinity], [tabGroupId, Infinity]);
const items = [];

return index.getAll(IDBKeyRange.only(tabGroupId));
let cursor = await index.openCursor(range);

while (cursor) {
items.push(cursor.value);
cursor = await cursor.continue();
}

await tx.done;

return items;
};

/**
Expand Down
17 changes: 13 additions & 4 deletions shiba/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ export const parseOneTabUrl = (input: string): TabBundle[] => {

const lines = input.split("\n");
const groups: TabBundle[] = [];
let currentGroup: TabGroup = new TabGroup();
const currentTime = Date.now();
let i = 0;
let currentGroup: TabGroup = new TabGroup({
timeCreated: currentTime,
});
let currentTabs: Tab[] = [];
let order = 0;

let lineCount = 0;
for (const line of lines) {
Expand All @@ -38,9 +43,12 @@ export const parseOneTabUrl = (input: string): TabBundle[] => {
if (l === "") {
if (currentTabs.length > 0) {
groups.push([currentGroup, currentTabs]);
i++;
currentGroup = new TabGroup({
timeCreated: currentTime - i,
});
currentTabs = [];
}
currentGroup = new TabGroup();
currentTabs = [];
} else {
// Line should be of format: "url | title"
// Note: title can contain "|"
Expand All @@ -62,10 +70,11 @@ export const parseOneTabUrl = (input: string): TabBundle[] => {
const tab: Tab = {
id: nanoid(),
groupId: currentGroup.id,
order: 0,
order,
title: trimmedTitle,
url: trimmedUrl,
};
order++;
currentTabs.push(tab);
}
}
Expand Down

0 comments on commit 67c8149

Please sign in to comment.