summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/pages/articles
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2024-07-27 16:44:01 -0400
committerrealtradam <[email protected]>2024-07-27 16:44:01 -0400
commitf75c5d9264d71298711321d83a9c6b23327b3f56 (patch)
treeb7f964a1e37cdead6a198e1138cc1f06331b0eb5 /frontend/src/pages/articles
parentb1112afc5162bb299d528974594dcf7c2ec46266 (diff)
downloadspring-blog-f75c5d9264d71298711321d83a9c6b23327b3f56.tar.gz
spring-blog-f75c5d9264d71298711321d83a9c6b23327b3f56.zip
fix linting
Diffstat (limited to 'frontend/src/pages/articles')
-rw-r--r--frontend/src/pages/articles/Article.tsx46
-rw-r--r--frontend/src/pages/articles/New.tsx161
2 files changed, 117 insertions, 90 deletions
diff --git a/frontend/src/pages/articles/Article.tsx b/frontend/src/pages/articles/Article.tsx
index b367811..1a96ada 100644
--- a/frontend/src/pages/articles/Article.tsx
+++ b/frontend/src/pages/articles/Article.tsx
@@ -1,25 +1,35 @@
import { useState, useEffect } from "react";
import { useParams } from "react-router-dom";
-export default function Article () {
- const { id } = useParams();
- const [articleData, setArticleData] = useState<any>();
+type article = {
+ id: number;
+ title: string;
+ photoUrl: string;
+ content: string;
+ createdOn: string;
+ updateOn: string;
+};
- useEffect(() => {
- const url = `${import.meta.env.VITE_API_TITLE}/api/v1/article/${id}`;
- fetch(url).then((response) => {
- if (response.ok) {
- return response.json();
- }
- throw new Error("Network response was not ok.");
- }).then((response) => setArticleData(response)); //.catch(() => navigate("/"));
- }, [id]);
+export default function Article() {
+ const { id } = useParams();
+ const [articleData, setArticleData] = useState<article>();
- return(
- <>
- <h1>{articleData?.title}</h1>
- <div>{articleData?.content}</div>
- </>
- );
+ useEffect(() => {
+ const url = `${import.meta.env.VITE_API_TITLE}/api/v1/article/${id}`;
+ fetch(url)
+ .then((response) => {
+ if (response.ok) {
+ return response.json();
+ }
+ throw new Error("Network response was not ok.");
+ })
+ .then((response) => setArticleData(response)); //.catch(() => navigate("/"));
+ }, [id]);
+ return (
+ <>
+ <h1>{articleData?.title}</h1>
+ <div>{articleData?.content}</div>
+ </>
+ );
}
diff --git a/frontend/src/pages/articles/New.tsx b/frontend/src/pages/articles/New.tsx
index 3402f22..f98c19a 100644
--- a/frontend/src/pages/articles/New.tsx
+++ b/frontend/src/pages/articles/New.tsx
@@ -1,83 +1,100 @@
import { FormEvent } from "react";
import { useNavigate } from "react-router-dom";
-export default function NewArticle () {
- const navigate = useNavigate();
+export default function NewArticle() {
+ const navigate = useNavigate();
- const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
- e.preventDefault(); //stops submit from happening
+ const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
+ e.preventDefault(); //stops submit from happening
- const target = e.target as typeof e.target & {
- title: { value: string };
- photoUrl: { value: string };
- content: { value: string };
- };
+ const target = e.target as typeof e.target & {
+ title: { value: string };
+ photoUrl: { value: string };
+ content: { value: string };
+ };
- const formData = new FormData();
- formData.append('title', target.title.value);
- formData.append('photoUrl', target.photoUrl.value);
- formData.append('content', target.content.value);
+ const formData = new FormData();
+ formData.append("title", target.title.value);
+ formData.append("photoUrl", target.photoUrl.value);
+ formData.append("content", target.content.value);
- const response = await fetch(`${import.meta.env.VITE_API_TITLE}/api/v1/article/new`, {
- credentials: 'include',
- method: 'post',
- body: formData,
- });
- if(response.ok) {
- navigate("/");
- }
- else {
- console.log(response);
- alert("check console for error");
- }
- };
- return(
- <>
-<div className="flex justify-center bg-white p-12">
-<form onSubmit={handleSubmit} method="post" className="w-full max-w-lg">
- <div className="flex flex-wrap -mx-3 mb-6">
- <div className="w-full md:w-1/2 px-3 mb-6 md:mb-0">
- <label className="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2">
+ const response = await fetch(
+ `${import.meta.env.VITE_API_TITLE}/api/v1/article/new`,
+ {
+ credentials: "include",
+ method: "post",
+ body: formData,
+ },
+ );
+ if (response.ok) {
+ navigate("/");
+ } else {
+ console.log(response);
+ alert("check console for error");
+ }
+ };
+ return (
+ <>
+ <div className="flex justify-center bg-white p-12">
+ <form onSubmit={handleSubmit} method="post" className="w-full max-w-lg">
+ <div className="flex flex-wrap -mx-3 mb-6">
+ <div className="w-full md:w-1/2 px-3 mb-6 md:mb-0">
+ <label className="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2">
Title
- </label>
- <input className="appearance-none block w-full bg-gray-200 text-gray-700 border border-red-500 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white"
- id="title"
- type="text"
- name="title"
- placeholder="Yep"/>
- <p className="text-red-500 text-xs italic">Please fill out this field.</p>
- </div>
- <div className="w-full md:w-1/2 px-3">
- <label className="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2">
+ </label>
+ <input
+ className="appearance-none block w-full bg-gray-200 text-gray-700 border border-red-500 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white"
+ id="title"
+ type="text"
+ name="title"
+ placeholder="Yep"
+ />
+ <p className="text-red-500 text-xs italic">
+ Please fill out this field.
+ </p>
+ </div>
+ <div className="w-full md:w-1/2 px-3">
+ <label className="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2">
Photo URL
- </label>
- <input className="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
- id="photoUrl"
- type="text"
- name="photoUrl"
- placeholder="Doe"/>
- <p className="text-red-500 text-xs italic">Please fill out this field.</p>
- </div>
- </div>
- <div className="flex flex-wrap -mx-3 mb-6">
- <div className="w-full px-3">
- <label className="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2">
+ </label>
+ <input
+ className="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
+ id="photoUrl"
+ type="text"
+ name="photoUrl"
+ placeholder="Doe"
+ />
+ <p className="text-red-500 text-xs italic">
+ Please fill out this field.
+ </p>
+ </div>
+ </div>
+ <div className="flex flex-wrap -mx-3 mb-6">
+ <div className="w-full px-3">
+ <label className="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2">
Content
- </label>
- <input className="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
- id="content"
- type="text"
- name="content"
- placeholder="Doe"/>
- <p className="text-red-500 text-xs italic">Please fill out this field.</p>
- </div>
- </div>
- <div className="flex flex-wrap mb-2">
- </div>
- <button type="submit" className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Create</button>
-
-</form>
-</div>
- </>
- );
+ </label>
+ <input
+ className="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
+ id="content"
+ type="text"
+ name="content"
+ placeholder="Doe"
+ />
+ <p className="text-red-500 text-xs italic">
+ Please fill out this field.
+ </p>
+ </div>
+ </div>
+ <div className="flex flex-wrap mb-2"></div>
+ <button
+ type="submit"
+ className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
+ >
+ Create
+ </button>
+ </form>
+ </div>
+ </>
+ );
}