initial commit
This commit is contained in:
commit
7e466e29d2
28 changed files with 17360 additions and 0 deletions
35
utils/blocked-site-repo.ts
Normal file
35
utils/blocked-site-repo.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import type { BlockedSite } from "./types"
|
||||
import type { ExtensionDatabase } from "./database"
|
||||
|
||||
export interface BlockedSitesRepo {
|
||||
getAll(): Promise<BlockedSite[]>
|
||||
getOne(id: string): Promise<BlockedSite | undefined>
|
||||
insert(input: BlockedSite): Promise<void>
|
||||
update(input: BlockedSite): Promise<void>
|
||||
delete(input: BlockedSite): Promise<void>
|
||||
}
|
||||
|
||||
export function createBlockedSitesRepo(_db: Promise<ExtensionDatabase>): BlockedSitesRepo {
|
||||
return {
|
||||
async getAll() {
|
||||
const db = await _db;
|
||||
return await db.getAll("blocked_sites");
|
||||
},
|
||||
async getOne(id) {
|
||||
const db = await _db;
|
||||
return await db.get("blocked_sites", id);
|
||||
},
|
||||
async insert(input) {
|
||||
const db = await _db;
|
||||
await db.add("blocked_sites", input)
|
||||
},
|
||||
async update(input) {
|
||||
const db = await _db;
|
||||
await db.put("blocked_sites", input)
|
||||
},
|
||||
async delete(input) {
|
||||
const db = await _db;
|
||||
await db.delete("blocked_sites", input.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
utils/database.ts
Normal file
24
utils/database.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { DBSchema, IDBPDatabase, openDB } from "idb";
|
||||
import { Todo, BlockedSite } from "./types";
|
||||
|
||||
interface ExtensionDatabaseScheme extends DBSchema {
|
||||
todos: {
|
||||
key: string;
|
||||
value: Todo;
|
||||
};
|
||||
blocked_sites: {
|
||||
key: string;
|
||||
value: BlockedSite;
|
||||
};
|
||||
}
|
||||
|
||||
export type ExtensionDatabase = IDBPDatabase<ExtensionDatabaseScheme>;
|
||||
|
||||
export function openExtensionDatabase(): Promise<ExtensionDatabase> {
|
||||
return openDB<ExtensionDatabaseScheme>("let-me-focus", 1, {
|
||||
upgrade(database) {
|
||||
database.createObjectStore("todos", { keyPath: "id" });
|
||||
database.createObjectStore("blocked_sites", { keyPath: "id" });
|
||||
},
|
||||
});
|
||||
}
|
||||
6
utils/proxy-service-keys.ts
Normal file
6
utils/proxy-service-keys.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import type { ProxyServiceKey } from "@webext-core/proxy-service";
|
||||
import type { BlockedSitesRepo } from "./blocked-site-repo";
|
||||
import type { TodosRepo } from "./todo-repo";
|
||||
|
||||
export const BLOCKED_SITES_REPO_KEY = 'blocked-sites-repo' as ProxyServiceKey<BlockedSitesRepo>;
|
||||
export const TODOS_REPO_KEY = 'todos-repo' as ProxyServiceKey<TodosRepo>;
|
||||
5
utils/storage.ts
Normal file
5
utils/storage.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { storage } from "#imports"
|
||||
|
||||
export const featureEnableBlock = storage.defineItem<boolean>("local:enableBlock", {
|
||||
fallback: false
|
||||
})
|
||||
35
utils/todo-repo.ts
Normal file
35
utils/todo-repo.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import type { Todo } from "./types"
|
||||
import type { ExtensionDatabase } from "./database"
|
||||
|
||||
export interface TodosRepo {
|
||||
getAll(): Promise<Todo[]>
|
||||
getOne(id: string): Promise<Todo | undefined>
|
||||
insert(input: Todo): Promise<void>
|
||||
update(input: Todo): Promise<void>
|
||||
delete(input: Todo): Promise<void>
|
||||
}
|
||||
|
||||
export function createTodosRepo(_db: Promise<ExtensionDatabase>): TodosRepo {
|
||||
return {
|
||||
async getAll() {
|
||||
const db = await _db;
|
||||
return await db.getAll("todos");
|
||||
},
|
||||
async getOne(id) {
|
||||
const db = await _db;
|
||||
return await db.get("todos", id);
|
||||
},
|
||||
async insert(input) {
|
||||
const db = await _db;
|
||||
await db.add("todos", input)
|
||||
},
|
||||
async update(input) {
|
||||
const db = await _db;
|
||||
await db.put("todos", input)
|
||||
},
|
||||
async delete(input) {
|
||||
const db = await _db;
|
||||
await db.delete("todos", input.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
11
utils/types.ts
Normal file
11
utils/types.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
export interface Todo {
|
||||
id: string;
|
||||
name: string;
|
||||
completed: boolean;
|
||||
}
|
||||
|
||||
export interface BlockedSite {
|
||||
id: string;
|
||||
url: string;
|
||||
blocked: boolean;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue