From d3b071a968b3ac24e033a81991e6ef482414cfca Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Wed, 4 Dec 2024 04:20:36 +0100 Subject: [PATCH] chore: improvement --- deno.json | 1 + deno.lock | 11 ++ routes/repository.ts | 16 ++- src/App.svelte | 83 ++---------- src/lib/components/table/table.svelte | 2 +- src/lib/functions/debounce.ts | 4 +- src/lib/pages/docs/get.svelte | 108 +++++++--------- src/lib/pages/docs/page.svelte | 26 ++-- src/lib/pages/docs/search.svelte | 14 +- src/lib/pages/home/page.svelte | 177 ++++++++++++++------------ src/lib/pages/home/table.svelte | 112 ++++++++-------- src/lib/pages/other/page.svelte | 13 +- src/lib/pages/shared/sidebar.svelte | 56 ++++++++ src/lib/types/repository.ts | 2 +- 14 files changed, 315 insertions(+), 310 deletions(-) create mode 100644 src/lib/pages/shared/sidebar.svelte diff --git a/deno.json b/deno.json index 427b648..85db2d7 100644 --- a/deno.json +++ b/deno.json @@ -25,6 +25,7 @@ "autoprefixer": "npm:autoprefixer@^10.4.20", "bits-ui": "npm:bits-ui@^0.21.16", "clsx": "npm:clsx@^2.1.1", + "detect-url-change": "npm:detect-url-change@^1.0.2", "lucide-svelte": "npm:lucide-svelte@^0.462.0", "mode-watcher": "npm:mode-watcher@^0.5.0", "postcss": "npm:postcss@^8.4.49", diff --git a/deno.lock b/deno.lock index a94e8cf..31e12f4 100644 --- a/deno.lock +++ b/deno.lock @@ -23,6 +23,7 @@ "npm:autoprefixer@^10.4.20": "10.4.20_postcss@8.4.49", "npm:bits-ui@~0.21.16": "0.21.16_svelte@5.2.10__acorn@8.14.0", "npm:clsx@^2.1.1": "2.1.1", + "npm:detect-url-change@^1.0.2": "1.0.2", "npm:hono-rate-limiter@*": "0.2.3_hono@4.6.5", "npm:hono@*": "4.6.5", "npm:js-yaml@^4.0.9": "4.1.0", @@ -686,6 +687,12 @@ "dequal@2.0.3": { "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==" }, + "detect-url-change@1.0.2": { + "integrity": "sha512-kw8H5SvDszrszffxBpfJ0zYQWbqNMxBuxUxz4tVwZVQMhhZmVShiXrPgEZx30H+J+iXQmmm1U39Ti2nUmIlG5g==", + "dependencies": [ + "events" + ] + }, "didyoumean@1.2.2": { "integrity": "sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==" }, @@ -780,6 +787,9 @@ "@types/estree" ] }, + "events@3.3.0": { + "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==" + }, "execa@7.2.0": { "integrity": "sha512-UduyVP7TLB5IcAQl+OzLyLcS/l32W/GLg+AhHJ+ow40FOk2U3SAllPwR44v4vmdFwIWqpdwxxpQbF1n5ta9seA==", "dependencies": [ @@ -1689,6 +1699,7 @@ "npm:autoprefixer@^10.4.20", "npm:bits-ui@~0.21.16", "npm:clsx@^2.1.1", + "npm:detect-url-change@^1.0.2", "npm:lucide-svelte@0.462", "npm:mode-watcher@0.5", "npm:postcss@^8.4.49", diff --git a/routes/repository.ts b/routes/repository.ts index 0fd13fd..8a30958 100644 --- a/routes/repository.ts +++ b/routes/repository.ts @@ -108,14 +108,23 @@ app.get('/repositories/search', async (c) => { SELECT * FROM repository WHERE name ILIKE '%' || ${text} || '%' - OR author ILIKE '%' || ${text} || '%'; + OR author ILIKE '%' || ${text} || '%' + LIMIT ${LIMIT_PER_PAGE}; `; return c.json({ data: repositories, - search: { - text, + pagination: { + currentPage: 1, + totalPages: 1, totalItems: repositories.length, + itemsPerPage: LIMIT_PER_PAGE, + hasNextPage: false, + hasPrevPage: false, + }, + sort: { + sortBy: 'stars', + order: 'desc', }, }); } catch (error) { @@ -124,5 +133,4 @@ app.get('/repositories/search', async (c) => { } }); - export default app; diff --git a/src/App.svelte b/src/App.svelte index b584227..4a3c521 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,45 +1,15 @@ @@ -48,49 +18,14 @@
-
- {#if !isDocsPage} - - {/if} - -
- - - - - - - -
+
+ + + + + + +
diff --git a/src/lib/components/table/table.svelte b/src/lib/components/table/table.svelte index 70a63ed..4df7ee7 100644 --- a/src/lib/components/table/table.svelte +++ b/src/lib/components/table/table.svelte @@ -8,7 +8,7 @@ export { className as class }; -
+
; + export function debounce any>( func: T, wait: number ): (...args: Parameters) => void { - let timeoutId: ReturnType; - return (...args: Parameters) => { clearTimeout(timeoutId); timeoutId = setTimeout(() => { diff --git a/src/lib/pages/docs/get.svelte b/src/lib/pages/docs/get.svelte index 23c4a29..3f04aa0 100644 --- a/src/lib/pages/docs/get.svelte +++ b/src/lib/pages/docs/get.svelte @@ -1,79 +1,57 @@ + +

Get Repositories

Get Repositories from the database

-
- GET - / api / repositories +
+ + GET + + /v1/repositories

Request

Query Parameters

-
-
-

page

-

number

-
- -

Page number of repository e.g. 1 | 2 | 3

-
+ {#each parameters as param} +
+
+

{param.name}

+

+ {param.type} +

+
-
-
-

limit

-

number

+

{param.description}

- -

Limit per page e.g. 10

-
- -
-
-

sortBy

-

string

-
- -

Sort by stars e.g. stars | author | forks

-
- -
-
-

order

-

string

-
- -

Order of sorting e.g. asc | desc

-
-
-
-

limit

-

number

-
- -

Limit per page e.g. 10

-
- -
-
-

sortBy

-

string

-
- -

Sort by stars e.g. stars | author | forks

-
- -
-
-

order

-

string

-
- -

Order of sorting e.g. asc | desc

-
+ {/each}
@@ -81,11 +59,11 @@ class="flex flex-col gap-3 bg-white dark:bg-transparent border dark:text-white rounded-md h-auto p-4 text-xs" >

curl --request GET \

-

--url http://localhost:8000/api/repositories \

+

--url https://api.naijastars.dev/v1/repositories \

         
diff --git a/src/lib/pages/docs/page.svelte b/src/lib/pages/docs/page.svelte
index 1c5e7dc..c8d43af 100644
--- a/src/lib/pages/docs/page.svelte
+++ b/src/lib/pages/docs/page.svelte
@@ -11,32 +11,36 @@
   const navigation = [
     {
       label: 'get',
-      text: 'Get Repositories'
+      text: 'Get Repositories',
     },
     {
       label: 'search',
-      text: 'Search Repositories'
-    }
+      text: 'Search Repositories',
+    },
   ];
 
 
 
   
- {/key} - {/if} + {#key gettingFreshData} +
+ {/key} + {/if} + diff --git a/src/lib/pages/home/table.svelte b/src/lib/pages/home/table.svelte index 8a4eae5..4aa89a6 100644 --- a/src/lib/pages/home/table.svelte +++ b/src/lib/pages/home/table.svelte @@ -1,10 +1,9 @@
@@ -159,7 +159,7 @@
@@ -184,25 +184,16 @@ @@ -227,7 +218,7 @@
- {$rows.length} repo(s) | Page {currentPage} of + {$rows.length} repo(s) | Page {apiMetadata.pagination.currentPage} of {apiMetadata.pagination.totalPages}
@@ -265,7 +256,7 @@ variant="outline" size="sm" on:click={onFirstPage} - disabled={currentPage === 1 || isFetching} + disabled={apiMetadata.pagination.currentPage === 1 || isFetching} > First page @@ -290,7 +281,8 @@ variant="outline" size="sm" on:click={onLastPage} - disabled={currentPage === apiMetadata.pagination.totalPages || isFetching} + disabled={apiMetadata.pagination.currentPage === + apiMetadata.pagination.totalPages || isFetching} > Last page diff --git a/src/lib/pages/other/page.svelte b/src/lib/pages/other/page.svelte index 7130a90..b303895 100644 --- a/src/lib/pages/other/page.svelte +++ b/src/lib/pages/other/page.svelte @@ -1,9 +1,16 @@ -
-
- +
+ + +
+
+ +
diff --git a/src/lib/pages/shared/sidebar.svelte b/src/lib/pages/shared/sidebar.svelte new file mode 100644 index 0000000..111099b --- /dev/null +++ b/src/lib/pages/shared/sidebar.svelte @@ -0,0 +1,56 @@ + + + diff --git a/src/lib/types/repository.ts b/src/lib/types/repository.ts index 7ce0f8e..bf701be 100644 --- a/src/lib/types/repository.ts +++ b/src/lib/types/repository.ts @@ -36,7 +36,7 @@ export type ApiMetadata = { hasPrevPage: boolean; }; sort: { - sortBy: 'stars' | 'author'; + sortBy: 'stars' | 'author' | 'forks'; order: 'asc' | 'desc'; }; };