Skip to content

Commit

Permalink
Cleaning, Fixing Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaByte committed Oct 9, 2023
1 parent feb084c commit e08eaac
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 149 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

[ TODO LIST ]

- [ ] Make a web version ( if possible )
- [ ] Add Linux and MacOS Builds
- [ ] Handle Sqlite with password
- [ ] Handle SQLite with password
- [x] Render performance for big sqlite files
- [x] Execute SQL command tab
- [x] Schema Generator
Expand Down
2 changes: 0 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ default-run = "app"
edition = "2021"
rust-version = "1.60"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = { version = "1.4.0", features = [] }

Expand Down
117 changes: 66 additions & 51 deletions src/app/browse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import {
} from "@/components/ui/table";

interface BrowseProps {
setSelectedTable: (value: SetStateAction<string | null>) => void;
setSelectedTable: (value: SetStateAction<string>) => void;
tables: string[];
selectedTable: string | null;
selectedTable: string;
records: Columns;
}

Expand All @@ -38,7 +38,6 @@ export default function Browse(props: BrowseProps) {
const endIndex = startIndex + ROWS_PER_PAGE;

const totalPages = Math.ceil(
// @ts-ignore
records[selectedTable]?.[Object.keys(records[selectedTable])[0]]?.length /
ROWS_PER_PAGE
);
Expand All @@ -53,7 +52,10 @@ export default function Browse(props: BrowseProps) {
{selectedTable && (
<Select
value={selectedTable}
onValueChange={(table: string) => setSelectedTable(table)}
onValueChange={(table: string) => {
setCurrentPage(1);
setSelectedTable(table);
}}
>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select Table" />
Expand All @@ -77,51 +79,63 @@ export default function Browse(props: BrowseProps) {
0}{" "}
Rows
</span>
<span className="text-sm">
( Page {currentPage} of {totalPages} )
</span>
</div>
<div className="mt-2 h-[420px] overflow-auto">
{selectedTable && records[selectedTable] && (
<>
<Table>
<TableHeader>
<TableRow>
{Object.keys(records[selectedTable]).map((column, index) => (
<TableHead key={index}>{column}</TableHead>
))}
</TableRow>
</TableHeader>
<TableBody>
{records[selectedTable][Object.keys(records[selectedTable])[0]]
.slice(startIndex, endIndex)
.map((_, rowIndex) => (
<TableRow key={rowIndex}>
{Object.keys(records[selectedTable]).map(
(column, columnIndex) => (
<TableCell
key={columnIndex}
className="max-w-[150px] truncate"
>
<span>
{
records[selectedTable][column][
rowIndex + startIndex
]
}
</span>
</TableCell>
)
)}
</TableRow>
))}
</TableBody>
</Table>
</>
<section className="flex flex-col">
<div className="mt-2 overflow-auto mb-[55px]">
{selectedTable && records[selectedTable] && (
<>
<Table>
<TableHeader>
<TableRow>
{Object.keys(records[selectedTable]).map(
(column, index) => (
<TableHead key={index}>{column}</TableHead>
)
)}
</TableRow>
</TableHeader>
<TableBody>
{records[selectedTable][
Object.keys(records[selectedTable])[0]
]
.slice(startIndex, endIndex)
.map((_, rowIndex) => (
<TableRow key={rowIndex}>
{Object.keys(records[selectedTable]).map(
(column, columnIndex) => (
<TableCell
key={columnIndex}
className="max-w-[150px] truncate"
>
<span>
{
records[selectedTable][column][
rowIndex + startIndex
]
}
</span>
</TableCell>
)
)}
</TableRow>
))}
</TableBody>
</Table>
</>
)}
</div>

{totalPages > 1 && (
<Pagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={handleChangePage}
/>
)}
</div>
<Pagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={handleChangePage}
/>
</section>
</div>
);
}
Expand All @@ -137,11 +151,12 @@ const Pagination: React.FC<PaginationProps> = ({
totalPages,
onPageChange,
}) => {
// @ts-ignore
const pageNumbers = [...Array(totalPages).keys()].map((num) => num + 1);

const pageNumbers = Array.from(
{ length: totalPages },
(_, index) => index + 1
);
return (
<ul className="flex overflow-x-scroll">
<ul className="flex overflow-x-scroll fixed bottom-0 w-full">
{pageNumbers.map((page) => (
<li
key={page}
Expand Down
42 changes: 22 additions & 20 deletions src/app/execute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,30 @@ export default function ExecuteSQL({ table }: { table: string }) {
</button>
{typeof result === "string" ? (
<p>{result}</p>
) : result instanceof Array ? (
<Table>
<TableHeader>
<TableRow>
{Object.keys(result[0]).map((key) => (
<TableHead key={key}>{key}</TableHead>
))}
</TableRow>
</TableHeader>
<TableBody>
{result.map((row, index) => (
<TableRow key={index}>
{Object.values(row).map((value, index) => (
<TableCell key={index} className="max-w-[150px] truncate">
{value}
</TableCell>
) : (
result instanceof Array && (
<Table>
<TableHeader>
<TableRow>
{Object.keys(result[0]).map((key) => (
<TableHead key={key}>{key}</TableHead>
))}
</TableRow>
))}
</TableBody>
</Table>
) : null}
</TableHeader>
<TableBody>
{result.map((row, index) => (
<TableRow key={index}>
{Object.values(row).map((value, index) => (
<TableCell key={index} className="max-w-[150px] truncate">
{value}
</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
)
)}
</form>
</div>
);
Expand Down
9 changes: 0 additions & 9 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Metadata } from "next";
import { Merriweather_Sans } from "next/font/google";

import ThemeProvider from "@/components/theme/provider";
import Toggle from "@/components/theme/toggle";

const font = Merriweather_Sans({ subsets: ["latin"] });
export const metadata: Metadata = {
Expand All @@ -26,14 +25,6 @@ export default function RootLayout({
disableTransitionOnChange
>
{children}
<footer className="p-4 fixed bottom-0 w-full bg-background border-t border-secondary">
<div className="flex justify-between items-center">
<Toggle />
<span className="hover:animate-bounce animate-pulse">
SQLite Viewer V0.4
</span>
</div>
</footer>
</ThemeProvider>
</body>
</html>
Expand Down
10 changes: 8 additions & 2 deletions src/app/load.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use client";

import { ReloadIcon } from "@radix-ui/react-icons";
import { Columns, TableInfos, TableInfo } from "@/types";
import { useState, useEffect } from "react";
import Toggle from "@/components/theme/toggle";

import { invoke } from "@tauri-apps/api/tauri";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
Expand All @@ -14,7 +16,7 @@ export default function Load({ path }: { path: string }) {
const [records, setRecords] = useState<Columns>({});
const [tables, setTables] = useState<string[]>([]);
const [tablesInfo, setTablesInfo] = useState<TableInfos>({});
const [selectedTable, setSelectedTable] = useState<string | null>(null);
const [selectedTable, setSelectedTable] = useState<string>("");

useEffect(() => {
onSelectedDatabase();
Expand Down Expand Up @@ -71,6 +73,7 @@ export default function Load({ path }: { path: string }) {
<TabsTrigger value="execute" className="grow">
Execute SQL
</TabsTrigger>
<Toggle />
</TabsList>
<TabsContent value="structure">
<Structure tablesInfo={tablesInfo} />
Expand All @@ -88,7 +91,10 @@ export default function Load({ path }: { path: string }) {
</TabsContent>
</Tabs>
) : (
<h1 className="text-2xl w-full mt-20 text-center">Loading Data..</h1>
<div className="flex gap-2 items-center justify-center mt-20">
<h1 className="text-2xl">Reading Content</h1>
<ReloadIcon className="animate-spin w-8 h-8" />
</div>
)}
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export default function Home() {
>
Select Database
</button>
<p>SQLite Viewer GUI Program written in Rust using Tauri + NextJS</p>
<p>I dont know what to put in this place!</p>
<p>Leave a Start on GitHub ⭐</p>
</div>
)}
</main>
Expand Down
7 changes: 3 additions & 4 deletions src/components/theme/toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { useTheme } from "next-themes";
import { MoonIcon, SunIcon } from "@radix-ui/react-icons";

import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
Expand All @@ -16,13 +15,13 @@ export default function Toggle() {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="icon">
<button className="flex items-center px-2 hover:opacity-70">
<SunIcon className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<MoonIcon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
<span className="sr-only">Toggle theme</span>
</Button>
</button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => setTheme("light")}>
Light
</DropdownMenuItem>
Expand Down
57 changes: 0 additions & 57 deletions src/components/ui/button.tsx

This file was deleted.

0 comments on commit e08eaac

Please sign in to comment.