Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions main/app/headset/[headsetName]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { db } from '@/app/server/db/index'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client side sites should start with "use client".

import { type Headset, headsets } from '@/app/server/db/schema/headsets'
import { eq, SQLWrapper } from 'drizzle-orm'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Database should not be accessed directly from Client. This should make use of existing backend server routes


/**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server side function present in client

* @param params.headsetName
* @returns {Promise<Headset[]>}
* @description Gets desired headset info from the database
*/
async function getHeadsetInfo( params: { headsetName: string } ): Promise<Headset[]> {
const headset: Headset[] = await db
.select()
.from(headsets)
.where(eq(headsets.name, params.headsetName))
.execute()
return headset;
}

/**
* @description display the headset info
* @returns null
*/
export default async function HeadsetDetails( { params }: {
params: {headsetName: string}
} ) {
const headsetInfo = await getHeadsetInfo(params);

return (
<>
<h1>Details about {params.headsetName} headset:</h1>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Price ($)</th>
<th>Channel Number</th>
<th>Channel List</th>
<th>Purpose</th>
<th>Portability</th>
<th>Company</th>
<th>Battery Life</th>
</tr>
</thead>
<tbody>
{headsetInfo.map(item => (
<tr key={item.id}>
<td>{item.id}</td>
<td>{item.name}</td>
<td>{item.description}</td>
<td>{item.price}</td>
<td>{item.channelNumber}</td>
<td>{item.channelList}</td>
<td>{item.purpose}</td>
<td>{item.portability}</td>
<td>{item.company}</td>
<td>{item.batteryLife}</td>
</tr>
))}
</tbody>
</table>
</>
);
}
9 changes: 8 additions & 1 deletion main/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface EEGData {
eegChannelSize: number;
}

import Link from 'next/link';

export default function Home(): React.JSX.Element {
/**
* @TODO Fix type of headsets state
Expand Down Expand Up @@ -57,8 +59,13 @@ export default function Home(): React.JSX.Element {
</p>
{headsets.map((headset: any) => (
<div key={headset.id}>
<p>{headset.name}</p>
<Link href={`/headset/${headset.name}`}>
<button>
<p>{headset.name}</p>
</button>
</Link>
</div>

))}
<div>
{eegData.length > 0 && (
Expand Down
2 changes: 1 addition & 1 deletion main/drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export default {
dbCredentials: {
url: './main.db'
}
} satisfies Config
} satisfies Config
Binary file modified main/main.db
Binary file not shown.
114 changes: 11 additions & 103 deletions main/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@radix-ui/react-slot": "^1.0.2",
"@servicestack/client": "^2.1.2",
"better-sqlite3": "^9.4.3",
"better-sqlite3": "^9.6.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"dotenv": "^16.4.5",
Expand All @@ -34,7 +34,7 @@
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"autoprefixer": "^10.0.1",
"drizzle-kit": "^0.20.14",
"drizzle-kit": "^0.21.2",
"eslint": "^8.57.0",
"eslint-config-next": "14.1.2",
"eslint-config-standard-with-typescript": "^43.0.1",
Expand Down
Loading