-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server-list): add server list retrieval and display functionality
- Loading branch information
Showing
3 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server'; | ||
import { db } from '@/db/db'; | ||
import { servers } from '@/db/schema/servers'; | ||
|
||
export const getServerList = () => db.select().from(servers).all(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use client'; | ||
|
||
import type { ColumnDef } from '@tanstack/react-table'; | ||
import { Icon } from '@/components/icon'; | ||
import { Text } from '@/components/text'; | ||
import { DataTableColumnHeader } from '@/components/dataTableColumnHeader'; | ||
|
||
import { cn } from '@/utils/cn'; | ||
|
||
import type { Server } from '@/db/schema/servers'; | ||
|
||
export const columns: ColumnDef<Server>[] = [ | ||
{ | ||
accessorKey: 'name', | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Country name" /> | ||
), | ||
cell: ({ row }) => { | ||
const countryCode = row.original.countryCode; | ||
const name: Server['name'] = row.getValue('name'); | ||
|
||
return ( | ||
<div className="flex items-center gap-4"> | ||
{countryCode && ( | ||
<Icon | ||
id={`flag-${countryCode}`.toLowerCase()} | ||
sprite="/svg-sprites/flags.svg" | ||
className="h-auto w-8 border border-gray-200" | ||
/> | ||
)} | ||
<Text weight="medium" asChild className={cn(!countryCode && 'pl-12')}> | ||
<span>{name}</span> | ||
</Text> | ||
</div> | ||
); | ||
}, | ||
}, | ||
{ | ||
accessorKey: 'distance', | ||
cell: ({ row }) => { | ||
const value: number = row.getValue('distance'); | ||
return ( | ||
<Text weight="medium" className="md:text-semibold" asChild> | ||
<span>{value} km</span> | ||
</Text> | ||
); | ||
}, | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader | ||
column={column} | ||
title="Distance" | ||
className="justify-end" | ||
/> | ||
), | ||
meta: { | ||
style: { | ||
textAlign: 'right', | ||
}, | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters