Skip to content

Commit

Permalink
Lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
justin13888 committed Jul 23, 2024
1 parent f34cad6 commit b7624a9
Show file tree
Hide file tree
Showing 14 changed files with 552 additions and 410 deletions.
4 changes: 1 addition & 3 deletions shiba/components/statusbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const SyncStatus: Component<SyncStatusProps> = ({ status }) => {
const colourError = "text-red-500";
return (
<span
class={
`flex flex-row items-center space-x-2 text-xs"`
}
class={`flex flex-row items-center space-x-2 text-xs"`}
aria-label="Sync status"
>
<Switch fallback={<p>Unknown...</p>}>
Expand Down
71 changes: 45 additions & 26 deletions shiba/entrypoints/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,36 @@ export default defineBackground({
logger.debug("Started Shiba background script");

// Do log cleanup
const doLogCleanup = async (
minLogs: number,
minAge: number,
) => {
const doLogCleanup = async (minLogs: number, minAge: number) => {
logger.debug("Cleaning up logs");
const logsDeleted = await cleanupLogs(minLogs, minAge);
logger.debug(`Logs deleted: ${logsDeleted}`);
}
};
const setupLogCleanup = async () => {
logger.debug("Setting up log cleanup");

try {
const logSettings = await loadLoggingSettings();

logger.debug(`Setting up log cleanup interval for ${logSettings.cleanupInterval} minutes`);
setInterval(async () => {
try {
await doLogCleanup(logSettings.minLogs, logSettings.minAge);
} catch (cleanupError) {
logger.error("Error during log cleanup", cleanupError);
}
}, logSettings.cleanupInterval * 60 * 1000);
logger.debug(
`Setting up log cleanup interval for ${logSettings.cleanupInterval} minutes`,
);
setInterval(
async () => {
try {
await doLogCleanup(
logSettings.minLogs,
logSettings.minAge,
);
} catch (cleanupError) {
logger.error(
"Error during log cleanup",
cleanupError,
);
}
},
logSettings.cleanupInterval * 60 * 1000,
);

doLogCleanup(logSettings.minLogs, logSettings.minAge);
} catch (error) {
Expand All @@ -38,36 +46,47 @@ export default defineBackground({
setupLogCleanup();

// Do snapshot generation
const updateSnapshots = async (retentionPolicies: RetentionPolicy[]) => {
const updateSnapshots = async (
retentionPolicies: RetentionPolicy[],
) => {
logger.debug("Updating snapshots");
const newSnapshot = await runSnapshot(retentionPolicies);
if (newSnapshot) {
logger.debug("Snapshot generated", newSnapshot);
} else {
logger.debug("No new snapshot generated");
}
}
};
const setupSnapshots = async () => {
logger.info("Setting up snapshots");
try {
const snapshotSettings = await loadSnapshotSettings();
logger.debug("Snapshot settings", snapshotSettings);

logger.debug(`Setting up snapshot interval for ${snapshotSettings.reconciliationInterval} minutes`);
setInterval(async () => {
try {
await updateSnapshots(snapshotSettings.retentionPolicies);
} catch (snapshotError) {
logger.error("Error during snapshot generation", snapshotError);
}
}, snapshotSettings.reconciliationInterval * 60 * 1000);

logger.debug(
`Setting up snapshot interval for ${snapshotSettings.reconciliationInterval} minutes`,
);
setInterval(
async () => {
try {
await updateSnapshots(
snapshotSettings.retentionPolicies,
);
} catch (snapshotError) {
logger.error(
"Error during snapshot generation",
snapshotError,
);
}
},
snapshotSettings.reconciliationInterval * 60 * 1000,
);

updateSnapshots(snapshotSettings.retentionPolicies);

} catch (error) {
logger.fatal("Failed to setup snapshots", error);
}
}
};
setupSnapshots();
logger.debug("Shiba background script setup complete");
},
Expand Down
9 changes: 2 additions & 7 deletions shiba/entrypoints/debug/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ export const App = () => {
<div class="pb-4 align-middle">
<h1 class="text-4xl font-extrabold">Shiba Debug</h1>
</div>
<Button onClick={addTestLogs}>
Add test logs
</Button>
<Button onClick={addTestLogs}>Add test logs</Button>
<div class="flex flex-col">
<Show
when={logs.state === "ready"}
Expand Down Expand Up @@ -137,10 +135,7 @@ export const App = () => {
</div>
<p>Page count: {page()}</p>
<div class="flex flex-row space-x-6">
<Button
onClick={handlePreviousPage}
disabled={page() === 1}
>
<Button onClick={handlePreviousPage} disabled={page() === 1}>
Previous Page
</Button>
<Button
Expand Down
100 changes: 66 additions & 34 deletions shiba/entrypoints/index/routes/history/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createAsync, Navigate, useParams } from "@solidjs/router";
import { Navigate, createAsync, useParams } from "@solidjs/router";
import { type Component, Show } from "solid-js";

const SnapshotPreview: Component = () => {
Expand All @@ -9,71 +9,98 @@ const SnapshotPreview: Component = () => {
}

const [snapshot, { refetch: snapshotRefetch }] = createResource(
() => id, getSnapshot
() => id,
getSnapshot,
); // TODO: Replace with solid infintie query and virtual
// TODO: Because snapshot could be undefined, errors and loading states both are undefined. (Solve by not using createResource)

// TODO: Display tab group categories properly
return (
<div class="flex min-h-screen w-full flex-col items-center bg-background px-4 py-12 md:px-6">
<div class="w-full max-w-screen-lg space-y-6">
<h1 class="text-3xl font-bold tracking-tighter">Snapshot Preview</h1>
<h1 class="text-3xl font-bold tracking-tighter">
Snapshot Preview
</h1>

<Show
when={snapshot()}
fallback={<p>Loading...</p>} // TODO: Make it look better
>
{(snapshot) => {
// Dictionary of Tab ID to Tab
const tabRecord: Record<string, Tab> = snapshot().tabs.reduce((acc, tab) => {
acc[tab.id] = tab;
return acc;
}, {} as Record<string, Tab>);
const tabRecord: Record<string, Tab> =
snapshot().tabs.reduce(
(acc, tab) => {
acc[tab.id] = tab;
return acc;
},
{} as Record<string, Tab>,
);

// Tab Group sorted in descending order
const tabGroups = snapshot().tabGroups.sort((a, b) => b.timeCreated - a.timeCreated);
const tabGroups = snapshot().tabGroups.sort(
(a, b) => b.timeCreated - a.timeCreated,
);

return (
<>
<h2 class="text-lg font-medium text-gray-600">{snapshot().id}</h2>
<h2 class="text-lg font-medium text-gray-600">
{snapshot().id}
</h2>
<div class="flex flex-col">
<p><strong>Identifier:</strong> {snapshot().identifier}</p>
<p><strong>Timestamp:</strong> {dateFormatter.format(snapshot().timestamp)}</p>
<p><strong>Triggers:</strong> {snapshot().triggers.length > 0 ? snapshot().triggers.join(", ") : "Manual"}</p>
<p>
<strong>Identifier:</strong>{" "}
{snapshot().identifier}
</p>
<p>
<strong>Timestamp:</strong>{" "}
{dateFormatter.format(
snapshot().timestamp,
)}
</p>
<p>
<strong>Triggers:</strong>{" "}
{snapshot().triggers.length > 0
? snapshot().triggers.join(", ")
: "Manual"}
</p>
</div>

<div class="flex flex-grow">
{/* TODO: Replace fallback with loading animation */}
<Switch
fallback={
<div class="flex justify-center w-full">
<p class="text-xl font-medium pt-4">There are no tabs...</p>
<p class="text-xl font-medium pt-4">
There are no tabs...
</p>
</div>
}
>
<Match when={tabGroups.length > 0}>
<div class="flex-col space-y-6">
<For each={tabGroups}>
{(tabGroup) => {
const tabs = tabRecord[tabGroup.groupId];
const tabs =
tabRecord[
tabGroup.groupId
];
// {/* TODO: Display Tab.notes */}
return (
<>
<div class="flex flex-row items-center space-x-4">
<span class="pr-2 align-middle">
{
tabGroup.name ? (
<p class="font-semibold">
{
tabGroup.name
}
</p>
) : (
<p class="font-semibold italic">
Unnamed
</p>
)
}
{tabGroup.name ? (
<p class="font-semibold">
{
tabGroup.name
}
</p>
) : (
<p class="font-semibold italic">
Unnamed
</p>
)}
</span>
<p>
{diffDate(
Expand All @@ -83,8 +110,14 @@ const SnapshotPreview: Component = () => {
</div>
{/* TODO: Display timeCreated */}
<ul class="pl-2 space-y-1">
<For each={tabs}>
{(tab) => (
<For
each={
tabs
}
>
{(
tab,
) => (
<li>
<span class="flex flex-row items-center space-x-4">
<SuspenseImage
Expand Down Expand Up @@ -119,7 +152,7 @@ const SnapshotPreview: Component = () => {
</For>
</ul>
</>
)
);
}}
</For>
</div>
Expand All @@ -128,13 +161,12 @@ const SnapshotPreview: Component = () => {
</div>
</>
// TODO: Implement infinite list
)
);
}}
</Show>

</div>
</div>
)
}
);
};

export default SnapshotPreview;
Loading

0 comments on commit b7624a9

Please sign in to comment.