Skip to content

Commit

Permalink
i think i need to
Browse files Browse the repository at this point in the history
  • Loading branch information
htothenan1 committed Oct 26, 2023
1 parent f5cbdcd commit 173c24a
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 162 deletions.
29 changes: 10 additions & 19 deletions app/_actions.ts → app/_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,55 @@ import {
} from "./lib/items"
import { revalidatePath } from "next/cache"

export async function createItemAction(
email: string,
name: string,
storageTip: string,
expiredAt: string
) {
export async function createItemAction(email, name, storageTip, expiredAt) {
await createItem(email, name, storageTip, expiredAt)

revalidatePath("/")
}

export async function createConsumedItemAction(email: string, name: string) {
export async function createConsumedItemAction(email, name) {
await createConsumedItem(email, name)

revalidatePath("/")
}

export async function createWastedItemAction(email: string, name: string) {
export async function createWastedItemAction(email, name) {
await createWastedItem(email, name)

revalidatePath("/")
}

export async function deleteItemAction(id: string) {
export async function deleteItemAction(id) {
await deleteItemById(id)
revalidatePath("/")
}

export async function deleteItemsActions(ownerId: string) {
export async function deleteItemsActions(ownerId) {
await deleteItems(ownerId)
revalidatePath("/")
}

export async function updateItemAction(
id: string,
name: string,
expiredAt: string
) {
export async function updateItemAction(id, name, expiredAt) {
await updateItemById(id, name, expiredAt)
revalidatePath("/")
}

export async function incrementCounterAction(email: string) {
export async function incrementCounterAction(email) {
await incrementCounter(email)
revalidatePath("/")
}

export async function incrementWasteCounterAction(email: string) {
export async function incrementWasteCounterAction(email) {
await incrementWasteCounter(email)
revalidatePath("/")
}

export async function incrementLogCounterAction(email: string) {
export async function incrementLogCounterAction(email) {
await incrementLogCounter(email)
revalidatePath("/")
}

export async function incrementMistakeCounterAction(email: string) {
export async function incrementMistakeCounterAction(email) {
await incrementMistakeCounter(email)
revalidatePath("/")
}
40 changes: 20 additions & 20 deletions app/components/SingleItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useState } from "react"
import { useSession } from "next-auth/react"
import Calendar from "react-calendar"
import { ReloadIcon } from "@radix-ui/react-icons"
import { homes } from "../data/homes"
import { useSpring, a } from "@react-spring/web"
import "react-calendar/dist/Calendar.css"

Expand All @@ -26,8 +25,7 @@ const SingleItemView = ({
}) => {
const { data: session } = useSession()
const [value, onChange] = useState(new Date())
const [isModalOpen, setModalOpen] = useState(false)
const [selected, setSelected] = useState(homes[0])
const [isFinishedModalOpen, setFinishedModalOpen] = useState(false)
const [deleteLoading, setDeleteLoading] = useState(false)
const [wasteLoading, setWasteLoading] = useState(false)
const [updateLoading, setUpdateLoading] = useState(false)
Expand All @@ -49,7 +47,7 @@ const SingleItemView = ({
await incrementCounterAction(session.user.email)
}
handleSelectItem(null)
setModalOpen(false)
setFinishedModalOpen(false)
setDeleteLoading(false)
setMistaken(false)
}
Expand All @@ -59,22 +57,21 @@ const SingleItemView = ({
await createWastedItemAction(session.user.email, data.name)
await deleteItemAction(data.id)
await incrementWasteCounterAction(session.user.email)
setModalOpen(false)
setFinishedModalOpen(false)
setWasteLoading(false)
handleSelectItem(null)
}

const updateItem = async (data, newHome) => {
const updateItem = async (data) => {
setUpdateLoading(true)
await updateItemAction(data.id, data.name, value, newHome.name)
await updateItemAction(data.id, data.name, value)
toast.info(`${data.name} Use By Date set!`, {
position: "top-center",
autoClose: 1000,
})
handleEditToggle(false)
handleSelectItem(null)
onChange(new Date())
setSelected(homes[0])
setUpdateLoading(false)
}

Expand All @@ -83,7 +80,10 @@ const SingleItemView = ({
setModalOpen(true)
}

function Modal({ onClose, children }) {
//Mistaken Modal

//Item Finished Modal
function FinishedModal({ onClose, children }) {
return (
<div
style={{
Expand Down Expand Up @@ -111,15 +111,11 @@ const SingleItemView = ({
>
{children}
<h3 className="text-base font-quicksandBold leading-6 text-gray-900">
{`${mistaken ? "Item added by mistake" : "Item Finished"}`}
{"Item Finished"}
</h3>
<div className="mt-2">
<p className="text-sm text-gray-500 font-quicksand">
{`${
mistaken
? "Was this item added by mistake?"
: " Was any of this item wasted?"
}`}
{" Was any of this item wasted?"}
</p>
</div>
<div className="mt-5">
Expand All @@ -134,11 +130,11 @@ const SingleItemView = ({
<div className="flex justify-center items-center">
{deleteLoading ? (
<div className="flex justify-center items-center">
{mistaken ? "Deleting..." : "Yay"}
{"Yay"}
<ReloadIcon className="ml-2 h-4 w-4 animate-spin" />
</div>
) : (
<>{mistaken ? "Yes!" : "Nope!"}</>
<>{"Nope!"}</>
)}
</div>
</button>
Expand All @@ -158,7 +154,7 @@ const SingleItemView = ({
<ReloadIcon className="ml-2 h-4 w-4 animate-spin" />
</div>
) : (
"Yes..."
"Yes"
)}
</div>
</button>
Expand All @@ -178,7 +174,11 @@ const SingleItemView = ({

return (
<>
{isModalOpen && <Modal onClose={() => setModalOpen(false)}></Modal>}
{isFinishedModalOpen && (
<FinishedModal
onClose={() => setFinishedModalOpen(false)}
></FinishedModal>
)}

<div className="flex flex-col m-6">
<h2 className="text-left pb-2 font-quicksandBold text-lg text-slate-600">
Expand Down Expand Up @@ -225,7 +225,7 @@ const SingleItemView = ({
{editStatus ? (
<button
onClick={() => {
updateItem(item, item.name, selected)
updateItem(item)
}}
className={`shadow-lg my-3 py-2 px-3 rounded-md ${
updateLoading
Expand Down
5 changes: 0 additions & 5 deletions app/data/homes.js

This file was deleted.

7 changes: 0 additions & 7 deletions app/data/ingredients.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ export const ingredientsObjects = [
storageTip:
"Store on counter until ripe, then refrigerate. If you've cut an avocado and have leftover halves, keep the pit in the unused half and wrap it tightly in plastic wrap or place it in an airtight container. This helps minimize exposure to air and slows down browning.",
},
// {
// id: "0p2e5f6c",
// name: "Baby Formula",
// expInt: 7,
// storageTip:
// "Keep unopened containers of powdered formula in a cool, dry place. Direct sunlight can degrade the nutrients in the formula. Avoid areas with high humidity. Always check the expiration date before using the formula. Do not use formula past its expiration date.",
// },
{
id: "0c2e3f6d",
name: "Bacon",
Expand Down
75 changes: 0 additions & 75 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -1,78 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
:root {
--background: 0 0% 100%;
--foreground: 224 71.4% 4.1%;

--muted: 220 14.3% 95.9%;
--muted-foreground: 220 8.9% 46.1%;

--popover: 0 0% 50%;
--popover-foreground: 224 71.4% 4.1%;

--card: 0 0% 100%;
--card-foreground: 224 71.4% 4.1%;

--border: 220 13% 91%;
--input: 220 13% 91%;

--primary: 220.9 39.3% 11%;
--primary-foreground: 210 20% 98%;

--secondary: 220 14.3% 95.9%;
--secondary-foreground: 220.9 39.3% 11%;

--accent: 220 14.3% 95.9%;
--accent-foreground: 220.9 39.3% 11%;

--destructive: 0 84.2% 60.2%;
--destructive-foreground: 210 20% 98%;

--ring: 217.9 10.6% 64.9%;

--radius: 0.5rem;
}

.dark {
--background: 224 71.4% 4.1%;
--foreground: 210 20% 98%;

--muted: 215 27.9% 16.9%;
--muted-foreground: 217.9 10.6% 64.9%;

--popover: 224 71.4% 4.1%;
--popover-foreground: 210 20% 98%;

--card: 224 71.4% 4.1%;
--card-foreground: 210 20% 98%;

--border: 215 27.9% 16.9%;
--input: 215 27.9% 16.9%;

--primary: 210 20% 98%;
--primary-foreground: 220.9 39.3% 11%;

--secondary: 215 27.9% 16.9%;
--secondary-foreground: 210 20% 98%;

--accent: 215 27.9% 16.9%;
--accent-foreground: 210 20% 98%;

--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 85.7% 97.3%;

--ring: 215 27.9% 16.9%;
}
}

/* @layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
} */
10 changes: 3 additions & 7 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import "./globals.css"
import { Analytics } from "@vercel/analytics/react"
import { Inter, Quicksand } from "next/font/google"
import { Quicksand } from "next/font/google"
import CustomToastContainer from "./common/CustomToastContainer"
import Provider from "./context/AuthContext"
import "react-toastify/dist/ReactToastify.css"

const inter = Inter({ subsets: ["latin"] })

export const metadata = {
title: "MinWaste App",
description: "A website to help reduce your food waste",
Expand All @@ -32,10 +30,8 @@ const quicksandBold = Quicksand({

export default function RootLayout({ children }) {
return (
<html className="h-full bg-slate-50/50" lang="en">
<body
className={`${inter.className} ${quicksand.variable} ${quicksandBold.variable} bg-slate-50/50 h-full`}
>
<html lang="en">
<body className={`${quicksand.variable} ${quicksandBold.variable}`}>
<Provider>
<CustomToastContainer />
{children}
Expand Down
15 changes: 0 additions & 15 deletions components.json

This file was deleted.

8 changes: 8 additions & 0 deletions prisma/migrations/20231026171608_remove_homes/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `home` on the `Item` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Item" DROP COLUMN "home";
1 change: 0 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ model Item {
expiredAt DateTime?
owner User @relation(fields: [ownerId], references: [id])
ownerId String
home String?
}

model ConsumedItem {
Expand Down
20 changes: 8 additions & 12 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import { PrismaClient } from "@prisma/client";
import { PrismaClient } from "@prisma/client"

const prisma = new PrismaClient();
const prisma = new PrismaClient()

async function main() {
// do your database stuff here
// then run the file
const item = await prisma.item.update({
where: {
// ... provide filter here
id: "634c3d28-61db-472f-89f2-5454fc9ece31",
},
data: {
// ... provide data here
name: "White Grapes",
},
});
})
}

main()
.then(async () => {
await prisma.$disconnect();
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
Loading

0 comments on commit 173c24a

Please sign in to comment.