Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .env

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.env.development.local
.env.test.local
.env.production.local

.env
npm-debug.log*
yarn-debug.log*
yarn-error.log*
64 changes: 17 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# Getting Started with Create React App
# 📂 TechTalk News (Mini-project for Cincinnatus Institute of Craftsmanship)
The most relevant news of technological advances

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
# Description
Techtalk is a project made based on a blog or digital newspaper to publish news, which allows you to publish images and videos accompanied by their title and description, consists of a full stack web application using React, Express, Tailwind and Json Web Token Authentication.

## Available Scripts
# Screenshot
![Alt text](image.png)
![Alt text](image-1.png)

## Instalation

Add your environment variables according to your data, example:
### REACT_APP_API_URL=http://localhost:5000/api

In the project directory, you can run:

### `npm install`
This command installs all the dependencies necessary for its operation

### `npm start`

Runs the app in the development mode.\
Expand All @@ -14,10 +26,7 @@ Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Expand All @@ -27,44 +36,5 @@ It correctly bundles React in production mode and optimizes the build for the be
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
# Authors
@Edwin6666
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"moment": "^2.29.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.0",
"react-hot-toast": "^2.4.1",
"react-icons": "^4.8.0",
"react-router-dom": "^6.14.2",
"react-scripts": "5.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/api/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const DeletePost = process.env.REACT_APP_POST_DELETE;
const PostId = process.env.REACT_APP_POST_ID;




export const getPostsRequest = async () =>
await axios.get(PostUrl, {});

Expand Down
32 changes: 23 additions & 9 deletions src/components/PostCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function insertMedia(filePath) {
}
}

export function PostCard({ post, user }) {
export function PostCard({ post }) {
const { deletePost } = usePosts();
const navigate = useNavigate();

Expand All @@ -38,23 +38,36 @@ export function PostCard({ post, user }) {
(t) => (
<div>
<p className="text-white">
{" "}
Do you want to Delete? <strong>{id}</strong>
<b> Do you want to Delete?</b> {post.title}
</p>
<div>
<button
className="bg-red-500 hover:bg-red-400 px-3 py-2 text-sm text-white rounded-sm mx-2"
onClick={() => {
deletePost(id);
toast.dismiss(t.id);
toast.success("Post Deleted Successful");
}}
>
Delete
</button>

<button
className="bg-slate-400 hover:bg-slate-500 px-3 py-2 text-white rounded-sm mx-2"
onClick={() => toast.dismiss(t.id)}
onClick={() => {
toast.dismiss(t.id);
toast(
"Notification: Post deletion cancelled. Your post has been preserved and will not be deleted. Thank you for your understanding and collaboration! ",
{
duration: 6000,
style: {
borderRadius: "10px",
background: "#333",
color: "#fff",
},
}
);
}}
>
Cancel
</button>
Expand Down Expand Up @@ -84,20 +97,21 @@ export function PostCard({ post, user }) {
</div>
</div>
<div>
{" "}
<button
className="text-sm px-2 py-1 rounded-sm group relative overflow-hidden bg-white shadow m-1"
onClick={() => navigate(`/posts/${post._id}`)}
>
<div class="absolute inset-0 w-0 bg-cyan-300 transition-all duration-[250ms] ease-out group-hover:w-full"></div>
<span class="relative text-black group-hover:text-white">Edit</span>
<div className="absolute inset-0 w-0 bg-cyan-300 transition-all duration-[250ms] ease-out group-hover:w-full"></div>
<span className="relative text-black group-hover:text-white">
Edit
</span>
</button>
<button
className=" text-sm px-2 py-1 rounded-sm group relative overflow-hidden bg-white shadow"
onClick={() => handleDelete(post._id)}
>
<div class="absolute inset-0 w-0 bg-rose-500 transition-all duration-[250ms] ease-out group-hover:w-full"></div>
<span class="relative text-black group-hover:text-white">
<div className="absolute inset-0 w-0 bg-rose-500 transition-all duration-[250ms] ease-out group-hover:w-full"></div>
<span className="relative text-black group-hover:text-white">
Comment on lines +104 to +114

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: use semantic html

Copy link

@adonyssantos adonyssantos Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not use semantic HTML

Delete
</span>
</button>
Expand Down
22 changes: 12 additions & 10 deletions src/components/RequiresAuth.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from 'react'
import React from "react";
import { useLocation, Navigate, Outlet } from "react-router-dom";
import useAuth from "../hooks/useAuth";

const RequiresAuth = ( {allowedRoles } ) => {
const { auth }= useAuth()
const location = useLocation()

return (
auth?.roles?.find(role => allowedRoles?.includes(role.name)) ? <Outlet /> : <Navigate to={"/"} state={{from: location}} replace/>
)
}
const RequiresAuth = ({ allowedRoles }) => {
const { auth } = useAuth();
const location = useLocation();

export default RequiresAuth;
return auth?.roles?.find((role) => allowedRoles?.includes(role.name)) ? (
<Outlet />
) : (
<Navigate to={"/"} state={{ from: location }} replace />
);
};

export default RequiresAuth;
7 changes: 1 addition & 6 deletions src/components/signup/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,8 @@ const Signup = () => {
/>
</div>
</div>

<p className="flex w-full justify-center">{error}</p>
<div className="flex w-full">
{error && (
<div className="w-370 px-15 py-15 my-5 text-14 bg-red-500 text-white rounded-5 text-center">
{error}
</div>
)}
<button
type="submit"
className="flex mt-2 items-center justify-center focus:outline-none text-white text-sm sm:text-base bg-blue-500 hover:bg-blue-600 rounded-2xl py-2 w-full transition duration-150 ease-in"
Expand Down
9 changes: 3 additions & 6 deletions src/components/signup/SignupForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import useForm from "../../hooks/useForm";
import useAuth from "../../hooks/useAuth";
import axios from "axios";

import toast from 'react-hot-toast';

const SignupForm = ({ onSuccess }) => {
const initialState = {
Expand Down Expand Up @@ -31,6 +31,7 @@ const SignupForm = ({ onSuccess }) => {
error.response.status <= 500
) {
setError(error.response.data.message);
toast.error("This didn't work.")
}
}
};
Expand Down Expand Up @@ -110,11 +111,7 @@ const SignupForm = ({ onSuccess }) => {
</div>

<div className="flex w-full">
{error && (
<div className="w-370 px-15 py-15 my-5 text-14 bg-red-500 text-white rounded-5 text-center">
{error}
</div>
)}
<span> {error} </span>
<button
type="submit"
className="flex mt-2 items-center justify-center focus:outline-none text-white text-sm sm:text-base bg-blue-500 hover:bg-blue-600 rounded-2xl py-2 w-full transition duration-150 ease-in"
Expand Down
12 changes: 5 additions & 7 deletions src/context/postContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const usePosts = () => {

export const PostProvider = ({ children }) => {
const [posts, setPosts] = useState([]);
const {auth } = useAuth()
const { auth } = useAuth();

useEffect(() => {
(async () => {
Expand All @@ -29,9 +29,9 @@ export const PostProvider = ({ children }) => {
const createPost = async (post) => {
try {
const res = await createPostRequest(post, auth.token);
setPosts([...posts, res.data]);
setPosts([...posts, res.data]);
} catch (error) {
console.log(error)

}
};

Expand All @@ -41,20 +41,18 @@ export const PostProvider = ({ children }) => {
};

const getPost = async (id) => {

try {
const res = await getPostRequest(id);
return res.data;

} catch (error) {
console.error(error);

}
};

const updatePost = async (id, post) => {

const res = await updatePostRequest(id, post, auth.token);
setPosts(posts.map((post) => (post.id === id ? res.data : post)));

};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const useAuthentication = () => {
const roles = res?.roles;
const token = res?.token;
setAuth({ roles, token });

if (roles === "admin") {
navigate("/");
} else {
Expand Down
Loading