From b088846a64e34974e77539b5cea54d9dc632ea41 Mon Sep 17 00:00:00 2001 From: Mansive Date: Wed, 20 Dec 2023 05:50:16 -0600 Subject: [PATCH 1/8] Establish db connection and basic search --- .gitignore | 4 ++ .xata/migrations/.ledger | 14 +++++ .../mig_clt8pr6ikbucdv445tkg_16264466.json | 11 ++++ .../mig_clt8pvh51tlm97jou9tg_50da88fb.json | 16 ++++++ .../mig_clt8qep51tlm97joua5g_39219fe8.json | 12 +++++ .../mig_clt8qg951tlm97joua7g_eb7523ab.json | 12 +++++ .../mig_clt8qm151tlm97joua8g_a673c218.json | 18 +++++++ .../mig_clt8qneikbucdv445u9g_e3a10c45.json | 13 +++++ .../mig_clt8qr9ufgk57snhcv90_e296b93f.json | 18 +++++++ .../mig_clt8r5951tlm97joua9g_9d118fb3.json | 18 +++++++ .../mig_clt8rb151tlm97jouaag_1632a9c3.json | 18 +++++++ .../mig_clt8u51ufgk57snhcva0_c24aa583.json | 18 +++++++ .../mig_clt8ul6ikbucdv445uag_dc5e54ff.json | 16 ++++++ .../mig_clt8up6ikbucdv445ubg_47dad0b9.json | 13 +++++ .../mig_clt8ut951tlm97jouabg_d5ce08c4.json | 16 ++++++ .../mig_clt8v0mikbucdv445ucg_25569b27.json | 16 ++++++ .xata/version/compatibility.json | 1 + .xatarc | 6 +++ package-lock.json | 10 +++- package.json | 1 + src/app/api/search/route.tsx | 19 +++++++ src/lib/xata.ts | 52 +++++++++++++++++++ 22 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 .xata/migrations/.ledger create mode 100644 .xata/migrations/mig_clt8pr6ikbucdv445tkg_16264466.json create mode 100644 .xata/migrations/mig_clt8pvh51tlm97jou9tg_50da88fb.json create mode 100644 .xata/migrations/mig_clt8qep51tlm97joua5g_39219fe8.json create mode 100644 .xata/migrations/mig_clt8qg951tlm97joua7g_eb7523ab.json create mode 100644 .xata/migrations/mig_clt8qm151tlm97joua8g_a673c218.json create mode 100644 .xata/migrations/mig_clt8qneikbucdv445u9g_e3a10c45.json create mode 100644 .xata/migrations/mig_clt8qr9ufgk57snhcv90_e296b93f.json create mode 100644 .xata/migrations/mig_clt8r5951tlm97joua9g_9d118fb3.json create mode 100644 .xata/migrations/mig_clt8rb151tlm97jouaag_1632a9c3.json create mode 100644 .xata/migrations/mig_clt8u51ufgk57snhcva0_c24aa583.json create mode 100644 .xata/migrations/mig_clt8ul6ikbucdv445uag_dc5e54ff.json create mode 100644 .xata/migrations/mig_clt8up6ikbucdv445ubg_47dad0b9.json create mode 100644 .xata/migrations/mig_clt8ut951tlm97jouabg_d5ce08c4.json create mode 100644 .xata/migrations/mig_clt8v0mikbucdv445ucg_25569b27.json create mode 100644 .xata/version/compatibility.json create mode 100644 .xatarc create mode 100644 src/app/api/search/route.tsx create mode 100644 src/lib/xata.ts diff --git a/.gitignore b/.gitignore index fd3dbb5..2f090e0 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,7 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + + +.env +.dev.vars diff --git a/.xata/migrations/.ledger b/.xata/migrations/.ledger new file mode 100644 index 0000000..6097711 --- /dev/null +++ b/.xata/migrations/.ledger @@ -0,0 +1,14 @@ +mig_clt8pr6ikbucdv445tkg_16264466 +mig_clt8pvh51tlm97jou9tg_50da88fb +mig_clt8qep51tlm97joua5g_39219fe8 +mig_clt8qg951tlm97joua7g_eb7523ab +mig_clt8qm151tlm97joua8g_a673c218 +mig_clt8qneikbucdv445u9g_e3a10c45 +mig_clt8qr9ufgk57snhcv90_e296b93f +mig_clt8r5951tlm97joua9g_9d118fb3 +mig_clt8rb151tlm97jouaag_1632a9c3 +mig_clt8u51ufgk57snhcva0_c24aa583 +mig_clt8ul6ikbucdv445uag_dc5e54ff +mig_clt8up6ikbucdv445ubg_47dad0b9 +mig_clt8ut951tlm97jouabg_d5ce08c4 +mig_clt8v0mikbucdv445ucg_25569b27 diff --git a/.xata/migrations/mig_clt8pr6ikbucdv445tkg_16264466.json b/.xata/migrations/mig_clt8pr6ikbucdv445tkg_16264466.json new file mode 100644 index 0000000..8096962 --- /dev/null +++ b/.xata/migrations/mig_clt8pr6ikbucdv445tkg_16264466.json @@ -0,0 +1,11 @@ +{ + "id": "mig_clt8pr6ikbucdv445tkg", + "checksum": "1:16264466529c465708d58829438f3ea695865e100ec7d4f1a20e4ee89e81f4bb", + "operations": [ + { + "addTable": { + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8pvh51tlm97jou9tg_50da88fb.json b/.xata/migrations/mig_clt8pvh51tlm97jou9tg_50da88fb.json new file mode 100644 index 0000000..0cbda78 --- /dev/null +++ b/.xata/migrations/mig_clt8pvh51tlm97jou9tg_50da88fb.json @@ -0,0 +1,16 @@ +{ + "id": "mig_clt8pvh51tlm97jou9tg", + "parentID": "mig_clt8pr6ikbucdv445tkg", + "checksum": "1:50da88fbc9a220e6ec2f5d16fd1ea79af9e9384b2c785b3ef5f0dc92d7fcac9b", + "operations": [ + { + "addColumn": { + "column": { + "name": "title", + "type": "string" + }, + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8qep51tlm97joua5g_39219fe8.json b/.xata/migrations/mig_clt8qep51tlm97joua5g_39219fe8.json new file mode 100644 index 0000000..0259995 --- /dev/null +++ b/.xata/migrations/mig_clt8qep51tlm97joua5g_39219fe8.json @@ -0,0 +1,12 @@ +{ + "id": "mig_clt8qep51tlm97joua5g", + "parentID": "mig_clt8pvh51tlm97jou9tg", + "checksum": "1:39219fe868101ac292a454d1c1713e8b8370a1b4822427ce40a5842d3fbc58d2", + "operations": [ + { + "removeTable": { + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8qg951tlm97joua7g_eb7523ab.json b/.xata/migrations/mig_clt8qg951tlm97joua7g_eb7523ab.json new file mode 100644 index 0000000..e1299cd --- /dev/null +++ b/.xata/migrations/mig_clt8qg951tlm97joua7g_eb7523ab.json @@ -0,0 +1,12 @@ +{ + "id": "mig_clt8qg951tlm97joua7g", + "parentID": "mig_clt8qep51tlm97joua5g", + "checksum": "1:eb7523ab119c0b2a29ec8f874ccb31e1bd0574a46093cadf76c3ca00eceabe85", + "operations": [ + { + "addTable": { + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8qm151tlm97joua8g_a673c218.json b/.xata/migrations/mig_clt8qm151tlm97joua8g_a673c218.json new file mode 100644 index 0000000..38e6d9d --- /dev/null +++ b/.xata/migrations/mig_clt8qm151tlm97joua8g_a673c218.json @@ -0,0 +1,18 @@ +{ + "id": "mig_clt8qm151tlm97joua8g", + "parentID": "mig_clt8qg951tlm97joua7g", + "checksum": "1:a673c218ed69470cd5ae2d9d824433ad1ff1c0e4ba17f6dc4f78c85b303f2f9b", + "operations": [ + { + "addColumn": { + "column": { + "name": "title", + "type": "string", + "notNull": true, + "defaultValue": "\"\"" + }, + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8qneikbucdv445u9g_e3a10c45.json b/.xata/migrations/mig_clt8qneikbucdv445u9g_e3a10c45.json new file mode 100644 index 0000000..c842810 --- /dev/null +++ b/.xata/migrations/mig_clt8qneikbucdv445u9g_e3a10c45.json @@ -0,0 +1,13 @@ +{ + "id": "mig_clt8qneikbucdv445u9g", + "parentID": "mig_clt8qm151tlm97joua8g", + "checksum": "1:e3a10c455e3f8ea6a61a2b58a52101a8e2c6586a54b1510400c842ae3f5793e4", + "operations": [ + { + "removeColumn": { + "column": "title", + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8qr9ufgk57snhcv90_e296b93f.json b/.xata/migrations/mig_clt8qr9ufgk57snhcv90_e296b93f.json new file mode 100644 index 0000000..a02acd0 --- /dev/null +++ b/.xata/migrations/mig_clt8qr9ufgk57snhcv90_e296b93f.json @@ -0,0 +1,18 @@ +{ + "id": "mig_clt8qr9ufgk57snhcv90", + "parentID": "mig_clt8qneikbucdv445u9g", + "checksum": "1:e296b93f1c5d4f53bbf4e583cc22c443b20c6cd6703c37a35637f24c20f7edde", + "operations": [ + { + "addColumn": { + "column": { + "name": "title", + "type": "string", + "notNull": true, + "defaultValue": "" + }, + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8r5951tlm97joua9g_9d118fb3.json b/.xata/migrations/mig_clt8r5951tlm97joua9g_9d118fb3.json new file mode 100644 index 0000000..fa99021 --- /dev/null +++ b/.xata/migrations/mig_clt8r5951tlm97joua9g_9d118fb3.json @@ -0,0 +1,18 @@ +{ + "id": "mig_clt8r5951tlm97joua9g", + "parentID": "mig_clt8qr9ufgk57snhcv90", + "checksum": "1:9d118fb3dfbf5fed2be74bb8c498303289476fab4c3cb64af21b9768dfd6f58f", + "operations": [ + { + "addColumn": { + "column": { + "name": "true_title", + "type": "string", + "notNull": true, + "defaultValue": "" + }, + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8rb151tlm97jouaag_1632a9c3.json b/.xata/migrations/mig_clt8rb151tlm97jouaag_1632a9c3.json new file mode 100644 index 0000000..154d3f8 --- /dev/null +++ b/.xata/migrations/mig_clt8rb151tlm97jouaag_1632a9c3.json @@ -0,0 +1,18 @@ +{ + "id": "mig_clt8rb151tlm97jouaag", + "parentID": "mig_clt8r5951tlm97joua9g", + "checksum": "1:1632a9c3a49f26b927bcb6d91a6862dfa6073f189ce63e8da230670adc2816da", + "operations": [ + { + "addColumn": { + "column": { + "name": "extension", + "type": "string", + "notNull": true, + "defaultValue": "" + }, + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8u51ufgk57snhcva0_c24aa583.json b/.xata/migrations/mig_clt8u51ufgk57snhcva0_c24aa583.json new file mode 100644 index 0000000..7b9d8f1 --- /dev/null +++ b/.xata/migrations/mig_clt8u51ufgk57snhcva0_c24aa583.json @@ -0,0 +1,18 @@ +{ + "id": "mig_clt8u51ufgk57snhcva0", + "parentID": "mig_clt8rb151tlm97jouaag", + "checksum": "1:c24aa583a4b4d4cdff434f8eb70c5b59c3e5af80496ea80bc399362c0ff67db3", + "operations": [ + { + "addColumn": { + "column": { + "name": "size", + "type": "int", + "notNull": true, + "defaultValue": "0" + }, + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8ul6ikbucdv445uag_dc5e54ff.json b/.xata/migrations/mig_clt8ul6ikbucdv445uag_dc5e54ff.json new file mode 100644 index 0000000..1ba5250 --- /dev/null +++ b/.xata/migrations/mig_clt8ul6ikbucdv445uag_dc5e54ff.json @@ -0,0 +1,16 @@ +{ + "id": "mig_clt8ul6ikbucdv445uag", + "parentID": "mig_clt8u51ufgk57snhcva0", + "checksum": "1:dc5e54ff5462e0144d3633914899f97b0ce8d2c37ea83541bcea7123ab91635b", + "operations": [ + { + "addColumn": { + "column": { + "name": "sources", + "type": "multiple" + }, + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8up6ikbucdv445ubg_47dad0b9.json b/.xata/migrations/mig_clt8up6ikbucdv445ubg_47dad0b9.json new file mode 100644 index 0000000..aff7479 --- /dev/null +++ b/.xata/migrations/mig_clt8up6ikbucdv445ubg_47dad0b9.json @@ -0,0 +1,13 @@ +{ + "id": "mig_clt8up6ikbucdv445ubg", + "parentID": "mig_clt8ul6ikbucdv445uag", + "checksum": "1:47dad0b9d387315cddc4f9a1b25dddb53f93ed48790efd2e186803c72ac7dcc8", + "operations": [ + { + "removeColumn": { + "column": "sources", + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8ut951tlm97jouabg_d5ce08c4.json b/.xata/migrations/mig_clt8ut951tlm97jouabg_d5ce08c4.json new file mode 100644 index 0000000..90c75fe --- /dev/null +++ b/.xata/migrations/mig_clt8ut951tlm97jouabg_d5ce08c4.json @@ -0,0 +1,16 @@ +{ + "id": "mig_clt8ut951tlm97jouabg", + "parentID": "mig_clt8up6ikbucdv445ubg", + "checksum": "1:d5ce08c408263f80863055712da3e1bf066731e115fba5e10f2e40ee7d41007e", + "operations": [ + { + "addColumn": { + "column": { + "name": "sources", + "type": "multiple" + }, + "table": "Books" + } + } + ] +} diff --git a/.xata/migrations/mig_clt8v0mikbucdv445ucg_25569b27.json b/.xata/migrations/mig_clt8v0mikbucdv445ucg_25569b27.json new file mode 100644 index 0000000..35f4b0d --- /dev/null +++ b/.xata/migrations/mig_clt8v0mikbucdv445ucg_25569b27.json @@ -0,0 +1,16 @@ +{ + "id": "mig_clt8v0mikbucdv445ucg", + "parentID": "mig_clt8ut951tlm97jouabg", + "checksum": "1:25569b27226827636af25095c26d23e44d59e489c57aba56575b975a0a0ce596", + "operations": [ + { + "addColumn": { + "column": { + "name": "md5", + "type": "string" + }, + "table": "Books" + } + } + ] +} diff --git a/.xata/version/compatibility.json b/.xata/version/compatibility.json new file mode 100644 index 0000000..3cecd0d --- /dev/null +++ b/.xata/version/compatibility.json @@ -0,0 +1 @@ +{"@xata.io/cli":{"latest":"0.15.3","compatibility":[{"range":">=0.0.0"}]},"@xata.io/client":{"latest":"0.28.2","compatibility":[{"range":">=0.0.0"}]}} \ No newline at end of file diff --git a/.xatarc b/.xatarc new file mode 100644 index 0000000..8c6ac80 --- /dev/null +++ b/.xatarc @@ -0,0 +1,6 @@ +{ + "databaseURL": "https://lolibrary-92ghbn.us-east-1.xata.sh/db/lolibrary", + "codegen": { + "output": "src/lib/xata.ts" + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5a59248..d6c2100 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@react-three/drei": "^9.90.0", "@react-three/fiber": "^8.15.12", "@types/three": "^0.159.0", + "@xata.io/client": "^0.28.2", "framer-motion": "^10.16.14", "next": "14.0.3", "react": "^18", @@ -727,6 +728,14 @@ "react": ">= 16.8.0" } }, + "node_modules/@xata.io/client": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@xata.io/client/-/client-0.28.2.tgz", + "integrity": "sha512-B5eCr5peggaDCfjsVIpXBxj4TgOg8K15RdCBEuBPXwDGRmZF+/1IILGztP1R46XbskJAHFX0jCmfLQEPWNV5Mw==", + "peerDependencies": { + "typescript": ">=4.5" + } + }, "node_modules/acorn": { "version": "8.11.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.2.tgz", @@ -4096,7 +4105,6 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", - "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 4081732..c37bced 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@react-three/drei": "^9.90.0", "@react-three/fiber": "^8.15.12", "@types/three": "^0.159.0", + "@xata.io/client": "^0.28.2", "framer-motion": "^10.16.14", "next": "14.0.3", "react": "^18", diff --git a/src/app/api/search/route.tsx b/src/app/api/search/route.tsx new file mode 100644 index 0000000..746f661 --- /dev/null +++ b/src/app/api/search/route.tsx @@ -0,0 +1,19 @@ +import { getXataClient } from "@/lib/xata"; +import { NextRequest, NextResponse } from "next/server"; + +export const runtime = "edge"; + +const xata = getXataClient(); + +export async function GET(request: NextRequest) { + const searchParams: string = decodeURIComponent( + request.nextUrl.searchParams.toString() + ); + + const results = await xata.db.Books.search(searchParams, { + target: ["title"], + fuzziness: 0, + }); + + return NextResponse.json({ results }); +} diff --git a/src/lib/xata.ts b/src/lib/xata.ts new file mode 100644 index 0000000..180768c --- /dev/null +++ b/src/lib/xata.ts @@ -0,0 +1,52 @@ +// Generated by Xata Codegen 0.28.2. Please do not edit. +import { buildClient } from "@xata.io/client"; +import type { + BaseClientOptions, + SchemaInference, + XataRecord, +} from "@xata.io/client"; + +const tables = [ + { + name: "Books", + columns: [ + { name: "title", type: "string", notNull: true, defaultValue: "" }, + { name: "true_title", type: "string", notNull: true, defaultValue: "" }, + { name: "extension", type: "string", notNull: true, defaultValue: "" }, + { name: "size", type: "int", notNull: true, defaultValue: "0" }, + { name: "sources", type: "multiple" }, + { name: "md5", type: "string" }, + ], + }, +] as const; + +export type SchemaTables = typeof tables; +export type InferredTypes = SchemaInference; + +export type Books = InferredTypes["Books"]; +export type BooksRecord = Books & XataRecord; + +export type DatabaseSchema = { + Books: BooksRecord; +}; + +const DatabaseClient = buildClient(); + +const defaultOptions = { + databaseURL: "https://lolibrary-92ghbn.us-east-1.xata.sh/db/lolibrary", +}; + +export class XataClient extends DatabaseClient { + constructor(options?: BaseClientOptions) { + super({ ...defaultOptions, ...options }, tables); + } +} + +let instance: XataClient | undefined = undefined; + +export const getXataClient = () => { + if (instance) return instance; + + instance = new XataClient(); + return instance; +}; From 2af225aa33966f47e4a502cafd29fc38178d86e0 Mon Sep 17 00:00:00 2001 From: Mansive <33560917+Mansive@users.noreply.github.com> Date: Wed, 20 Dec 2023 05:59:06 -0600 Subject: [PATCH 2/8] Update deploy.yml --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a50bf18..d76efa9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,10 +46,10 @@ jobs: projectName: lilium-orientalis-library directory: .vercel/output/static # Optional: Enable this if you want to have GitHub Deployments triggered - gitHubToken: ${{ secrets.GITHUB_TOKEN }} + gitHubToken: ${{ secr#ts.GITHUB_TOKEN }} # Optional: Switch what branch you are publishing to. # By default this will be the branch which triggered this workflow - branch: main + #branch: main # Optional: Change the working directory #workingDirectory: my-site # Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta` From 6dc9a74fd846b2163f8769a373938f8139251683 Mon Sep 17 00:00:00 2001 From: Mansive Date: Wed, 20 Dec 2023 22:59:44 -0600 Subject: [PATCH 3/8] Replace random pound --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d76efa9..9f604ef 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,7 +46,7 @@ jobs: projectName: lilium-orientalis-library directory: .vercel/output/static # Optional: Enable this if you want to have GitHub Deployments triggered - gitHubToken: ${{ secr#ts.GITHUB_TOKEN }} + gitHubToken: ${{ secrets.GITHUB_TOKEN }} # Optional: Switch what branch you are publishing to. # By default this will be the branch which triggered this workflow #branch: main From f187929580bbed7db7694da302fe1d45013545a4 Mon Sep 17 00:00:00 2001 From: Mansive Date: Wed, 20 Dec 2023 23:00:06 -0600 Subject: [PATCH 4/8] Display search api results --- src/app/api/search/route.tsx | 2 +- src/app/page.tsx | 14 ++++++++------ src/components/Card/Card.tsx | 2 +- .../SearchResultList/SearchResultList.tsx | 9 ++++++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/app/api/search/route.tsx b/src/app/api/search/route.tsx index 746f661..2f6e88f 100644 --- a/src/app/api/search/route.tsx +++ b/src/app/api/search/route.tsx @@ -15,5 +15,5 @@ export async function GET(request: NextRequest) { fuzziness: 0, }); - return NextResponse.json({ results }); + return NextResponse.json(results); } diff --git a/src/app/page.tsx b/src/app/page.tsx index d1ee9b0..cee4e8a 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -6,7 +6,7 @@ import SearchBar from "@/components/SearchBar"; import SearchResultList from "@/components/SearchResultList"; import Spinner from "@/components/Spinner"; -import { Book, BOOKS } from "@/data/book-data"; +import { Book } from "@/data/book-data"; import styles from "./page.module.css"; @@ -22,11 +22,13 @@ export default function Home() { setStatus("loading"); - setTimeout(() => { - const nextSearchResults = BOOKS.filter(({ title }) => - title.includes(searchTerm) - ); - setSearchResults(nextSearchResults); + setTimeout(async () => { + // const nextSearchResults = BOOKS.filter(({ title }) => + // title.includes(searchTerm) + // ); + const response = await fetch("/api/search?query=" + searchTerm); + const data = await response.json(); + setSearchResults(data["records"]); setStatus("success"); }, 1500); }; diff --git a/src/components/Card/Card.tsx b/src/components/Card/Card.tsx index 682b480..a94f41a 100644 --- a/src/components/Card/Card.tsx +++ b/src/components/Card/Card.tsx @@ -6,7 +6,7 @@ type CardInterface = { id: string; title: string; sources: string[]; - size: number; + size: string; extension: string; }; diff --git a/src/components/SearchResultList/SearchResultList.tsx b/src/components/SearchResultList/SearchResultList.tsx index 7b2b8d9..6ac7acd 100644 --- a/src/components/SearchResultList/SearchResultList.tsx +++ b/src/components/SearchResultList/SearchResultList.tsx @@ -31,6 +31,13 @@ function SearchResultList({ searchResults }: SearchResultListInterface) { }; }, []); + // https://stackoverflow.com/a/48764436 + function round(num: number, decimalPlaces = 0) { + var p = Math.pow(10, decimalPlaces); + var n = num * p * (1 + Number.EPSILON); + return Math.round(n) / p; + } + return (
{searchResults?.map((book) => ( @@ -39,7 +46,7 @@ function SearchResultList({ searchResults }: SearchResultListInterface) { id={book.id} title={book.title} sources={book.sources} - size={book.size} + size={round(book.size / 1048576, 2).toFixed(1)} // to mebibytes extension={book.extension} /> ))} From b7013b4ea3ce27aae656a6bfb2574af29dcb0791 Mon Sep 17 00:00:00 2001 From: Mansive Date: Wed, 20 Dec 2023 23:44:45 -0600 Subject: [PATCH 5/8] Fix deploy issues --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9f604ef..ccee1e5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -37,6 +37,8 @@ jobs: - name: Build run: npx @cloudflare/next-on-pages@1 + env: + XATA_API_KEY: ${{ secrets.XATA_API_KEY }} - name: Publish to Cloudflare Pages uses: cloudflare/pages-action@v1 From 9635011a175b44364174156434e8115dd50f74cc Mon Sep 17 00:00:00 2001 From: Mansive Date: Thu, 21 Dec 2023 18:21:35 -0600 Subject: [PATCH 6/8] Increase max length for search term --- src/app/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index cee4e8a..0f61091 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -48,7 +48,7 @@ export default function Home() { onChange={(event: React.ChangeEvent) => { setSearchTerm(event.target.value); }} - maxLength={64} + maxLength={128} />
From 14a87abb6d7b0f93190bfa3005c6ebbbf8fa9e02 Mon Sep 17 00:00:00 2001 From: Mansive <33560917+Mansive@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:39:51 -0600 Subject: [PATCH 7/8] Limit string length on search route --- src/app/api/search/route.tsx | 6 ++++++ src/app/page.tsx | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/api/search/route.tsx b/src/app/api/search/route.tsx index 2f6e88f..95f333f 100644 --- a/src/app/api/search/route.tsx +++ b/src/app/api/search/route.tsx @@ -9,6 +9,12 @@ export async function GET(request: NextRequest) { const searchParams: string = decodeURIComponent( request.nextUrl.searchParams.toString() ); + if (searchParams.length > 128) { + return NextResponse.json( + { message: "Search entry is too long" }, + { status: 403 } + ); + } const results = await xata.db.Books.search(searchParams, { target: ["title"], diff --git a/src/app/page.tsx b/src/app/page.tsx index 0f61091..8ce77c6 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -22,15 +22,20 @@ export default function Home() { setStatus("loading"); - setTimeout(async () => { - // const nextSearchResults = BOOKS.filter(({ title }) => - // title.includes(searchTerm) - // ); + try { const response = await fetch("/api/search?query=" + searchTerm); + if (!response.ok) { + throw new Error(); + } const data = await response.json(); setSearchResults(data["records"]); setStatus("success"); - }, 1500); + console.log("success"); + } catch (error) { + console.log("wtf"); + setStatus("idle"); + //setStatus("error"); + } }; return ( From b43d358ba1b82042ebc1c7d21fdcdb52a184ed3b Mon Sep 17 00:00:00 2001 From: Mansive <33560917+Mansive@users.noreply.github.com> Date: Fri, 22 Dec 2023 02:00:25 -0600 Subject: [PATCH 8/8] Improved spinner logic --- src/app/page.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 8ce77c6..8ebad30 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -29,10 +29,8 @@ export default function Home() { } const data = await response.json(); setSearchResults(data["records"]); - setStatus("success"); - console.log("success"); + data["records"].length == 0 ? setStatus("idle") : setStatus("success"); } catch (error) { - console.log("wtf"); setStatus("idle"); //setStatus("error"); }