Skip to content

Commit

Permalink
IDE Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Mar 12, 2024
1 parent 13ab62d commit 0ed7faa
Show file tree
Hide file tree
Showing 41 changed files with 94 additions and 160 deletions.
9 changes: 9 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!--suppress ALL -->
<br/>
<p align="center">
<a href="https://github.com/maxtyson123/13_DGT_WEBSITE">
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)_
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/dropdown_section.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from "react";
import React, {useState} from "react";
import styles from "@/styles/components/dropdown_section.module.css";

interface DropdownSectionProps {
Expand Down
2 changes: 2 additions & 0 deletions website/src/components/footer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection SpellCheckingInspection

import Image from "next/image";
import React, {useEffect} from "react";
import styles from "@/styles/components/footer.module.css";
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/infinteLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ export function InfiniteLoading({searchQuery} : InfiniteLoadingProps) {
</div>
</>
)
};
}
1 change: 0 additions & 1 deletion website/src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/page_header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function PageHeader({ children, size = "medium" }: PageHeaderProp
/>
</div>

{/* 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*/}
<div className={styles.headerContainer + " gridCentre"}>

{/* This is the blurred background for what ever is made to be displayed in the header */}
Expand Down
5 changes: 1 addition & 4 deletions website/src/components/plant_sections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
6 changes: 4 additions & 2 deletions website/src/components/slider.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// noinspection SpellCheckingInspection

import React from "react";
import "owl.carousel/dist/assets/owl.carousel.css";
import "owl.carousel/dist/assets/owl.theme.default.css";
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");
}

Expand Down
3 changes: 1 addition & 2 deletions website/src/components/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -34,7 +33,7 @@ export default function Stats(){
async function fetchData() {
try {

let res = null;
let res: null;

const storedData = getFromCache("plant_stats");

Expand Down
13 changes: 6 additions & 7 deletions website/src/lib/api_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"}

}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion website/src/lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions website/src/lib/plant_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface ImageMetaData {
}

/**
* Meta data for a file, (attachment.meta)
* Metadata for a file, (attachment.meta)
*
* @see {@link AttachmentSectionData}
*/
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion website/src/lib/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 1 addition & 7 deletions website/src/pages/account/edit.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 4 additions & 10 deletions website/src/pages/account/index.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -291,7 +285,7 @@ export function AccountPage({dataID}: AccountPageProps){
localStorage.removeItem("userApiKeysData_" + userID)

// Reload the data
fetchData(userID)
await fetchData(userID)
}


Expand Down
8 changes: 1 addition & 7 deletions website/src/pages/account/keys/[id].tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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")
}

}
Expand Down
7 changes: 1 addition & 6 deletions website/src/pages/account/keys/create.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -146,7 +141,7 @@ export function AccountPage({dataID}: AccountPageProps){

setLoading(false)
// Go to the account page
router.push("/account/")
await router.push("/account/")

}

Expand Down
Loading

0 comments on commit 0ed7faa

Please sign in to comment.