From 0ed7faa69b1d503cc43bfa750b405cee45dfc5d4 Mon Sep 17 00:00:00 2001 From: Max Tyson <98maxt98@gmail.com> Date: Tue, 12 Mar 2024 22:23:18 +1300 Subject: [PATCH] IDE Checks --- .idea/inspectionProfiles/Project_Default.xml | 9 ++++++ LICENSE | 2 +- README.md | 25 ++++++++-------- website/src/components/dropdown_section.tsx | 2 +- website/src/components/footer.tsx | 2 ++ website/src/components/infinteLoading.tsx | 2 +- website/src/components/layout.tsx | 1 - website/src/components/page_header.tsx | 2 +- website/src/components/plant_sections.tsx | 5 +--- website/src/components/slider.tsx | 6 ++-- website/src/components/stats.tsx | 3 +- website/src/lib/api_tools.ts | 13 ++++---- website/src/lib/cache.ts | 2 +- website/src/lib/plant_data.ts | 4 +-- website/src/lib/users.ts | 2 +- website/src/pages/account/edit.tsx | 8 +---- website/src/pages/account/index.tsx | 14 +++------ website/src/pages/account/keys/[id].tsx | 8 +---- website/src/pages/account/keys/create.tsx | 7 +---- website/src/pages/admin/settings.tsx | 5 ++-- website/src/pages/admin/users.tsx | 1 - website/src/pages/api/auth/[...nextauth].ts | 2 +- .../src/pages/api/files/backup_database.ts | 7 ++--- website/src/pages/api/files/upload.ts | 10 ------- website/src/pages/api/plants/download.ts | 2 +- website/src/pages/api/plants/upload.ts | 2 ++ website/src/pages/calendar.tsx | 9 ++---- website/src/pages/index.tsx | 11 ++----- website/src/pages/plants/[id].tsx | 9 ++---- website/src/pages/plants/create.tsx | 30 ++++++++----------- website/src/pages/plants/index.tsx | 2 -- website/src/pages/plants/mushrooms.tsx | 6 ---- website/src/pages/plants/plant_index.tsx | 12 +++----- website/src/pages/search.tsx | 13 +++----- .../components/input_sections.module.css | 2 +- .../src/styles/components/navbar.module.css | 4 +-- .../components/plant_sections.module.css | 2 +- .../src/styles/pages/account/index.module.css | 2 +- website/src/styles/pages/index.module.css | 2 +- .../src/styles/pages/plant_index.module.css | 2 +- website/src/styles/pages/plants/id.module.css | 2 +- 41 files changed, 94 insertions(+), 160 deletions(-) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 03d9549..a2fd731 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,6 +1,15 @@ \ No newline at end of file diff --git a/LICENSE b/LICENSE index ba14586..35de57a 100644 --- a/LICENSE +++ b/LICENSE @@ -12,7 +12,7 @@ modification, are permitted provided that the following conditions are met: this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -3. Neither the name of the copyright holder nor the names of its +3. Neither the name of the copyright holder nor the names of it's contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/README.md b/README.md index ad99d36..0c3505f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +

@@ -41,7 +42,7 @@ ![Screen Shot](doc/screenshots/about.png) -This project is built on top of next js and a SQL database to create a website that informs users about various New Zealand plants and their uses. The website aims to display this information in a interesting, entertaining and interactive way with the site being accessible to a wide range of users on mobile or PC. The plants are stored in a SQL database which the website uses to dynamically generate the contents for the pages from, with it heavily relying on the ID of the plant to do most things. Additonally, a API is provided to interact with the database connected to the site allowing for the user to search for a plant or download a plant's information. Parts of the API that modify data are restricted behind user authentication, either in the form of an API key or a whitelisted email in the auth table of the database. +This project is built on top of Next.js and a SQL database to create a website that informs users about various New Zealand plants and their uses. The website aims to display this information in an interesting, entertaining and interactive way with the site being accessible to a wide range of users on mobile or PC. The plants are stored in a SQL database which the website uses to dynamically generate the contents for the pages from, with it heavily relying on the ID of the plant to do most things. Additionally, an API is provided to interact with the database connected to the site allowing for the user to search for a plant or download a plant's information. Parts of the API that modify data are restricted behind user authentication, either in the form of an API key or a whitelisted email in the auth table of the database. ## Built With @@ -58,7 +59,7 @@ To get a local copy up and running follow these simple steps. ### Prerequisites -The website requires npm and node js +The website requires npm and Node.js * [node.js](https://nodejs.org/en) * [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) @@ -75,24 +76,24 @@ git clone https://github.com/maxtyson123/13_DGT_WEBSITE.git npm install ``` * Copy the '.env.example' into a new file '.env.local' -2. Database Setup (Pick one and edit constants.ts to select which one is being used) +1. Database Setup (Pick one and edit constants.ts to select which one is being used) 2. A) Postgres: * Setup a Postgres server [PostgreSQL](https://www.postgresql.org/) * Copy the config into .env.local * Run the SQL file [create_tables](server/postgres_sql/create_tables.sql) -2. B) MySQL: +1. B) MySQL: * Setup a MySQL server [MySQL](https://www.mysql.com/) * Copy the config into .env.local * Run the SQL file [create_tables](server/my_sql/create_tables.sql) -3. FTP Setup: +1. FTP Setup: * Download [FileZilla](https://filezilla-project.org/download.php) or any other FTP provider * Copy the config into .env.local -4. Github Setup: -* Go to [Github Apps](https://github.com/settings/apps) and press 'New App' +1. GitHub Setup: +* Go to [GitHub Apps](https://github.com/settings/apps) and press 'New App' * Set the GitHub App name to Rongoā * Set the homepage and callback URLs to your site, e.g. ```sh @@ -101,9 +102,9 @@ http://localhost:3000/api/auth/callback/github * Under account permissions set Email addresses to read only * Once completed creation, create a new client secret * Copy the config into .env.local -5. Other OAuth Setup: -* Follow NextAuth.js's [documentation](https://next-auth.js.org/configuration/providers/oauth) to setup other OAuth providers -6. Run the site +1. Other OAuth Setup: +* Follow NextAuth.js's [documentation](https://next-auth.js.org/configuration/providers/oauth) to set up other OAuth providers +1. Run the site ```sh cd website npm run dev @@ -126,7 +127,7 @@ To add an api key, go to the user profile page and press the generate api key bu Go to the [/plants/create](https://13-dgt-website.vercel.app/plants/create) page and enter the information for the plant. Once you are finished, press the upload button, or if you wish to continue creating the plant later, press generate JSON (note: images and attachments will have to be selected again). ##### Edit Plants -Go to the [/plants/create?id={id_of_plant}](https://13-dgt-website.vercel.app/plants/create) page and edit the information for the plant. Once you are finished, press the upload button and it will modify that plant. +Go to the [/plants/create?id={id_of_plant}](https://13-dgt-website.vercel.app/plants/create) page and edit the information for the plant. Once you are finished, press the upload button, and it will modify that plant. _For more examples, please refer to the [Documentation](https://maxtyson123.github.io/13_DGT_WEBSITE)_ @@ -137,7 +138,7 @@ See the [open issues](https://github.com/maxtyson123/13_DGT_WEBSITE/issues) for ## Contributing -Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. +Contributions are what make the open source community such an amazing place to be learned, inspire, and create. Any contributions you make are **greatly appreciated**. * If you have suggestions for adding or removing projects, feel free to [open an issue](https://github.com/maxtyson123/13_DGT_WEBSITE/issues/new) to discuss it, or directly create a pull request after you edit the *README.md* file with necessary changes. * Please make sure you check your spelling and grammar. * Create individual PR for each suggestion. diff --git a/website/src/components/dropdown_section.tsx b/website/src/components/dropdown_section.tsx index cc14c6e..68cae91 100644 --- a/website/src/components/dropdown_section.tsx +++ b/website/src/components/dropdown_section.tsx @@ -1,4 +1,4 @@ -import {useState} from "react"; +import React, {useState} from "react"; import styles from "@/styles/components/dropdown_section.module.css"; interface DropdownSectionProps { diff --git a/website/src/components/footer.tsx b/website/src/components/footer.tsx index 947fe24..c6609d9 100644 --- a/website/src/components/footer.tsx +++ b/website/src/components/footer.tsx @@ -1,3 +1,5 @@ +// noinspection SpellCheckingInspection + import Image from "next/image"; import React, {useEffect} from "react"; import styles from "@/styles/components/footer.module.css"; diff --git a/website/src/components/infinteLoading.tsx b/website/src/components/infinteLoading.tsx index a5e2bf6..10b9c93 100644 --- a/website/src/components/infinteLoading.tsx +++ b/website/src/components/infinteLoading.tsx @@ -75,4 +75,4 @@ export function InfiniteLoading({searchQuery} : InfiniteLoadingProps) { ) -}; \ No newline at end of file +} \ No newline at end of file diff --git a/website/src/components/layout.tsx b/website/src/components/layout.tsx index 03030da..eef009c 100644 --- a/website/src/components/layout.tsx +++ b/website/src/components/layout.tsx @@ -3,7 +3,6 @@ import HtmlHeader from "@/components/html_header"; import Navbar from "@/components/navbar"; import Section from "@/components/section"; import Footer from "@/components/footer"; -import ScrollToTop from "@/components/scroll_to_top"; import PageHeader from "@/components/page_header"; import styles from "@/styles/pages/account/index.module.css"; import {Loading} from "@/components/loading"; diff --git a/website/src/components/page_header.tsx b/website/src/components/page_header.tsx index ec72eac..e1129cc 100644 --- a/website/src/components/page_header.tsx +++ b/website/src/components/page_header.tsx @@ -62,7 +62,7 @@ export default function PageHeader({ children, size = "medium" }: PageHeaderProp /> - {/* This is the container for the header, it uses css to centre its contents*/} + {/* This is the container for the header, it uses css to centre it's contents*/}

{/* This is the blurred background for what ever is made to be displayed in the header */} diff --git a/website/src/components/plant_sections.tsx b/website/src/components/plant_sections.tsx index 804f810..94a9ce0 100644 --- a/website/src/components/plant_sections.tsx +++ b/website/src/components/plant_sections.tsx @@ -345,10 +345,7 @@ interface SourceSectionProps{ * @returns {JSX.Element} The rendered section component. */ export function SourceSection({section} : SourceSectionProps){ - let sourceItem = ( - <> - - ) + let sourceItem: JSX.Element switch (section.source_type){ case "Internet": diff --git a/website/src/components/slider.tsx b/website/src/components/slider.tsx index c680790..4af3ce3 100644 --- a/website/src/components/slider.tsx +++ b/website/src/components/slider.tsx @@ -1,3 +1,5 @@ +// noinspection SpellCheckingInspection + import React from "react"; import "owl.carousel/dist/assets/owl.carousel.css"; import "owl.carousel/dist/assets/owl.theme.default.css"; @@ -5,9 +7,9 @@ import styles from "@/styles/components/slider.module.css"; import dynamic from "next/dynamic"; -var $ = require("jquery"); +const $ = require("jquery"); if (typeof window !== "undefined") { - // @ts-ignore - This is a hack to get around the fact that the window object doesn't like jquery in nextjs + // @ts-ignore - This is a hack to get around the fact that the window object doesn't like jquery in Next.js window.$ = window.jQuery = require("jquery"); } diff --git a/website/src/components/stats.tsx b/website/src/components/stats.tsx index 32b0f29..ed3b0b5 100644 --- a/website/src/components/stats.tsx +++ b/website/src/components/stats.tsx @@ -3,7 +3,6 @@ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faBookMedical, faBowlFood, faSeedling, faTools} from "@fortawesome/free-solid-svg-icons"; import React, {useEffect, useRef, useState} from "react"; import {getFromCache, saveToCache} from "@/lib/cache"; -import axios from "axios"; import {useRouter} from "next/router"; import {makeRequestWithToken} from "@/lib/api_tools"; @@ -34,7 +33,7 @@ export default function Stats(){ async function fetchData() { try { - let res = null; + let res: null; const storedData = getFromCache("plant_stats"); diff --git a/website/src/lib/api_tools.ts b/website/src/lib/api_tools.ts index 52fc8d4..c684d1d 100644 --- a/website/src/lib/api_tools.ts +++ b/website/src/lib/api_tools.ts @@ -47,7 +47,7 @@ export async function checkApiPermissions(request: NextApiRequest, response: Nex }else{ token = token.data - let requestURL = request.url + let requestURL: string | undefined // Remove any query parameters token = token.split("?")[0] @@ -78,14 +78,14 @@ export async function checkApiPermissions(request: NextApiRequest, response: Nex // Parse the log let log = JSON.parse(api_key_data.api_key_logs) - // Check if the log is at its limit + // Check if the log is at it's limit if(log.length >= 100 && !checkPermissions(permissions, "data:logs:unlimitedApiLogEntries")){ - // Remove the item at 1 because don't want to remove the first item as its the creation data + // Remove the item at 1 because don't want to remove the first item as it's the creation data log.splice(1, 1) - // Overwrite the new item to state that the log is at its limit - log[1] = {time: new Date().toISOString(), action: "Previous log entries have been removed as the log is at its limit of 100 entries"} + // Overwrite the new item to state that the log is at it's limit + log[1] = {time: new Date().toISOString(), action: "Previous log entries have been removed as the log is at it's limit of 100 entries"} } @@ -153,8 +153,7 @@ export async function makeRequestWithToken ( try { // Make the request - const response = await axios(axiosConfig); - return response; + return await axios(axiosConfig); } catch (error : any) { // Handle errors console.error('Request failed:', error.message); diff --git a/website/src/lib/cache.ts b/website/src/lib/cache.ts index 0bfeac8..7cdc5f9 100644 --- a/website/src/lib/cache.ts +++ b/website/src/lib/cache.ts @@ -14,7 +14,7 @@ interface CacheItem { */ export function getFromCache(id: string){ - let item = null; + let item: null; item = sessionStorage.getItem(id); // Check if the item exists in the local storage diff --git a/website/src/lib/plant_data.ts b/website/src/lib/plant_data.ts index 5cab4e7..23fbe42 100644 --- a/website/src/lib/plant_data.ts +++ b/website/src/lib/plant_data.ts @@ -84,7 +84,7 @@ export interface ImageMetaData { } /** - * Meta data for a file, (attachment.meta) + * Metadata for a file, (attachment.meta) * * @see {@link AttachmentSectionData} */ @@ -818,7 +818,7 @@ export async function fetchPlant (id: number) { } /** - * Will fix the paths of the attachments to be the proper path, this is because when uploading the attachments the path is set to the local path on the server, this will change it to the public path. The local path is used as the plant has no way of knowing its ID until it is saved to the database, it will ignore any attachments that start with http as they are already using the public path. + * Will fix the paths of the attachments to be the proper path, this is because when uploading the attachments the path is set to the local path on the server, this will change it to the public path. The local path is used as the plant has no way of knowing it's ID until it is saved to the database, it will ignore any attachments that start with http as they are already using the public path. * * @param {PlantData} plant - The plant data to fix the paths of * diff --git a/website/src/lib/users.ts b/website/src/lib/users.ts index 93fe2c9..b39d9d4 100644 --- a/website/src/lib/users.ts +++ b/website/src/lib/users.ts @@ -326,7 +326,7 @@ export function getUserPermissions(user: RongoaUser | null) { permissions.api.plants.months.publicAccess = true; permissions.api.plants.random.publicAccess = true; permissions.api.plants.search.publicAccess = true; - permissions.api.plants.uses.publicAccess = true;; + permissions.api.plants.uses.publicAccess = true; permissions.api.user.data.publicAccess = true; permissions.api.user.plants.publicAccess = true; diff --git a/website/src/pages/account/edit.tsx b/website/src/pages/account/edit.tsx index ba216b3..a51d40c 100644 --- a/website/src/pages/account/edit.tsx +++ b/website/src/pages/account/edit.tsx @@ -1,17 +1,11 @@ -import HtmlHeader from "@/components/html_header"; -import Navbar from "@/components/navbar"; import React, {useEffect, useRef, useState} from "react"; import Section from "@/components/section"; -import Footer from "@/components/footer"; -import PageHeader from "@/components/page_header"; import styles from "@/styles/pages/account/index.module.css" import {useSession} from "next-auth/react"; import {ADMIN_USER_TYPE, EDITOR_USER_TYPE, MEMBER_USER_TYPE, RongoaUser, UserDatabaseDetails} from "@/lib/users"; import {globalStyles} from "@/lib/global_css"; import {useRouter} from "next/router"; -import {Error} from "@/components/error"; import {FileInput, SmallInput, ValidationState} from "@/components/input_sections"; -import {Loading} from "@/components/loading"; import {makeRequestWithToken} from "@/lib/api_tools"; import {Layout} from "@/components/layout"; @@ -133,7 +127,7 @@ export default function EditAccount() { // Email is valid setValidUserEmail(["success", "no error"]) - // Check that there is a image being uploaded + // Check that there is an image being uploaded if(userLocalImage !== null) { console.log(userLocalImage) diff --git a/website/src/pages/account/index.tsx b/website/src/pages/account/index.tsx index 4d9c0d2..81acfec 100644 --- a/website/src/pages/account/index.tsx +++ b/website/src/pages/account/index.tsx @@ -1,14 +1,10 @@ -import HtmlHeader from "@/components/html_header"; -import Navbar from "@/components/navbar"; import React, {useEffect, useRef, useState} from "react"; import Section from "@/components/section"; -import Footer from "@/components/footer"; -import PageHeader from "@/components/page_header"; import styles from "@/styles/pages/account/index.module.css" import statsStyles from "@/styles/components/stats.module.css" import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; -import {faCamera, faPerson, faSeedling} from "@fortawesome/free-solid-svg-icons"; -import {signIn, signOut, useSession} from "next-auth/react"; +import {faCamera, faSeedling} from "@fortawesome/free-solid-svg-icons"; +import {signOut, useSession} from "next-auth/react"; import { ADMIN_USER_TYPE, checkUserPermissions, @@ -24,9 +20,7 @@ import {DropdownSection} from "@/components/dropdown_section"; import {useRouter} from "next/router"; import Link from "next/link"; import {getNamesInPreference, macronCodeToChar, numberDictionary, PlantData} from "@/lib/plant_data"; -import {Error} from "@/components/error"; import {makeCachedRequest, makeRequestWithToken} from "@/lib/api_tools"; -import {Loading} from "@/components/loading"; import {Layout} from "@/components/layout"; export default function Account() { @@ -113,7 +107,7 @@ export function AccountPage({dataID}: AccountPageProps){ if(session?.user) { - // Not viewing a user so we are viewing our own account + // Not viewing a user, so we are viewing our own account // This is our account setMyAccount(true) @@ -291,7 +285,7 @@ export function AccountPage({dataID}: AccountPageProps){ localStorage.removeItem("userApiKeysData_" + userID) // Reload the data - fetchData(userID) + await fetchData(userID) } diff --git a/website/src/pages/account/keys/[id].tsx b/website/src/pages/account/keys/[id].tsx index 78cfe2a..d5be3da 100644 --- a/website/src/pages/account/keys/[id].tsx +++ b/website/src/pages/account/keys/[id].tsx @@ -1,14 +1,8 @@ import {useRouter} from "next/router"; import React, {useEffect, useState} from "react"; import {useSession} from "next-auth/react"; -import HtmlHeader from "@/components/html_header"; -import Navbar from "@/components/navbar"; import Section from "@/components/section"; -import PageHeader from "@/components/page_header"; import styles from "@/styles/pages/account/index.module.css"; -import {Loading} from "@/components/loading"; -import {Error} from "@/components/error"; -import Footer from "@/components/footer"; import {makeCachedRequest, makeRequestWithToken} from "@/lib/api_tools"; import {checkUserPermissions, getStrings, RongoaUser} from "@/lib/users"; import {DropdownSection} from "@/components/dropdown_section"; @@ -62,7 +56,7 @@ export default function KeyViewer(){ apiUrl += "&publicUserID=" + user }else{ // Send them to their account page - router.push("/account") + await router.push("/account") } } diff --git a/website/src/pages/account/keys/create.tsx b/website/src/pages/account/keys/create.tsx index 5686022..dba6164 100644 --- a/website/src/pages/account/keys/create.tsx +++ b/website/src/pages/account/keys/create.tsx @@ -1,16 +1,11 @@ -import HtmlHeader from "@/components/html_header"; -import Navbar from "@/components/navbar"; import React, {useEffect} from "react"; import Section from "@/components/section"; -import Footer from "@/components/footer"; -import PageHeader from "@/components/page_header"; import styles from "@/styles/pages/account/index.module.css" import {useSession} from "next-auth/react"; import {useRouter} from "next/router"; import {SmallInput, ValidationState} from "@/components/input_sections"; import {getDefaultPermissions, getStrings, getUserPermissions, RongoaUser, UserPermissions} from "@/lib/users"; import {makeRequestWithToken} from "@/lib/api_tools"; -import {Loading} from "@/components/loading"; import {Error} from "@/components/error"; import {Layout} from "@/components/layout"; @@ -146,7 +141,7 @@ export function AccountPage({dataID}: AccountPageProps){ setLoading(false) // Go to the account page - router.push("/account/") + await router.push("/account/") } diff --git a/website/src/pages/admin/settings.tsx b/website/src/pages/admin/settings.tsx index ce84ca8..0adc3db 100644 --- a/website/src/pages/admin/settings.tsx +++ b/website/src/pages/admin/settings.tsx @@ -1,9 +1,8 @@ import Section from "@/components/section"; import styles from "@/styles/pages/admin.module.css"; import Link from "next/link"; -import React, {useEffect, useRef, useState} from "react"; +import React, {useState} from "react"; import {useSession} from "next-auth/react"; -import {checkUserPermissions, RongoaUser} from "@/lib/users"; import {makeRequestWithToken} from "@/lib/api_tools"; import {globalStyles} from "@/lib/global_css"; import { useLogger } from 'next-axiom'; @@ -99,7 +98,7 @@ export default function Admin(){ setLoadingMessage("") } - // Log that the admin imported a back up + // Log that the admin imported a back-up log.info(`Admin ${session?.user?.email} imported back up`) // Clear the cache diff --git a/website/src/pages/admin/users.tsx b/website/src/pages/admin/users.tsx index 8dc8fa8..f7d3e4f 100644 --- a/website/src/pages/admin/users.tsx +++ b/website/src/pages/admin/users.tsx @@ -10,7 +10,6 @@ import { useLogger } from 'next-axiom'; import Table from "@/components/table"; import {Layout} from "@/components/layout"; import {useRouter} from "next/router"; -import {getNamesInPreference} from "@/lib/plant_data"; export default function Admin(){ const pageName = "Admin"; diff --git a/website/src/pages/api/auth/[...nextauth].ts b/website/src/pages/api/auth/[...nextauth].ts index ee788af..59ba29f 100644 --- a/website/src/pages/api/auth/[...nextauth].ts +++ b/website/src/pages/api/auth/[...nextauth].ts @@ -23,7 +23,7 @@ export const authOptions: NextAuthOptions = { async jwt({ token, trigger, session}) { - // If there isnt the user data in the token the fetch it + // If there isn't the user data in the token the fetch it if(!token.user) { // Get the tables and client diff --git a/website/src/pages/api/files/backup_database.ts b/website/src/pages/api/files/backup_database.ts index 076dcce..4f72afb 100644 --- a/website/src/pages/api/files/backup_database.ts +++ b/website/src/pages/api/files/backup_database.ts @@ -1,13 +1,10 @@ import {NextApiRequest, NextApiResponse} from 'next'; -import {getClient, getTables, makeQuery, PostgresSQL, SQLDatabase} from "@/lib/databse"; +import {getClient, getTables, makeQuery} from "@/lib/databse"; import {checkApiPermissions} from "@/lib/api_tools"; import {getServerSession} from "next-auth"; import {authOptions} from "@/pages/api/auth/[...nextauth]"; import { Logger } from 'next-axiom'; -import {Form} from "multiparty"; -import {USE_POSTGRES} from "@/lib/constants"; -import Client from "ftp"; -import fs from "fs"; + export default async function handler( request: NextApiRequest, response: NextApiResponse, diff --git a/website/src/pages/api/files/upload.ts b/website/src/pages/api/files/upload.ts index c9c2086..7a4fb46 100644 --- a/website/src/pages/api/files/upload.ts +++ b/website/src/pages/api/files/upload.ts @@ -8,7 +8,6 @@ import {checkApiPermissions} from "@/lib/api_tools"; import {getServerSession} from "next-auth"; import {authOptions} from "@/pages/api/auth/[...nextauth]"; import { Logger } from 'next-axiom'; -import {AttachmentData} from "@/lib/plant_data"; function createUpSertQuery(table: string, columns: string[], data: any[]) { @@ -269,15 +268,6 @@ export default async function handler( path = "plants"; } - - // Check if the data is being downloaded from the Postgres database - let tables = new SQLDatabase(); - - // Set the tables to use - if(USE_POSTGRES) { - tables = new PostgresSQL(); - } - // Check if there is an error if (err) { return response.status(500).json({ error: 'Error parsing form data.', data: err }); diff --git a/website/src/pages/api/plants/download.ts b/website/src/pages/api/plants/download.ts index 125ab4d..7ce2314 100644 --- a/website/src/pages/api/plants/download.ts +++ b/website/src/pages/api/plants/download.ts @@ -53,7 +53,7 @@ export async function downloadPlantData(table: any, id: any, client: any, restri // Try downloading the data from the database try { - // Convert the table to an array if its just one table + // Convert the table to an array if it's just one table let tableArray = table; if(typeof table === 'string'){ tableArray = [table]; diff --git a/website/src/pages/api/plants/upload.ts b/website/src/pages/api/plants/upload.ts index a5d21cb..31929a2 100644 --- a/website/src/pages/api/plants/upload.ts +++ b/website/src/pages/api/plants/upload.ts @@ -1,3 +1,5 @@ +// noinspection SpellCheckingInspection + import {NextApiRequest, NextApiResponse} from 'next'; import {getClient, getTables, makeQuery} from "@/lib/databse"; import {USE_POSTGRES} from "@/lib/constants"; diff --git a/website/src/pages/calendar.tsx b/website/src/pages/calendar.tsx index 3cc0ba9..c676b12 100644 --- a/website/src/pages/calendar.tsx +++ b/website/src/pages/calendar.tsx @@ -1,10 +1,5 @@ -import Navbar from "@/components/navbar"; -import HtmlHeader from "@/components/html_header"; import React, {useEffect, useRef} from "react"; import Section from "@/components/section"; -import Footer from "@/components/footer"; -import ScrollToTop from "@/components/scroll_to_top"; -import PageHeader from "@/components/page_header"; import styles from "@/styles/pages/calendar.module.css"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faArrowLeft, faArrowRight} from "@fortawesome/free-solid-svg-icons"; @@ -71,7 +66,7 @@ export default function Calendar(){ async function fetchData() { try { - let res = null; + let res: null; const storedData = getFromCache("plant_months"); @@ -209,7 +204,7 @@ function EventEntryDisplayed({entry, month, prevMonth, nextMonth}: EventEntryDis type = "OnGoing" style = styles.onGoing }else{ - // If this is reached then the month is not between the start and end month, but it still could be looped around (e.g dec - march) + // If this is reached then the month is not between the start and end month, but it still could be looped around (e.g. dec - march) // If the end month is less than the start month then the event is ongoing if(entry.endMonth < entry.startMonth){ if ((month >= entry.startMonth && month <= 12) || (month >= 1 && month < entry.endMonth)) { diff --git a/website/src/pages/index.tsx b/website/src/pages/index.tsx index 55ed9d4..58c795a 100644 --- a/website/src/pages/index.tsx +++ b/website/src/pages/index.tsx @@ -3,27 +3,20 @@ import React, {useEffect, useRef} from "react"; import styles from "@/styles/pages/index.module.css" -import Navbar from "@/components/navbar"; -import HtmlHeader from "@/components/html_header"; import Section from "@/components/section"; -import PageHeader from "@/components/page_header"; import SearchBox from "@/components/search_box"; import {PlantCardApi, PlantCardLoading} from "@/components/plant_card"; import Stats from "@/components/stats"; -import Footer from "@/components/footer"; -import ScrollToTop from "@/components/scroll_to_top"; import {getFromCache, saveToCache} from "@/lib/cache"; import {globalStyles} from "@/lib/global_css"; import Image from "next/image"; import Slider from "@/components/slider"; import {AttachmentData, fetchPlant, ImageMetaData} from "@/lib/plant_data"; import {CreditedImage} from "@/components/credits"; -import {QueryClient} from "@tanstack/react-query"; import {ModalImage} from "@/components/modal"; import {makeRequestWithToken} from "@/lib/api_tools"; import {useSession} from "next-auth/react"; import {UserDatabaseDetails} from "@/lib/users"; -import {any} from "prop-types" import {Layout} from "@/components/layout"; export default function Home() { @@ -78,7 +71,7 @@ export default function Home() { const user = userData.data.data as UserDatabaseDetails - update({database: user}) + await update({database: user}) saveToCache("user_data_refreshed", true) } } @@ -163,7 +156,7 @@ export default function Home() { }) }, [plantIds]) - // Handle screensize changes + // Handle screen size changes useEffect(() => { // If the screen is mobile sized, set the isMobile state to true diff --git a/website/src/pages/plants/[id].tsx b/website/src/pages/plants/[id].tsx index 3d6b75b..8068ad7 100644 --- a/website/src/pages/plants/[id].tsx +++ b/website/src/pages/plants/[id].tsx @@ -1,11 +1,6 @@ import React, {useEffect, useRef} from "react"; import {useRouter} from 'next/router' import Section from "@/components/section"; -import Footer from "@/components/footer"; -import HtmlHeader from "@/components/html_header"; -import Navbar from "@/components/navbar"; -import PageHeader from "@/components/page_header"; -import ScrollToTop from "@/components/scroll_to_top"; import {fetchPlant, getNamesInPreference, ImageMetaData, PlantData} from "@/lib/plant_data"; import styles from "@/styles/pages/plants/id.module.css"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; @@ -117,7 +112,7 @@ export default function PlantPage() { }, []); - // Handle screensize changes + // Handle screen size changes useEffect(() => { // If the screen is mobile sized, set the isMobile state to true @@ -194,7 +189,7 @@ export default function PlantPage() { } - }, [plantData]); + }, [plantData, setMainImageFromIndex]); const changeImage = (index: number) => { diff --git a/website/src/pages/plants/create.tsx b/website/src/pages/plants/create.tsx index af27e31..add405b 100644 --- a/website/src/pages/plants/create.tsx +++ b/website/src/pages/plants/create.tsx @@ -27,19 +27,15 @@ import { SourceSectionData, ValidPlantData } from "@/lib/plant_data"; -import Section from "@/components/section"; -import Footer from "@/components/footer"; -import ScrollToTop from "@/components/scroll_to_top"; import {MONTHS, PLANT_PARTS} from "@/lib/constants" import {useRouter} from "next/router"; import {Error} from "@/components/error"; -import {signIn, useSession} from "next-auth/react"; +import {useSession} from "next-auth/react"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; -import {faCloudArrowUp, faFile, faPerson} from "@fortawesome/free-solid-svg-icons"; +import {faCloudArrowUp, faFile} from "@fortawesome/free-solid-svg-icons"; import {globalStyles} from "@/lib/global_css"; -import {checkUserPermissions, RongoaUser} from "@/lib/users"; -import {Loading} from "@/components/loading"; +import {RongoaUser} from "@/lib/users"; import {createToken, makeRequestWithToken} from "@/lib/api_tools"; import axios from "axios"; import {Layout} from "@/components/layout"; @@ -48,7 +44,7 @@ import {Layout} from "@/components/layout"; /// _______________ SECTIONS _______________ /// class SourceInfo { - // Store the data for the section at its current state + // Store the data for the section at it's current state state = { type: "", data: "", @@ -169,7 +165,7 @@ export function SourceSection({typeHandler, dataHandler, valid, state}: SourceSe class CustomInfo { - // Store the data for the section at its current state + // Store the data for the section at it's current state state = { title: "", text: "", @@ -286,7 +282,7 @@ export function CustomSection({titleHandler, textHandler, valid, state}: CustomS class CraftInfo { - // Store the data for the section at its current state + // Store the data for the section at it's current state state = { partOfPlant: "", useIdentifier: "", @@ -466,7 +462,7 @@ export function CraftSection({useIdentifierHandler, useValueHandler, additionalI } class MedicalInfo { - // Store the data for the section at its current state + // Store the data for the section at it's current state state = { type: "", useIdentifier: "", @@ -667,7 +663,7 @@ export function MedicalUseSection({medicalTypeHandler, medicalUseIdentifierHandl class EdibleInfo { - // Store the data for the section at its current state + // Store the data for the section at it's current state state = { partOfPlant: "", useIdentifier: "", @@ -1639,7 +1635,7 @@ export default function CreatePlant() { setEnglishNameValidationState(["error", "Required if preferred name is English"]) isValid = false; - // Dont need to check if null here as there is nothing before it + // Don't need to check if null here as there is nothing before it elementThatNeedsFocus = "english-name"; } } else { setEnglishNameValidationState(["success", "No Error"] as [ValidationState, string]); } @@ -1806,7 +1802,7 @@ export default function CreatePlant() { if(!input) return input; - let clean = input; + let clean: string; // Replace ' with slanted ' clean = input.replaceAll("'", "’"); @@ -2027,7 +2023,7 @@ export default function CreatePlant() { plantOBJ.sections.push(customInfoOBJ); } - // Loop through the sections to double check that the images they use are in the attachments + // Loop through the sections to double-check that the images they use are in the attachments for(let i = 0; i < plantOBJ.sections.length; i++) { // Only Edible, Medical and Craft sections have images @@ -2481,7 +2477,7 @@ export default function CreatePlant() { for(let i = 0; i < imageInfoRef.current.length; i++){ setProgressMessage(`Uploading image ${i + 1} of ${imageInfoRef.current.length}`) - // If the image url is already set to have a url, skip it + // If the image url is already set to have an url, skip it if(imageInfoRef.current[i].state.image_url.startsWith("http")) { continue; } @@ -2604,7 +2600,7 @@ export default function CreatePlant() { return; } - // Get its position on the page + // Get it's position on the page let dims = element.getBoundingClientRect(); // Scroll to it, add 150px spacing so that the nav bar has space, ensure that it is smooth and doesn't just jump diff --git a/website/src/pages/plants/index.tsx b/website/src/pages/plants/index.tsx index e13f107..bf24350 100644 --- a/website/src/pages/plants/index.tsx +++ b/website/src/pages/plants/index.tsx @@ -1,6 +1,4 @@ import React, {useState} from "react"; -import Section from "@/components/section"; -import PageHeader from "@/components/page_header"; import styles from "@/styles/pages/plants/mushrooms.module.css"; import {QueryClient, QueryClientProvider} from "@tanstack/react-query"; import {InfiniteLoading} from "@/components/infinteLoading"; diff --git a/website/src/pages/plants/mushrooms.tsx b/website/src/pages/plants/mushrooms.tsx index dd80e65..f227da3 100644 --- a/website/src/pages/plants/mushrooms.tsx +++ b/website/src/pages/plants/mushrooms.tsx @@ -1,10 +1,4 @@ -import Navbar from "@/components/navbar"; -import HtmlHeader from "@/components/html_header"; import React from "react"; -import Section from "@/components/section"; -import Footer from "@/components/footer"; -import ScrollToTop from "@/components/scroll_to_top"; -import PageHeader from "@/components/page_header"; import styles from "@/styles/pages/plants/mushrooms.module.css"; import {QueryClient, QueryClientProvider} from "@tanstack/react-query"; import {InfiniteLoading} from "@/components/infinteLoading"; diff --git a/website/src/pages/plants/plant_index.tsx b/website/src/pages/plants/plant_index.tsx index 19081df..d7407f6 100644 --- a/website/src/pages/plants/plant_index.tsx +++ b/website/src/pages/plants/plant_index.tsx @@ -1,10 +1,5 @@ -import Navbar from "@/components/navbar"; -import HtmlHeader from "@/components/html_header"; import React, {useEffect, useRef} from "react"; import Section from "@/components/section"; -import Footer from "@/components/footer"; -import ScrollToTop from "@/components/scroll_to_top"; -import PageHeader from "@/components/page_header"; import styles from "@/styles/pages/plant_index.module.css"; import Stats from "@/components/stats"; import {DropdownInput} from "@/components/input_sections"; @@ -20,6 +15,7 @@ interface plantEntry { const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("") +// noinspection SpellCheckingInspection export default function PlantIndex(){ const pageName = "Plant Index" const [plantData, setPlantData] = React.useState(null) @@ -255,7 +251,7 @@ export default function PlantIndex(){ // If the ID is the same then add the plant name to the use if(items[i].id === plantData[j].id) { - // Get the preffered name + // Get the preferred name items[i].name += (" - " + macronCodeToChar(getNamesInPreference(plantData[j])[0], numberDictionary)) break } @@ -278,7 +274,7 @@ export default function PlantIndex(){ console.log(items) setIndexItems(items) - // Re render the components + // Re-render the components setRenderKey(prevState => prevState + 1) @@ -298,7 +294,7 @@ export default function PlantIndex(){

This page contains a list of all the plants on the website. The plants are sorted alphabetically.

-

Click on a plant to view its page.

+

Click on a plant to view it's page.

Use the dropdown below to select what the index should display

{ + const getSearchResults = async (name: string, mushrooms: boolean) => { const startTime = Date.now() @@ -92,9 +87,9 @@ export default function Search(){ console.log("Getting search results") // Get the search results - const response = await makeRequestWithToken("get",`/api/plants/search?name=${name}&mushrooms=${mushroons ? "include" : "exclude"}`) - console.log(mushroons ? "include" : "exclude") - console.log(mushroons) + const response = await makeRequestWithToken("get",`/api/plants/search?name=${name}&mushrooms=${mushrooms ? "include" : "exclude"}`) + console.log(mushrooms ? "include" : "exclude") + console.log(mushrooms) // Get the data from the response const data = response.data.data diff --git a/website/src/styles/components/input_sections.module.css b/website/src/styles/components/input_sections.module.css index fcd7f60..b31c80e 100644 --- a/website/src/styles/components/input_sections.module.css +++ b/website/src/styles/components/input_sections.module.css @@ -118,7 +118,7 @@ border-radius: 8px; box-sizing: border-box; width: 100%; - color: #ABAFB1; /* Input can have its own gray the works with most themes */ + color: #ABAFB1; /* Input can have it's own gray the works with most themes */ font-size: 16px; line-height: 19px; background: var(--main-background); diff --git a/website/src/styles/components/navbar.module.css b/website/src/styles/components/navbar.module.css index a0db32a..70dbf0f 100644 --- a/website/src/styles/components/navbar.module.css +++ b/website/src/styles/components/navbar.module.css @@ -90,12 +90,12 @@ Account Image Shouldn't Have a Border */ .navItem:has(img), .activePage:has(img){ - border-bottom: 0px + border-bottom: 0 } .activePage:hover:has(img), .navItem:hover:has(img){ opacity: 0.75; - border-bottom: 0px + border-bottom: 0 } .dropdownContent { diff --git a/website/src/styles/components/plant_sections.module.css b/website/src/styles/components/plant_sections.module.css index 3b6abf4..0d4925d 100644 --- a/website/src/styles/components/plant_sections.module.css +++ b/website/src/styles/components/plant_sections.module.css @@ -14,7 +14,7 @@ /* Make the source section have a padding of 0.5% and justify the items to the start - Add some margin so its not too close to the edge + Add some margin so it's not too close to the edge */ .sourceSection{ padding: .5%; diff --git a/website/src/styles/pages/account/index.module.css b/website/src/styles/pages/account/index.module.css index 0e5ad88..2ad8594 100644 --- a/website/src/styles/pages/account/index.module.css +++ b/website/src/styles/pages/account/index.module.css @@ -250,7 +250,7 @@ } .logItem{ - padding: 5px 15px 5px 0px; + padding: 5px 15px 5px 0; } .logItem h3{ diff --git a/website/src/styles/pages/index.module.css b/website/src/styles/pages/index.module.css index 2886b69..3929378 100644 --- a/website/src/styles/pages/index.module.css +++ b/website/src/styles/pages/index.module.css @@ -89,7 +89,7 @@ } /* - The search box takes up the width of the page header but its set to only take up 60% of this. + The search box takes up the width of the page header but it's set to only take up 60% of this. */ .searchBox{ grid-column-start: 1; diff --git a/website/src/styles/pages/plant_index.module.css b/website/src/styles/pages/plant_index.module.css index 5f6eb3b..d7a9150 100644 --- a/website/src/styles/pages/plant_index.module.css +++ b/website/src/styles/pages/plant_index.module.css @@ -93,7 +93,7 @@ } /* - Centre the stats and scale it down to 80% of its original size + Centre the stats and scale it down to 80% of it's original size */ .statsContainer{ display: grid; diff --git a/website/src/styles/pages/plants/id.module.css b/website/src/styles/pages/plants/id.module.css index f6ef893..425ee46 100644 --- a/website/src/styles/pages/plants/id.module.css +++ b/website/src/styles/pages/plants/id.module.css @@ -206,7 +206,7 @@ .plantImageDescription{ background-color: var(--secondary-gray); - border-radius: 0px 0px 20px 20px; + border-radius: 0 0 20px 20px; margin-top: -20px; padding: 30px 10px 10px; }