diff --git a/src/assets/styles/_category.scss b/src/assets/styles/_category.scss index ecbc42d..fe97196 100644 --- a/src/assets/styles/_category.scss +++ b/src/assets/styles/_category.scss @@ -78,7 +78,7 @@ min-height: 7rem; padding: 1rem; display: grid; - grid-template-columns: 1fr 5fr; + grid-template-columns: 1fr 3fr 5fr; gap: 1rem; background: #f2f0fd; &:nth-child(2n) { diff --git a/src/helpers/apiRequests.ts b/src/helpers/apiRequests.ts index 9e2a88b..46451db 100644 --- a/src/helpers/apiRequests.ts +++ b/src/helpers/apiRequests.ts @@ -40,10 +40,13 @@ export const getLinks = (setLinks: React.Dispatch) => { export const createLink = ( setSuccess: React.Dispatch, - data: { link: string } + data: { name: string; source: string } ) => { axios - .post("http://95.85.124.41:8080/link/create", { link: data.link }) + .post("http://95.85.124.41:8080/link/create", { + name: data.name, + source: data.source, + }) .then((res) => { setSuccess(res.data.message); }) @@ -55,10 +58,10 @@ export const createLink = ( export const updateLink = ( setSuccess: React.Dispatch, id: number, - data: { link: string } + data: { name: string; source: string } ) => { axios - .put(`http://95.85.124.41:8080/link/update/${id}`, { link: data.link }) + .put(`http://95.85.124.41:8080/link/update/${id}`, { source: data.source }) .then((res) => { setSuccess(res.data.message); }) diff --git a/src/pages/Category.tsx b/src/pages/Category.tsx index 9072cf9..6d6e3ad 100644 --- a/src/pages/Category.tsx +++ b/src/pages/Category.tsx @@ -4,20 +4,16 @@ import { useState, useEffect } from "react"; // Icons import { IoIosCreate } from "react-icons/io"; -import { - createLink, - deleteLink, - getLinks, - updateLink, -} from "../helpers/apiRequests"; -import { capitalizeFirstLetter } from "../helpers/stringMethods"; +import { getLinks } from "../helpers/apiRequests"; import { LinksAll } from "../types/links"; interface dataType { - create: string; + createName: string; + createLink: string; delete: number; updateId: number; - updateData: string; + updateName: string; + updateLink: string; } interface successType { @@ -30,28 +26,13 @@ interface successType { } const Category = () => { - const [data, setData] = useState({ - create: "", - delete: 0, - updateId: 0, - updateData: "", - }); - - const [success, setSuccess] = useState({ - create: "", - delete: "", - update: "", - hasCreateUpdated: false, - hasDeleteUpdated: false, - hasUpdateUpdated: false, - }); - const defaultDate = new Date("00-00-00"); const [all, setAll] = useState([ { id: -1, - link: "", + name: "", + source: "", createdAt: defaultDate, updatedAt: defaultDate, }, @@ -67,207 +48,41 @@ const Category = () => {
-

Category

+

Source

-

All links

+

All sources

- - - - + + + + + + + - {all[0].id !== -1 - ? all.map((link: LinksAll) => { - return ( - - - - - ); - }) - : ""} + {all[0].id !== -1 ? ( + all.map((source: LinksAll) => { + return ( + + + + + + ); + }) + ) : ( + + + + + + )}
IDLink
IDNameSource
{link.id}{link.link}
{source.id}{source.name} + {source.source} +
-
) => - e.preventDefault() - } - > -
- - ) => { - setData({ - ...data, - create: capitalizeFirstLetter(e.target.value.toLowerCase()), - }); - }} - /> - {success.hasCreateUpdated ? ( - success.create === "success" ? ( - Category added successfuly - ) : ( - Failed to add category - ) - ) : ( - "" - )} -
- -
-
) => - e.preventDefault() - } - > -
- - ) => { - if (e.target.value.length === 0) { - setData({ - ...data, - updateId: 0, - }); - } else { - setData({ - ...data, - updateId: parseInt(e.target.value), - }); - } - }} - /> - ) => { - setData({ - ...data, - updateData: capitalizeFirstLetter( - e.target.value.toLowerCase() - ), - }); - }} - /> - {success.hasUpdateUpdated ? ( - success.update === "success" ? ( - Category updated successfuly - ) : ( - Failed to update category - ) - ) : ( - "" - )} -
- -
-
) => - e.preventDefault() - } - > -
- - ) => { - if (e.target.value.length === 0) { - setData({ - ...data, - delete: 0, - }); - } else { - setData({ - ...data, - delete: parseInt(e.target.value), - }); - } - }} - /> - {success.hasDeleteUpdated ? ( - success.delete === "success" ? ( - Category deleted successfuly - ) : ( - Failed to delete category - ) - ) : ( - "" - )} -
- -
diff --git a/src/pages/Posts.tsx b/src/pages/Posts.tsx index b23b464..d919e64 100644 --- a/src/pages/Posts.tsx +++ b/src/pages/Posts.tsx @@ -66,6 +66,8 @@ const Posts = () => { } }, [posts]); + console.log(posts[0]); + return (
@@ -236,7 +238,7 @@ const Posts = () => { - {parseDate(post.date)[0]} + {/* {parseDate(post.publish_date)[0]} */} {post.summary} @@ -271,7 +273,7 @@ const Posts = () => { - {parseDate(post.date)[0]} + {/* {parseDate(post.publish_date)[0]} */} {post.summary} diff --git a/src/types/links.ts b/src/types/links.ts index f5f8f5f..3fbb60e 100644 --- a/src/types/links.ts +++ b/src/types/links.ts @@ -1,6 +1,7 @@ export interface LinksAll { id: number; - link: string; + name: string; + source: string; createdAt: Date; updatedAt: Date; } diff --git a/src/types/posts.ts b/src/types/posts.ts index a987585..b3394e3 100644 --- a/src/types/posts.ts +++ b/src/types/posts.ts @@ -3,7 +3,7 @@ export interface PostType { category: string; title: string; link: string; - date: Date; + publish_date: Date; summary: string; createdAt: Date; updatedAt: Date;