Fix main page
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
.vscode/settings.json
|
||||
project1.zip
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user