DEMO of Pinterest like application:
- navigate to the home page (route /)
- if the user is not logged in there is a login button at the top right to login.
- the user can log in by passing a username and password(mock creds. i.e. username: testuser, pass: pass123 with at least 5 chars), then auth creds save to cookie and navigate to the home page for published posts
- On home page you see the sorted posts by publish date from new to oldest date and logout button on top right
- if you hover over each post, you can delete it
- On the home page you have a filter search input at the top header to filter the list of posts and update url query param and header that contains home page and create nav links.
- On the home page if you have not published any post you can click on publish your first post button or the create nav link to navigate to /create-post-tool page
- at the create post tool page you can attach the image and fill in the form
- you have the list of draft posts in the left sidebar you can remove before publishing
- then you can publish the post and have it in Homp page posts list
- finally, you can logout of the platform and clear the cookie creds and data and stores(you can customize which data to be removed).
Approach:
- created the project in stack Next.js(v.14), TypeScript, Jest, Storybook, prettier, husky
- Created public api's by Next.js API routes and connected to the app
- /api/login (login api )
- /api/posts/get (get posts list)
- /api/posts/post (create new post)
- /api/posts/delete (delete the post)
- Authentication is implemented by cookies-next(client & server) and AuthContext
- Add apiInstance to handle all https requests(GET, POST, PUT, DELETE) (path:src/utils/api.ts)
- src folder structure
- components
- business (business specific i.e. LoginForm, NewPostForm, PostList, ...)
- common components (Unit components i.e. TextInput, Image, Modal, ... )
- shared components (Header, Layout)
- components
- full dynamic form using react-hook-form and yup validation is implemented and able to connect in controlled and un-controlled modes to unit components
- Zustand in-memory state management
- persist store to keep posts in the cookie
- non-persist to keep tool draft posts
- Constant folder to keep constant variables
- contexts folder(Auth context)
- hooks folder keeps the extracted and created custom hooks
- Icons folder keeps custom svg icons
- pages folder contains the API routes and home page and create-post-tool page
- store folder contain persist postStore and non-persist draftToolPostStore
- styles folder keeps the global styles
- for accessibility I have used semantic HTML5 tags, meta head tags and tabIndex
- types folder contains the static types
- utils folder keeps the utility functions
- Addted storybook to TextInput component (path: src/components/common/TextInput/TextInput.stories.tsx)
- Added unit test to TextInput component (path: src/components/common/TextInput/TextInput.test.tsx)
Note: Since Next.js version is v.14, so running platform should have Node.js version 18.17 or later.
Node.js 18.17 or later.
git clone https://github.com/Ferigit/Pinterest.git
1. cd root dir
2. pull main branch
3. yarn (or npm install)
4. yarn dev (or npm run dev)
1. cd root dir
2. pull main branch
3. yarn (or npm install)
4. yarn storybook (or npm run storybook)
1. cd root dir
2. pull main branch
3. yarn (or npm install)
4. yarn test (or npm run test)
1. cd root dir
3. yarn (or npm install)
3. yarn build (or npm run build)