Fix main page

This commit is contained in:
AndrewTrieu
2022-12-28 20:23:33 +02:00
parent 2a37c8bdf4
commit 728c9823cf
6 changed files with 22 additions and 17 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
.vscode/settings.json
project1.zip

View File

@@ -7,7 +7,7 @@ Users can create new shopping lists, add items to them, and mark items as
collected. The application displays a list of all active shopping lists, as well
as a page for each individual shopping list showing all its items.
The application is deployed at https://shopper.fly.dev/ using
The application is deployed at https://shoptool.fly.dev/ using
[Fly.io](https://fly.io/). Feel free to try it out!
The web application is built using Deno, a JavaScript/TypeScript runtime with

View File

@@ -7,10 +7,15 @@ const responseDetails = {
const showMain = async (_request) => {
const data = {
flag: true,
listCount: await mainService.checkList(),
itemCount: await mainService.checkItem(),
};
if (data.listCount > 0) {
data.flag = false;
}
return new Response(await renderFile("main.eta", data), responseDetails);
};

View File

@@ -1,6 +1,6 @@
# fly.toml file generated for shopper on 2022-12-27T19:33:40+02:00
# fly.toml file generated for shoptool on 2022-12-28T19:38:57+02:00
app = "shopper"
app = "shoptool"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

View File

@@ -2,14 +2,20 @@ import { executeQuery } from "../database/database.js";
const checkList = async () => {
const result = await executeQuery("SELECT COUNT(*) FROM shopping_lists;");
return result.rows[0].count;
if (result.rows && result.rows.length > 0) {
return result.rows[0].count;
}
return 0;
};
const checkItem = async () => {
const result = await executeQuery(
"SELECT COUNT(*) FROM shopping_list_items;"
);
return result.rows[0].count;
if (result.rows && result.rows.length > 0) {
return result.rows[0].count;
}
return 0;
};
export { checkList, checkItem };

View File

@@ -2,18 +2,11 @@
<h1>Shared shopping lists</h1>
<ul>
<% if (it.listCount !== 0) { %>
<li>Shopping lists: <%= it.listCount %></li>
<% } else { %>
<% if (it.flag) { %>
<li>No shopping lists yet.</li>
<% } %>
<% if (it.itemCount !== 0) { %>
<li>Shopping list items: <%= it.itemCount %></li>
<% } else { %>
<li>No items yet.</li>
<% } %>
<li>Shopping lists: <%= it.listCount %></li>
<li>Shopping list items: <%= it.itemCount %></li>
</ul>
<% if (it.listCount !== 0) { %>
<a href="/lists">Lists</a>
<% } %>
<% } %>
<a href="/lists">Lists</a>