-
Notifications
You must be signed in to change notification settings - Fork 0
initial commit for demo next js project #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
app/api/comments.js
Outdated
"use server"; | ||
import instance from "../utils/axios"; | ||
|
||
export async function fetchCommentsByPostId(postId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just return the promise from this function and use the try catch block in the component making the API call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
app/api/posts.js
Outdated
|
||
export async function createPost(data, userId) { | ||
try { | ||
await instance.post("/posts", { ...data, userId }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the payload from the component which is calling this function
app/api/posts.js
Outdated
} catch (error) { | ||
return { message: "Failed to edit post" }; | ||
} | ||
revalidatePath(`/users/posts/${userId}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic should be in the case of API success
app/api/posts.js
Outdated
|
||
export async function fetchPostsPages(userId, query) { | ||
try { | ||
const response = await instance.get(`/posts?userId=${userId}&q=${query}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to make the number of pages in the same API call when fetching posts for users
}; | ||
|
||
const allPages = generatePagination(currentPage, totalPages); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compute the position here
app/users/posts/[id]/PostsBody.js
Outdated
<> | ||
<div | ||
className="cursor-pointer" | ||
onClick={() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
app/users/posts/[id]/PostsForm.js
Outdated
{({ handleSubmit, handleChange, values, errors, touched }) => ( | ||
<form onSubmit={handleSubmit}> | ||
<div className=" rounded-md bg-gray-50 p-4 md:p-6 "> | ||
<TextField |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map
return ( | ||
<main> | ||
<Breadcrumbs | ||
breadcrumbs={[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
app/users/posts/[id]/buttons.js
Outdated
); | ||
} | ||
|
||
export function OnCloseModal({ userId }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CloseModalButton
app/users/posts/[id]/error.js
Outdated
<h2 className="text-center">Something went wrong!</h2> | ||
<button | ||
className="mt-4 rounded-md bg-blue-500 px-4 py-2 text-sm text-white transition-colors hover:bg-blue-400" | ||
onClick={() => reset()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onClick={reset}
app/api/comments.js
Outdated
"use server"; | ||
import instance from "../utils/axios"; | ||
|
||
export async function fetchCommentsByPostId(postId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
app/api/posts.js
Outdated
const offset = (currentPage - 1) * ITEMS_PER_PAGE; | ||
const [response, allData] = await Promise.all([ | ||
instance.get( | ||
`/posts?userId=${userId}&_start=${offset}&_limit=${ITEMS_PER_PAGE}&q=${query}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use axios query params
app/api/posts.js
Outdated
query | ||
) { | ||
const offset = (currentPage - 1) * ITEMS_PER_PAGE; | ||
const [response, allData] = await Promise.all([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paginatedPosts, allPosts
app/api/posts.js
Outdated
|
||
export async function createPost(data) { | ||
await instance.post("/posts", data); | ||
revalidatePath(`/users/posts/${data?.userId}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the redirects from here
app/api/users.js
Outdated
@@ -0,0 +1,31 @@ | |||
"use server"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this directive
app/components/navLinks.js
Outdated
"flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3", | ||
{ | ||
"bg-sky-100 text-blue-600": | ||
`/${pathname.split("/")?.[1]}` === link.href, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compute this expression above
app/components/shared/Search.js
Outdated
const term = e.target.value; | ||
const params = new URLSearchParams(searchParams); | ||
params.set(PAGE, "1"); | ||
if (term) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (term) params.set(QUERY, term);
else params.delete(QUERY);
app/components/shared/SideBar.js
Outdated
<div className="flex h-full flex-col px-3 py-4 md:px-2"> | ||
<Link | ||
className="mb-2 flex h-20 items-end justify-start rounded-md bg-blue-600 p-4 md:h-40" | ||
href="/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a constant here, HOME maybe
app/users/[id]/edit/EditUser.js
Outdated
return ( | ||
<main> | ||
<Breadcrumbs | ||
breadcrumbs={[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this array in DataHelpers file
app/users/components/UserForm.js
Outdated
|
||
export default function UserForm({ user }) { | ||
return ( | ||
<Formik |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change it to useFormik hook
app/users/components/UserForm.js
Outdated
<Formik | ||
initialValues={user || generateInitialValues(createUserFormData)} | ||
validationSchema={UserValidationSchema.createUser()} | ||
onSubmit={async (values, { resetForm }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never create inline functions, always create a separate function
app/users/create/CreateUser.js
Outdated
<main> | ||
<Breadcrumbs | ||
breadcrumbs={[ | ||
{ label: USERS, href: urls.USERS }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
const [loading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
const fetchCommentsData = async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this function out of the useEffect hook
app/utils/constants/index.js
Outdated
export const TRY_AGAIN = "Try again"; | ||
export const CANCEL = "Cancel"; | ||
//urls | ||
export const urls = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this constants inside RouteContants file
}, | ||
]; | ||
|
||
export const createPostFormData = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
} | ||
}; | ||
|
||
const formik = useFormik({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
…es,interceptingroutes
No description provided.