├── .env
├── .eslintrc.json
├── .gitignore
├── README.md
├── next.config.js
├── package-lock.json
├── package.json
├── postcss.config.js
├── problem.json
├── public
├── next.svg
└── vercel.svg
├── src
├── app
│ ├── accounts
│ │ ├── dashboard
│ │ │ ├── [...id]
│ │ │ │ └── page.tsx
│ │ │ └── page.tsx
│ │ ├── problems
│ │ │ └── [id]
│ │ │ │ └── page.tsx
│ │ ├── signIn
│ │ │ └── page.tsx
│ │ └── signUp
│ │ │ └── page.tsx
│ ├── api
│ │ ├── auth
│ │ │ ├── profile
│ │ │ │ └── route.ts
│ │ │ ├── signIn
│ │ │ │ └── route.ts
│ │ │ ├── signOut
│ │ │ │ └── route.ts
│ │ │ └── signUp
│ │ │ │ └── route.ts
│ │ ├── handler
│ │ │ ├── handelDisLikedproblems
│ │ │ │ └── route.ts
│ │ │ ├── handelFavoritesproblems
│ │ │ │ └── route.ts
│ │ │ ├── handelLikedproblems
│ │ │ │ └── route.ts
│ │ │ └── handelSolvedproblems
│ │ │ │ └── route.ts
│ │ ├── languages
│ │ │ └── python
│ │ │ │ ├── run
│ │ │ │ └── route.ts
│ │ │ │ └── submit
│ │ │ │ └── route.ts
│ │ └── utils
│ │ │ ├── problemSets
│ │ │ └── route.ts
│ │ │ └── verifiedUserDetails
│ │ │ └── route.ts
│ ├── favicon.ico
│ ├── globals.css
│ ├── layout.tsx
│ └── page.tsx
├── assets
│ ├── choiceLock.pdf
│ ├── finalChoiceLock.pdf
│ ├── java.png
│ ├── js.png
│ ├── logo.png
│ ├── logo2.webp
│ ├── me1.png
│ ├── plate.png
│ └── python.png
├── components
│ ├── Footer
│ │ └── footer.tsx
│ ├── Header
│ │ ├── acountNavbar.tsx
│ │ ├── landingPageNavbar.tsx
│ │ ├── playgroundNavbar.tsx
│ │ └── problemPageNavbar.tsx
│ ├── Timer
│ │ └── timer.tsx
│ ├── Workspace
│ │ ├── Playground
│ │ │ ├── console
│ │ │ │ └── consoleRunner.tsx
│ │ │ └── playground.tsx
│ │ ├── ProblemDescription
│ │ │ └── problemDescription.tsx
│ │ └── workspace.tsx
│ └── home
│ │ └── home.tsx
├── database
│ └── dbConfig.ts
├── helpers
│ ├── encryption.ts
│ └── type.ts
├── hooks
│ ├── useLocalStorage.ts
│ └── useWindowSize.ts
├── middleware.ts
└── models
│ ├── problemModel.ts
│ └── userModel.ts
├── tailwind.config.ts
├── tsconfig.json
└── yarn.lock
/.env:
--------------------------------------------------------------------------------
1 | MONGO_URl= "mongodb://localhost:27017/Leet-code-2023"
2 | SECRET_KEY="publicUserKey"
3 | TOKEN_NAME= "User-Token"
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "next/core-web-vitals"
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # next.js
12 | /.next/
13 | /out/
14 |
15 | # production
16 | /build
17 |
18 | # misc
19 | .DS_Store
20 | *.pem
21 |
22 | # debug
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 |
27 | # local env files
28 | .env*.local
29 |
30 | # vercel
31 | .vercel
32 |
33 | # typescript
34 | *.tsbuildinfo
35 | next-env.d.ts
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # LeetCode Clone with Next.js and MongoDB
3 |
4 | Welcome to LeetCode-clone, a dynamic coding challenge platform built with Next.js and MongoDB. This platform not only provides a vast array of algorithmic problems for users to solve but also features automatic testcase evaluation to streamline the learning process.
5 |
6 |
7 | ## Key Features:
8 |
9 |
10 | - **Automatic Testcase Evaluation:** Submit your solution, and LeetCode will run it against a set of predefined test cases, providing instant feedback on correctness.
11 | - **User Authentication:** Secure user authentication system for account creation and login.
12 | - **Coding Challenges:** Diverse set of challenges to practice and improve algorithmic skills.
13 | - **Submission Checker:** Real-time evaluation of user submissions, highlighting test cases passed and failed.
14 | - **User Profile:** Track your progress, completed challenges, and submission history.
15 | - **Responsive Design:** User-friendly interface accessible across devices.
16 |
17 |
18 | ## Technology Stack:
19 |
20 | - **Frontend:** Next.js, TypeScript, TailwindCSS
21 | - **Backend:** Node.js, MongoDB
22 | - **Authentication:** crypto
23 |
24 |
25 | ## Installation
26 |
27 | ## Getting Started:
28 |
29 | - **1. Clone the repository:** `git clone [repository-url]`
30 | - **2. Install dependencies:** `npm install` in both the `frontend` and `backend` directories.
31 | - **4. Set up MongoDB:** Configure your MongoDB connection string in the backend `.env` file. Also Import the `problem.json` in your MongoDB
32 | - **5. Run the development server:** `npm run dev` in both the `frontend` and `backend` directories.
33 |
34 | ## Feedback
35 |
36 | If you have any feedback, please reach out to us at asahaayan@gmail.com
37 |
38 |
39 | ## Optimizations
40 |
41 | What optimizations did you make in your code? E.g. refactors, performance improvements, accessibility
42 |
43 |
44 | ## Screenshots
45 |
46 | 
47 | 
48 | 
49 | 
50 | 
51 | 
52 | 
53 | 
54 |
55 |
56 |
57 | ## 🔗 Links
58 | [](https://www.linkedin.com/)
59 | [](https://twitter.com/)
60 |
61 |
--------------------------------------------------------------------------------
/next.config.js:
--------------------------------------------------------------------------------
1 | /** @type {import('next').NextConfig} */
2 | const nextConfig = {}
3 |
4 | module.exports = nextConfig
5 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "leetcode-clone",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "dev": "next dev",
7 | "build": "next build",
8 | "start": "next start",
9 | "lint": "next lint"
10 | },
11 | "dependencies": {
12 | "@codemirror/lang-javascript": "^6.2.1",
13 | "@codemirror/lang-python": "^6.1.3",
14 | "@types/node": "20.6.2",
15 | "@types/react": "18.2.22",
16 | "@types/react-dom": "18.2.7",
17 | "@uiw/codemirror-theme-vscode": "^4.21.21",
18 | "@uiw/react-codemirror": "^4.21.21",
19 | "autoprefixer": "10.4.15",
20 | "axios": "^1.6.2",
21 | "crypto": "^1.0.1",
22 | "eslint": "8.49.0",
23 | "eslint-config-next": "13.4.19",
24 | "mongoose": "^8.0.1",
25 | "next": "^13.5.5-canary.4",
26 | "postcss": "8.4.30",
27 | "python-shell": "^5.0.0",
28 | "react": "^18.2.0",
29 | "react-confetti": "^6.1.0",
30 | "react-dom": "18.2.0",
31 | "react-firebase-hooks": "^5.1.1",
32 | "react-icons": "^4.12.0",
33 | "react-split": "^2.0.14",
34 | "react-toastify": "^9.1.3",
35 | "tailwindcss": "3.3.3",
36 | "typescript": "5.2.2"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: {
3 | tailwindcss: {},
4 | autoprefixer: {},
5 | },
6 | }
7 |
--------------------------------------------------------------------------------
/problem.json:
--------------------------------------------------------------------------------
1 | [{
2 | "_id": {
3 | "$oid": "65813607db0ee3b9bc352d37"
4 | },
5 | "id": "two-sum",
6 | "title": "Two Sum",
7 | "problemStatement": "Given an array of integers nums
and an integer target
, return indices of the two numbers such that they add up to target
.
You may assume that each input would have exactly one solution , and youmay not use thesame element twice.
You can return the answer in any order.
",
8 | "examples": [
9 | {
10 | "id": 0,
11 | "inputText": "nums = [2,7,11,15], target = 9",
12 | "outputText": "[0,1]",
13 | "explanation": "Because nums[0] + nums[1] == 9, we return [0, 1]."
14 | },
15 | {
16 | "id": 1,
17 | "inputText": "nums = [3,2,4], target = 6",
18 | "outputText": "[1,2]",
19 | "explanation": "Because nums[1] + nums[2] == 6, we return [1, 2]."
20 | },
21 | {
22 | "id": 2,
23 | "inputText": " nums = [3,3], target = 6",
24 | "outputText": "[0,1]"
25 | }
26 | ],
27 | "constraints": "2 ≤ nums.length ≤ 10
-10 ≤ nums[i] ≤ 10
-10 ≤ target ≤ 10
Only one valid answer exists. ",
28 | "difficulty": "Easy",
29 | "category": "Array",
30 | "order": 1,
31 | "videoId": "8-k1C6ehKuw",
32 | "starterCode": "import sys\nimport ast\n\ndef two_sum(nums, target):\n ''' Write Your Code '''\n\n\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n # Parse command-line arguments as lists\n arg_lists = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n \n for arg_list in arg_lists:\n nums, target = arg_list\n nums = [int(num) for num in nums] # Convert string representation of numbers to integers\n result = two_sum(nums, target)\n print(result)\n else:\n nums = [2, 7, 11, 15]\n target = 9\n result = two_sum(nums, target)\n print(result)\n\n\n",
33 | "testCase": {
34 | "input": [
35 | "[[2, 7, 11, 15], 9]",
36 | "[[3, 2, 4], 6]",
37 | "[[3, 3], 6]"
38 | ],
39 | "output": [
40 | "[0, 1]",
41 | "[1, 2]",
42 | "[0, 1]"
43 | ]
44 | }
45 | },
46 | {
47 | "_id": {
48 | "$oid": "65813607db0ee3b9bc352d38"
49 | },
50 | "id": "reverse-linked-list",
51 | "title": "Reverse Linked List",
52 | "problemStatement": "Given the head
of a singly linked list, reverse the list, and return the reversed list .
",
53 | "examples": [
54 | {
55 | "id": 0,
56 | "inputText": "head = [1,2,3,4,5]",
57 | "outputText": "[5,4,3,2,1]"
58 | },
59 | {
60 | "id": 1,
61 | "inputText": "head = [1,2,3]",
62 | "outputText": "[3,2,1]"
63 | },
64 | {
65 | "id": 2,
66 | "inputText": "head = [1]",
67 | "outputText": "[1]"
68 | }
69 | ],
70 | "constraints": "The number of nodes in the list is the range [0, 5000]
. -5000 <= Node.val <= 5000
",
71 | "difficulty": "Hard",
72 | "category": "Linked List",
73 | "order": 2,
74 | "videoId": "",
75 | "starterCode": "import ast\nimport sys\n\nclass ListNode:\n def __init__(self, value=0, next=None): \n self.value = value\n self.next = next\n\ndef reverse_linked_list(head):\n prev = None\n current = head\n ''' Write your logic '''\n \n\n# Function to convert a list to a linked list\ndef list_to_linked_list(lst):\n if not lst:\n return None\n\n head = ListNode(lst[0])\n current = head\n\n for value in lst[1:]:\n current.next = ListNode(value)\n current = current.next\n\n return head\n\n# Function to convert a linked list to a list\ndef linked_list_to_list(head):\n result = []\n while head:\n result.append(head.value)\n head = head.next\n return result\n\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n \n for i in nums:\n input_head = list_to_linked_list(i)\n reversed_head = reverse_linked_list(input_head)\n output_list = linked_list_to_list(reversed_head)\n print(output_list)\n \n else:\n \n # Example usage:\n input_list = [1, 2, 3, 4, 5]\n\n # Convert the input list to a linked list\n input_head = list_to_linked_list(input_list)\n\n # Reverse the linked list\n reversed_head = reverse_linked_list(input_head)\n\n # Convert the reversed linked list to a list\n output_list = linked_list_to_list(reversed_head)\n\n print(output_list)",
76 | "testCase": {
77 | "input": [
78 | "[2, 7, 11, 15]",
79 | "[1,2]",
80 | "[0]"
81 | ],
82 | "output": [
83 | "[15, 11, 7, 2]",
84 | "[2, 1]",
85 | "[0]"
86 | ]
87 | }
88 | },
89 | {
90 | "_id": {
91 | "$oid": "65813607db0ee3b9bc352d39"
92 | },
93 | "id": "jump-game",
94 | "title": "Jump Game",
95 | "problemStatement": "You are given an integer array nums
. You are initially positioned at the first index and each element in the array represents your maximum jump length at that position.
Return true
if you can reach the last index, or false
otherwise.
",
96 | "examples": [
97 | {
98 | "id": 0,
99 | "inputText": "nums = [2,3,1,1,4]",
100 | "outputText": "true",
101 | "explanation": "Jump 1 step from index 0 to 1, then 3 steps to the last index."
102 | },
103 | {
104 | "id": 1,
105 | "inputText": "nums = [3,2,1,0,4]",
106 | "outputText": "false",
107 | "explanation": "You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index."
108 | }
109 | ],
110 | "constraints": "1 <= nums.length <= 10^4
0 <= nums[i] <= 10^5
",
111 | "difficulty": "Medium",
112 | "category": "Dynamic Programming",
113 | "order": 3,
114 | "videoId": "",
115 | "starterCode": "import ast\nimport sys\n\n\ndef can_jump(nums):\n '''Write Your Logic'''\n\n\n\nif __name__ == \"__main__\":\n # Check if command-line arguments are available\n if len(sys.argv) > 1:\n # Parse command-line arguments as integers\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = can_jump(i)\n print(result)\n \n else:\n nums = [2, 3, 1, 1, 4]\n result = can_jump(nums)\n print(result)\n",
116 | "testCase": {
117 | "input": [
118 | "[2,3,1,1,4]",
119 | "[3,2,1,0,4]"
120 | ],
121 | "output": [
122 | "True",
123 | "False"
124 | ]
125 | }
126 | },
127 | {
128 | "_id": {
129 | "$oid": "65813607db0ee3b9bc352d3a"
130 | },
131 | "id": "valid-parentheses",
132 | "title": "Valid Parentheses",
133 | "problemStatement": "Given a string s
containing just the characters '('
, ')'
, '{'
, '}'
, '['
and ']'
, determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type. ",
134 | "examples": [
135 | {
136 | "id": 0,
137 | "inputText": "s = ()",
138 | "outputText": "True"
139 | },
140 | {
141 | "id": 1,
142 | "inputText": "s = ()[]{}",
143 | "outputText": "True"
144 | },
145 | {
146 | "id": 2,
147 | "inputText": "s = (]",
148 | "outputText": "False"
149 | },
150 | {
151 | "id": 3,
152 | "inputText": "s = ([)]",
153 | "outputText": "False"
154 | }
155 | ],
156 | "constraints": "1 <= s.length <= 104
s
consists of parentheses only '()[]{}'
. ",
157 | "difficulty": "Easy",
158 | "category": "Stack",
159 | "order": 4,
160 | "videoId": "xty7fr-k0TU",
161 | "starterCode": "import sys\n\ndef is_valid(s):\n ''' Write Your Code '''\n\n\nif __name__ == \"__main__\":\n # Check if command-line arguments are available\n if len(sys.argv) > 1:\n nums = [(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = is_valid(i)\n print(result)\n else:\n nums = \"({[]})\"\n result = is_valid(nums)\n print(result)\n",
162 | "testCase": {
163 | "input": [
164 | "()",
165 | "()[]{}",
166 | "(]"
167 | ],
168 | "output": [
169 | "True",
170 | "True",
171 | "False"
172 | ]
173 | }
174 | },
175 | {
176 | "_id": {
177 | "$oid": "65813607db0ee3b9bc352d3b"
178 | },
179 | "id": "search-a-2d-matrix",
180 | "title": "Search a 2D Matrix",
181 | "problemStatement": "Write an efficient algorithm that searches for a value in an m x n
matrix. This matrix has the following properties:
Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row. Given matrix
, an m x n
matrix, and target
, return true
if target
is in the matrix, and false
otherwise.
",
182 | "examples": [
183 | {
184 | "id": 0,
185 | "inputText": "matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3",
186 | "outputText": "true"
187 | },
188 | {
189 | "id": 1,
190 | "inputText": "matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13",
191 | "outputText": "false"
192 | },
193 | {
194 | "id": 2,
195 | "inputText": "matrix = [[1]], target = 1",
196 | "outputText": "true"
197 | }
198 | ],
199 | "constraints": "m == matrix.length
n == matrix[i].length
1 <= m, n <= 100
-104 <= matrix[i][j], target <= 104
",
200 | "difficulty": "Medium",
201 | "category": "Binary Search",
202 | "order": 5,
203 | "videoId": "ZfFl4torNg4",
204 | "starterCode": "import ast\nimport sys\n\ndef search_matrix(matrix, target):\n #Write Your Code\n\n\nif __name__ == \"__main__\":\n # Check if command-line arguments are available\n if len(sys.argv) > 1:\n arg_pairs = [ast.literal_eval(arg) for arg in sys.argv[1:]] \n for arg_pair in arg_pairs:\n matrix, target = arg_pair\n matrix = [list(row) for row in matrix] # Ensure each row is a list\n target = int(target)\n \n result = search_matrix(matrix, target)\n print(result)\n \n else:\n matrix = [\n [1,3,5,7],[10,11,16,20],[23,30,34,60]\n ]\n\n target = 3\n result = search_matrix(matrix, target)\n print(result)\n",
205 | "testCase": {
206 | "input": [
207 | "[[[1,3,5,7],[10,11,16,20],[23,30,34,60]], 3]",
208 | "[[[1,3,5,7],[10,11,16,20],[23,30,34,60]], 13]"
209 | ],
210 | "output": [
211 | "True",
212 | "False"
213 | ]
214 | }
215 | },
216 | {
217 | "_id": {
218 | "$oid": "65813607db0ee3b9bc352d3c"
219 | },
220 | "id": "container-with-most-water",
221 | "title": "Container With Most Water",
222 | "problemStatement": "You are given an integer array height
of length n
. There are n vertical lines drawn such that the two endpoints of the ith
line are (i, 0)
and (i, height[i])
. Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store.Notice that you may not slant the container.
",
223 | "examples": [
224 | {
225 | "id": 0,
226 | "inputText": "height = [1,8,6,2,5,4,8,3,7]",
227 | "explanation": "The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.",
228 | "outputText": "49"
229 | },
230 | {
231 | "id": 1,
232 | "inputText": "height =[1,1]",
233 | "outputText": "1"
234 | }
235 | ],
236 | "constraints": "n == height.length
2 <= n <=10^5
0 <= height[i] <= 104
",
237 | "difficulty": "Medium",
238 | "category": "Two Pointers",
239 | "order": 6,
240 | "videoId": "",
241 | "starterCode": "import ast\nimport sys\n\n\ndef max_area(height):\n max_area_value = 0\n left = 0\n right = len(height) - 1\n ''' Write Your Logic '''\n\n\n return max_area_value\n\n# Example usage:\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n \n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = max_area(i)\n print(result)\n \n else:\n # Example Use\n height = [1, 8, 6, 2, 5, 4, 8, 3, 7]\n result = max_area(height)\n print(result)\n",
242 | "testCase": {
243 | "input": [
244 | "[1, 8, 6, 2, 5, 4, 8, 3, 7]",
245 | "[1,1]"
246 | ],
247 | "output": [
248 | "49",
249 | "1"
250 | ]
251 | }
252 | },
253 | {
254 | "_id": {
255 | "$oid": "65813607db0ee3b9bc352d3d"
256 | },
257 | "id": "merge-intervals",
258 | "title": "Merge Intervals",
259 | "problemStatement": "Given an array of intervals
where intervals[i] = [starti , endi ]
, merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
",
260 | "examples": [
261 | {
262 | "id": 0,
263 | "inputText": "intervals = [[1,3],[2,6],[8,10],[15,18]]",
264 | "explanation": "Since intervals [1,3] and [2,6] overlap, merge them into [1,6].",
265 | "outputText": "[[1,6],[8,10],[15,18]]"
266 | },
267 | {
268 | "id": 1,
269 | "inputText": "intervals = [[1,4],[4,5]]",
270 | "explanation": "Intervals [1,4] and [4,5] are considered overlapping.",
271 | "outputText": "[[1,5]]"
272 | }
273 | ],
274 | "constraints": "1 <== intervals.length <= 104
intervals[i].length ==2
0 <= starti <=endi <= 104
",
275 | "difficulty": "Medium",
276 | "category": "intervals",
277 | "order": 7,
278 | "videoId": "",
279 | "starterCode": "import ast\nimport sys\n\ndef merge(intervals):\n #Write your logic \n\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = merge(i)\n print(result)\n \n else: \n intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]\n result = merge(intervals)\n print(result)\n",
280 | "testCase": {
281 | "input": [
282 | "[[1, 3], [2, 6], [8, 10], [15, 18]]",
283 | "[[1, 4], [4, 5]]"
284 | ],
285 | "output": [
286 | "[[1, 6], [8, 10], [15, 18]]",
287 | "[[1, 5]]"
288 | ]
289 | }
290 | },
291 | {
292 | "_id": {
293 | "$oid": "65813607db0ee3b9bc352d3e"
294 | },
295 | "id": "maximum-depth-of-binary-tree",
296 | "title": "Maximum Depth of Binary Tree",
297 | "problemStatement": "Given the root
of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
",
298 | "examples": [
299 | {
300 | "id": 0,
301 | "inputText": "root = [3,9,20,null,null,15,7]",
302 | "outputText": "3"
303 | },
304 | {
305 | "id": 1,
306 | "inputText": "root = [1,null,2]",
307 | "outputText": "2"
308 | }
309 | ],
310 | "constraints": "The number of nodes in the tree is in the range[0, 104 ]
-100 <= Node.val <= 100
",
311 | "difficulty": "Easy",
312 | "category": "Tree",
313 | "order": 8,
314 | "videoId": "4qYTqOiRMoM",
315 | "starterCode": "import ast\nimport sys\n\n\nclass TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef list_to_tree(nodes):\n if not nodes:\n return None\n\n root = TreeNode(nodes[0])\n queue = [root]\n i = 1\n\n while i < len(nodes):\n current = queue.pop(0)\n\n if nodes[i] is not None:\n current.left = TreeNode(nodes[i])\n queue.append(current.left)\n i += 1\n\n if i < len(nodes) and nodes[i] is not None:\n current.right = TreeNode(nodes[i])\n queue.append(current.right)\n i += 1\n\n return root\n\ndef max_depth(root):\n ''' Write Your Code '''\n\n\n\n\n\nif __name__ == \"__main__\":\n \n if len(sys.argv) > 1: \n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n root = list_to_tree(i)\n result = max_depth(root)\n print(result)\n \n else:\n input_list = [3, 9, 20, None, None, 15, 7]\n root = list_to_tree(input_list)\n result = max_depth(root)\n print(result)\n \n",
316 | "testCode": {
317 | "input": [
318 | "[3, 9, 20, None, None, 15, 7]",
319 | "[1,None,2]"
320 | ],
321 | "output": [
322 | "3",
323 | "2"
324 | ]
325 | }
326 | },
327 | {
328 | "_id": {
329 | "$oid": "65813607db0ee3b9bc352d3f"
330 | },
331 | "id": "best-time-to-buy-and-sell-stock",
332 | "title": "Best Time to Buy and Sell Stock",
333 | "problemStatement": "You are given an array prices
where prices[i]
is the price of a given stock on the ith
day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0
.
",
334 | "examples": [
335 | {
336 | "id": 0,
337 | "inputText": "prices = [7,1,5,3,6,4]",
338 | "explanation": "Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.",
339 | "outputText": "5"
340 | },
341 | {
342 | "id": 1,
343 | "inputText": "prices = [7,6,4,3,1]",
344 | "explanation": "In this case, no transactions are done and the max profit = 0.",
345 | "outputText": "0"
346 | }
347 | ],
348 | "constraints": "1 <= prices.length <= 105
0 <= prices[i] <= 104
",
349 | "difficulty": "Easy",
350 | "category": "Array",
351 | "order": 9,
352 | "videoId": "",
353 | "starterCode": "import ast\nimport sys\n\n\ndef max_profit(prices):\n if not prices or len(prices) < 2:\n return 0\n\n min_price = prices[0]\n max_profit = 0\n\n '''' Write Your Code '''\n \n\n return max_profit\n\n\n\n\nif __name__ == \"__main__\":\n \n if len(sys.argv) > 1:\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = max_profit(i)\n print(result)\n \n else:\n prices = [7, 1, 5, 3, 6, 4]\n result = max_profit(prices)\n print(result)\n ",
354 | "testCase": {
355 | "Input": [
356 | "[7, 1, 5, 3, 6, 4]",
357 | "[7,6,4,3,1]"
358 | ],
359 | "OutPut": [
360 | "5",
361 | "0"
362 | ]
363 | }
364 | },
365 | {
366 | "_id": {
367 | "$oid": "6581aa6bdb0ee3b9bc352d46"
368 | },
369 | "id": "subsets",
370 | "title": "Subsets",
371 | "problemStatement": "Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order.
",
372 | "examples": [
373 | {
374 | "id": 0,
375 | "inputText": "nums = [1,2,3]",
376 | "outputText": "[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]"
377 | },
378 | {
379 | "id": 1,
380 | "inputText": "nums = [0]",
381 | "outputText": "[[],[0]]"
382 | }
383 | ],
384 | "constraints": "1 <= nums.length <= 10
-10 <= num[i] <= 10
All the numbers of nums
are unique . ",
385 | "difficulty": "Medium",
386 | "category": "Backtracking",
387 | "order": 10,
388 | "videoId": "",
389 | "starterCode": "import sys\nimport ast\n\n\ndef subsets(nums):\n ''' Write Your Logic '''\n\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = subsets(i)\n print(result)\n \n else:\n prices = [1, 2, 3]\n result = subsets(prices)\n print(result)\n ",
390 | "testCase": {
391 | "input": [
392 | "[1,2,3]",
393 | "[0]"
394 | ],
395 | "output": [
396 | "[[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]",
397 | "[[], [0]]"
398 | ]
399 | }
400 | }]
--------------------------------------------------------------------------------
/public/next.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/public/vercel.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/accounts/dashboard/[...id]/page.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 | import axios from 'axios';
3 | import React, { useEffect, useState } from 'react'
4 | import AcountNavbar from '@/components/Header/acountNavbar'
5 | import { IoSearch } from "react-icons/io5";
6 | import { AiOutlineSolution } from "react-icons/ai";
7 | import { ImYoutube2 } from "react-icons/im";
8 | import { ImCheckboxChecked, ImCheckboxUnchecked } from "react-icons/im";
9 | import { useRouter } from 'next/navigation';
10 | import { Users, ProblemList } from '@/helpers/type';
11 |
12 | const page = ({ params }: any) => {
13 |
14 | const router = useRouter();
15 | const [problems, setProblems] = useState([]);
16 | const [user, setUser] = useState();
17 | const [difficultyColors, setDifficultyColor] = useState([
18 | {
19 | type: 'Hard',
20 | color: 'text-red-500',
21 | },
22 | {
23 | type: 'Medium',
24 | color: 'text-orange-400',
25 | },
26 | {
27 | type: 'Easy',
28 | color: 'text-lime-400',
29 | },
30 | ]);
31 |
32 | const getData = async () => {
33 | try {
34 | const problemSet = await axios.get('../../api/utils/problemSets');
35 | setProblems(problemSet.data.data);
36 |
37 |
38 | const user = await axios.get('../../api/utils/verifiedUserDetails');
39 | setUser(user.data.user);
40 |
41 |
42 |
43 | } catch (error) {
44 | console.log(error);
45 | }
46 |
47 | }
48 |
49 | useEffect(() => {
50 | getData();
51 | }, [])
52 |
53 | return (
54 |
55 |
56 |
57 |
58 |
59 |
68 |
69 |
70 |
71 |
72 | Status
73 |
74 |
75 | Problem Title
76 |
77 |
78 | Difficulty
79 |
80 |
81 | Category
82 |
83 |
84 | Solution
85 |
86 |
87 | Video Solution
88 |
89 |
90 |
91 |
92 | {problems.map((problem: any, index) => (
93 |
94 |
95 | {/* status show */}
96 |
97 | {user?.problemList.map((userProblem: ProblemList, index) => (
98 |
99 | {userProblem._id === problem._id ? (
100 | userProblem.solved ? (
101 |
102 | ) : (
103 |
104 | )
105 | ) : (
106 | ''
107 | )}
108 |
109 | ))}
110 |
111 |
112 |
113 | {
114 | router.push(`/accounts/problems/${problem.id}`);
115 | }}>
116 | {problem.order}. {problem.title}
117 |
118 |
119 | {
120 | if (difficultyTypes.type === problem.difficulty) {
121 | return " " + difficultyTypes.color + " ";
122 | }
123 | })}`}>
124 |
125 | {problem.difficulty}
126 |
127 |
128 |
129 | {problem.category}
130 |
131 |
132 | {/* {problem.solution} */}
133 |
134 |
135 |
136 |
137 |
138 |
139 | ))}
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 | )
148 | }
149 |
150 | export default page
151 |
--------------------------------------------------------------------------------
/src/app/accounts/dashboard/page.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 | import React, { useEffect, useState } from 'react'
3 | import axios from 'axios';
4 | import { useRouter } from 'next/navigation';
5 | import { CgProfile } from "react-icons/cg";
6 | import Navbar from "@/components/Header/acountNavbar"
7 | import { toast } from 'react-toastify';
8 | import { Users } from '@/helpers/type';
9 |
10 |
11 | const page = () => {
12 | const router = useRouter();
13 | const [user, setUser] = useState();
14 |
15 | const getUser = async () => {
16 | const res = await axios.get('../../api/utils/verifiedUserDetails');
17 | setUser(res.data.user);
18 | }
19 | useEffect(() => {
20 | getUser();
21 | }, [])
22 |
23 | const handelSignOut = async ()=>{
24 | try {
25 | const res = await axios.get('../../api/auth/signOut');
26 | if (res.status==200) {
27 | toast.success("Successfully logged Out",{
28 | position: "top-center",
29 | autoClose: 2000,
30 | theme: "light"
31 | });
32 | }
33 | router.push('/accounts/signIn');
34 |
35 | } catch (error) {
36 |
37 | }
38 | }
39 |
40 |
41 | console.log();
42 | return (
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
{user?.totalSolved?.toString()}
51 |
Solve Problem
52 |
53 |
54 |
{user?.totalLikes?.toString()}
55 |
Likes
56 |
57 |
58 |
{user?.totalDisLikes?.toString()}
59 |
DisLikes
60 |
61 |
62 |
68 |
69 |
70 | {
73 | router.push(`/accounts/dashboard/${user?._id}`);
74 | }}
75 | >
76 | Dashboard
77 |
78 |
82 | SignOut
83 |
84 |
85 |
86 |
87 |
88 |
{user?.username}
89 |
Kolkata
90 |
91 |
Email - {user?.email}
92 |
Computer Science
93 |
94 |
95 |
96 |
Made By - Ayan Saha
97 |
98 | eat {`->`} code {`->`} sleep
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | )
107 | }
108 |
109 |
110 | export default page
111 |
--------------------------------------------------------------------------------
/src/app/accounts/problems/[id]/page.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 | import React, { useEffect, useState } from 'react'
3 | import Navbar from '@/components/Header/problemPageNavbar'
4 | import Workspace from '@/components/Workspace/workspace'
5 | import axios from 'axios'
6 |
7 |
8 |
9 | const page = () => {
10 |
11 | const [users, setUsers] = useState();
12 | const [problems, setProbelems] = useState();
13 |
14 | const getUser = async () => {
15 | let responce = await axios.get('../../../api/utils/verifiedUserDetails');
16 | setUsers(responce.data.user);
17 | // console.log(responce.data.user);
18 | }
19 |
20 | const getProblems = async () => {
21 | const rest = await axios.get('../../../api/utils/problemSets');
22 | setProbelems(rest.data.data);
23 | // console.log(res.data.data);
24 | }
25 |
26 | useEffect(() => {
27 | getUser();
28 | getProblems();
29 | }, [])
30 |
31 |
32 | return (
33 |
34 |
35 |
36 |
37 | )
38 | }
39 |
40 | export default page
41 |
--------------------------------------------------------------------------------
/src/app/accounts/signIn/page.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 | import React, { useEffect, useState } from 'react'
3 | import Logo from '@/assets/logo2.webp'
4 | import Navbar from '@/components/Header/acountNavbar'
5 | import Image from 'next/image'
6 | import Link from 'next/link'
7 | import { useRouter } from 'next/navigation'
8 | import axios from 'axios'
9 | import { toast } from 'react-toastify'
10 |
11 | const page = () => {
12 | const [email, setEmail] = useState("");
13 | const [password, setPassword] = useState("");
14 | const [loading, setLoading] = useState(false);
15 | const router = useRouter();
16 |
17 | const onSignin = async (e: any) => {
18 | e.preventDefault();
19 |
20 | try {
21 |
22 | setLoading(true);
23 | const res = await axios.post("../api/auth/signIn",{
24 | email: email,
25 | password: password
26 | })
27 |
28 | if (res.status === 200) {
29 | toast.success("Successfully logged in",{
30 | position: "top-center",
31 | autoClose: 2000,
32 | theme: "light"
33 | });
34 | router.push(`/accounts/dashboard/${res.data.data}`);
35 | }
36 |
37 |
38 | } catch (error:any) {
39 | toast.error(error.response.data.error,{
40 | position: "top-center",
41 | autoClose: 2000,
42 | theme: "light"
43 | })
44 |
45 | // console.log(error);
46 | }finally{
47 | setLoading(false);
48 | }
49 | }
50 |
51 | return (
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
LeetCode
61 |
93 |
94 |
95 | Create Your Account
96 | SignUp
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 | )
106 | }
107 |
108 | export default page
109 |
--------------------------------------------------------------------------------
/src/app/accounts/signUp/page.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 | import React, { useState } from 'react'
3 | import Navbar from '@/components/Header/acountNavbar'
4 | import Link from 'next/link'
5 | import Image from 'next/image'
6 | import Logo from '@/assets/logo2.webp'
7 | import { useRouter } from 'next/navigation'
8 | import axios from 'axios'
9 | import { toast } from 'react-toastify'
10 |
11 | const page = () => {
12 | const router = useRouter();
13 | const [userName, setUserName] = useState("");
14 | const [email, setEmail] = useState("");
15 | const [password, setPassword] = useState("");
16 | const [passwordChecker, setPasswordChecker] = useState(false);
17 | const [loding, setLoding] = useState(false);
18 |
19 |
20 | const validPasswordChecker = (pass: string ,confPass: string)=>{
21 | if(pass === confPass){
22 | setPasswordChecker(true);
23 | }else{
24 | setPasswordChecker(false);
25 | }
26 | }
27 |
28 | const onSignup = async (e:any) => {
29 | e.preventDefault();
30 | setLoding(true);
31 |
32 | try {
33 | const res = await axios.post('../api/auth/signUp', {
34 | username: userName,
35 | email: email,
36 | password: password,
37 | })
38 |
39 | if (res.status === 200) {
40 | toast.success(res.data.message,{
41 | position: "top-center",
42 | autoClose: 2000,
43 | theme: "light"
44 | })
45 | console.log(res)
46 | router.push('/accounts/signIn');
47 | }
48 |
49 | } catch (error: any) {
50 | toast.error(error.response.data.error,{
51 | position: "top-center",
52 | autoClose: 2000,
53 | theme: "light"
54 | })
55 |
56 | //rest of the errors
57 | console.log(error);
58 | }finally {
59 | setLoding(false);
60 | }
61 |
62 | }
63 | return (
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
LeetCode
72 |
119 |
120 |
121 | Do you have An Account ?
122 | SignIn
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 | )
131 | }
132 |
133 | export default page
134 |
--------------------------------------------------------------------------------
/src/app/api/auth/profile/route.ts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/app/api/auth/profile/route.ts
--------------------------------------------------------------------------------
/src/app/api/auth/signIn/route.ts:
--------------------------------------------------------------------------------
1 | import connectDB from "@/database/dbConfig";
2 | import { random,authentication } from "@/helpers/encryption";
3 | import { createUser, getUserByEmail } from "@/models/userModel";
4 | import { NextRequest, NextResponse } from "next/server";
5 |
6 |
7 | connectDB();
8 |
9 | export const POST = async(req: NextRequest, res: NextResponse) => {
10 | try {
11 |
12 | const data = await req.json();
13 | const { email, password } = data;
14 |
15 | if (!email || !password) {
16 | return NextResponse.json({ error: "Invalid email or password" },{status: 409});
17 | }
18 |
19 | const verifiedUser = await getUserByEmail(email).select('+authentication.salt + authentication.password');
20 | // console.log(verifiedUser._id.toString());
21 |
22 | if (!verifiedUser) {
23 | return NextResponse.json({ error: "User Not Found" },{status: 400});
24 | }
25 |
26 | if (verifiedUser.authentication && verifiedUser.authentication.salt) {
27 |
28 | const expectedHash = authentication(verifiedUser.authentication.salt, password);
29 |
30 | if (expectedHash !== verifiedUser.authentication.password) {
31 |
32 | // If passwords do not match, return an error response with a 408 status code
33 | return NextResponse.json({ error: "Password Not matched" }, { status: 408 });
34 |
35 | } else {
36 |
37 | // Passwords match
38 | // console.log("Passwords match");
39 |
40 | //creating a token and saving it
41 | const salt = random();
42 | verifiedUser.authentication.sessionToken = authentication(salt, verifiedUser._id.toString());
43 | await verifiedUser.save();
44 |
45 | const oneDayInMilliseconds = 24 * 60 * 60 * 1000;
46 | const response = NextResponse.json({
47 | data: verifiedUser._id,
48 | message: "login successful",
49 | success: true,
50 | expires: Date.now() + oneDayInMilliseconds
51 | })
52 |
53 | response.cookies.set(process.env.TOKEN_NAME!, verifiedUser.authentication.sessionToken,{
54 | httpOnly: true,
55 | path:"/",
56 | });
57 |
58 | return response;
59 |
60 | // return NextResponse.json(verifiedUser,{status: 200});
61 |
62 | }
63 | } else {
64 |
65 | // Handle the case where 'verifiedUser.authentication' is undefined
66 | return NextResponse.json({ error: "User Not Found" }, { status: 404 });
67 |
68 | }
69 |
70 | } catch (error) {
71 | console.log(error);
72 | }
73 |
74 | }
--------------------------------------------------------------------------------
/src/app/api/auth/signOut/route.ts:
--------------------------------------------------------------------------------
1 | import { NextResponse } from "next/server";
2 |
3 | export const GET = async (res: NextResponse) =>{
4 | try {
5 |
6 | const response = NextResponse.json({
7 | message: "LogOut Successfully",
8 | success: true
9 | });
10 |
11 | response.cookies.set(process.env.TOKEN_NAME!, "", {
12 | httpOnly: true,
13 | expires: new Date(0)
14 | });
15 |
16 | return response;
17 |
18 | } catch (error) {
19 | console.log(error);
20 | }
21 | }
--------------------------------------------------------------------------------
/src/app/api/auth/signUp/route.ts:
--------------------------------------------------------------------------------
1 | import connectDB from "@/database/dbConfig";
2 | import { random, authentication } from "@/helpers/encryption";
3 | import { createUser, getUserByEmail } from "@/models/userModel";
4 | import { getProblems } from "@/models/problemModel";
5 |
6 | import { NextRequest, NextResponse } from "next/server";
7 |
8 | connectDB();
9 |
10 | export const POST = async (req: NextRequest, res: NextResponse) => {
11 |
12 | try {
13 | const data = await req.json();
14 | const { username, email, password } = data;
15 | // console.log(data);
16 |
17 | if (!username || !email || !password) {
18 | return NextResponse.json({ error: "Enter username or email" }, { status: 404 });
19 | }
20 |
21 | const existUser = await getUserByEmail(email);
22 |
23 | if (existUser) {
24 | console.log("User already exists");
25 | return NextResponse.json({ error: 'User already exists' }, { status: 409 });
26 | }
27 |
28 | const problems = await getProblems();
29 |
30 | const salt = random();
31 |
32 | // Create a new user with the same password but encrypted
33 | const res= await createUser({
34 | username: username,
35 | email: email,
36 | authentication: {
37 | salt,
38 | password: authentication(salt, password),
39 | },
40 |
41 | totalLikes: 0,
42 | totalDisLikes: 0,
43 | totalSolved: 0,
44 |
45 |
46 | problemList: problems.map((problem) => {
47 | return {
48 | _id: problem._id,
49 | like: false,
50 | dislike: false,
51 | favorite: false,
52 | solved: false,
53 | solvedAnswer: "",
54 | };
55 | }),
56 |
57 | })
58 |
59 |
60 |
61 | return NextResponse.json({ message: "User created" }, { status: 200 });
62 |
63 | } catch (error: any) {
64 | console.log(error);
65 | return NextResponse.json({ error: error.message }, { status: 404 });
66 | }
67 | }
--------------------------------------------------------------------------------
/src/app/api/handler/handelDisLikedproblems/route.ts:
--------------------------------------------------------------------------------
1 | import { NextRequest, NextResponse } from 'next/server'
2 | import connectDB from "@/database/dbConfig";
3 | import { getUserById, updateUserById } from '@/models/userModel';
4 |
5 |
6 | connectDB();
7 |
8 | export const POST = async (req: NextRequest, res: NextResponse) => {
9 | const data = await req.json();
10 | const { disLike, index, user } = data;
11 |
12 | try {
13 |
14 | const updateObject: Record = {};
15 | updateObject[`problemList.${index}.dislike`] = disLike;
16 | await updateUserById(user._id, updateObject);
17 |
18 |
19 | const updatedUser = await getUserById(user._id);
20 |
21 | const dislikedProblems = updatedUser.problemList.filter((problem: any) => problem.dislike === true)
22 |
23 | await updateUserById(user._id, {totalDisLikes: dislikedProblems.length});
24 |
25 |
26 | const response = NextResponse.json({
27 | message: "DisLiked Successfully",
28 | success: true,
29 | })
30 |
31 | return response
32 |
33 | } catch (error) {
34 | console.log(error);
35 | return error;
36 | }
37 | }
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/app/api/handler/handelFavoritesproblems/route.ts:
--------------------------------------------------------------------------------
1 | import { NextRequest, NextResponse } from 'next/server'
2 | import connectDB from "@/database/dbConfig";
3 | import { updateUserById } from '@/models/userModel';
4 |
5 |
6 | connectDB();
7 |
8 | export const POST = async (req: NextRequest, res: NextResponse) => {
9 | const data = await req.json();
10 | const { favorite, index, user } = data;
11 |
12 | try {
13 | const updateObject: Record = {};
14 | updateObject[`problemList.${index}.favorite`] = favorite;
15 |
16 |
17 |
18 | await updateUserById(user._id, updateObject);
19 |
20 | const response = NextResponse.json({
21 | message: "favorite Successfully",
22 | success: true,
23 | })
24 |
25 | return response
26 |
27 | } catch (error) {
28 | console.log(error);
29 | return error;
30 | }
31 | }
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/app/api/handler/handelLikedproblems/route.ts:
--------------------------------------------------------------------------------
1 | import { NextRequest, NextResponse } from 'next/server'
2 | import connectDB from "@/database/dbConfig";
3 | import { getUserById, updateUserById } from '@/models/userModel';
4 |
5 |
6 | connectDB();
7 |
8 | export const POST = async (req: NextRequest, res: NextResponse) => {
9 | const data = await req.json();
10 | const { like, index, user } = data;
11 |
12 | try {
13 | const updateObject: Record = {};
14 | updateObject[`problemList.${index}.like`] = like;
15 | await updateUserById(user._id, updateObject);
16 |
17 |
18 | const updatedUser = await getUserById(user._id)
19 |
20 | const likedProblems = updatedUser.problemList.filter((problem: any) => problem.like === true);
21 |
22 |
23 | // Update 'totalLikes' in a single call
24 | await updateUserById(user._id, { totalLikes: likedProblems.length });
25 |
26 | const response = NextResponse.json({
27 | message: "Liked Successfully",
28 | success: true,
29 | })
30 |
31 | return response
32 |
33 | } catch (error) {
34 | console.log(error);
35 | return error;
36 | }
37 | }
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/app/api/handler/handelSolvedproblems/route.ts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/app/api/handler/handelSolvedproblems/route.ts
--------------------------------------------------------------------------------
/src/app/api/languages/python/run/route.ts:
--------------------------------------------------------------------------------
1 | import { NextRequest, NextResponse } from 'next/server';
2 | import { PythonShell } from 'python-shell';
3 |
4 | export const POST = async (req: NextRequest, res: NextResponse) => {
5 | const data = await req.json();
6 |
7 | const { code } = data;
8 | // console.log(code);
9 |
10 | try {
11 | const message = await PythonShell.runString(code)
12 | const response = NextResponse.json({
13 | data: message,
14 | message: "Compilation Finished",
15 | success: true,
16 | })
17 |
18 | return response;
19 |
20 | } catch (error: any) {
21 | const response = NextResponse.json({
22 | data: null,
23 | message: 'Error during compilation',
24 | success: false,
25 | status: error.status,
26 | error: error.message,
27 | });
28 |
29 | return response;
30 | }
31 |
32 |
33 |
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/app/api/languages/python/submit/route.ts:
--------------------------------------------------------------------------------
1 | import connectDB from '@/database/dbConfig';
2 | import { getUserById, updateUserById } from '@/models/userModel';
3 | import { NextRequest, NextResponse } from 'next/server';
4 | import { PythonShell } from 'python-shell';
5 |
6 | connectDB();
7 |
8 | export const POST = async (req: NextRequest, res: NextResponse) => {
9 | const data = await req.json();
10 | const { user, index, code, problem } = data;
11 |
12 |
13 |
14 | try {
15 |
16 | // Maping the command line parameters
17 | let options = {
18 | args: problem.testCase.input.map((value: string)=>{
19 | return value
20 | })
21 | };
22 |
23 | // Return the output as list(Pyhton)
24 | const message = await PythonShell.runString(code,options)
25 |
26 |
27 | // map the outputs
28 | const Output = problem.testCase.output.map((value: string)=>{
29 | return value
30 | })
31 |
32 |
33 | // check if all the tests passed or failed
34 | let checkResultCount = 0;
35 | for (let index = 0; index < Output.length; index++) {
36 | if (Output[index] === message[index]) {
37 | checkResultCount++;
38 | }else{
39 | break;
40 | }
41 | }
42 |
43 | // returning the responce
44 | if (checkResultCount === Output.length) {
45 |
46 | const updateObject: Record = {};
47 |
48 | // set the solved part true
49 | updateObject[`problemList.${index}.solved`] = true;
50 | await updateUserById(user._id, updateObject);
51 |
52 | // set the solved code in db
53 | updateObject[`problemList.${index}.solvedAnswer`] = code;
54 | await updateUserById(user._id, updateObject);
55 |
56 | // set the solved
57 | updateObject[`problemList.${index}.solved`] = true;
58 | await updateUserById(user._id, updateObject);
59 |
60 | // Set Total number of Solves
61 | const updatedUser = await getUserById(user._id);
62 |
63 | const solvedproblems = updatedUser.problemList.filter((problem: any) => problem.solved === true);
64 | await updateUserById(user._id, { totalSolved: solvedproblems.length });
65 |
66 |
67 |
68 | const response = NextResponse.json({
69 | data: message,
70 | message: "All Test Cases passed",
71 | success: true,
72 | })
73 |
74 |
75 |
76 | return response;
77 | }else{
78 | const responseTaseCase = NextResponse.json({
79 | data: checkResultCount,
80 | message: "All TestCase Not Passed",
81 | success: false,
82 | })
83 | return responseTaseCase
84 | }
85 |
86 |
87 |
88 | } catch (error: any) {
89 | // Handle error
90 | const response = NextResponse.json({
91 | data: null,
92 | message: 'Error during compilation',
93 | success: false,
94 | status: error.status,
95 | error: error.message,
96 | });
97 |
98 | return response;
99 | }
100 |
101 | }
102 |
103 |
104 |
--------------------------------------------------------------------------------
/src/app/api/utils/problemSets/route.ts:
--------------------------------------------------------------------------------
1 | import connectDB from '@/database/dbConfig';
2 | import { NextRequest, NextResponse } from 'next/server';
3 | import {getProblems} from '@/models/problemModel'
4 |
5 | connectDB();
6 |
7 | export const GET = async (req: NextRequest, res:NextResponse) =>{
8 | try {
9 | const data = await getProblems();
10 | return NextResponse.json({data});
11 |
12 | } catch (error) {
13 | console.log(error)
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/src/app/api/utils/verifiedUserDetails/route.ts:
--------------------------------------------------------------------------------
1 | import connectDB from "@/database/dbConfig";
2 | import {getUserBySessionToken} from '@/models/userModel';
3 | import { NextResponse } from 'next/server'
4 | import type { NextRequest } from 'next/server'
5 |
6 | connectDB();
7 |
8 | export const GET = async (request: NextRequest) => {
9 | try {
10 |
11 | const token = request.cookies.get(process.env.TOKEN_NAME!)?.value || '';
12 |
13 | const user = await getUserBySessionToken(token);
14 |
15 | if (user) {
16 | return NextResponse.json({user});
17 | }
18 |
19 | } catch (error) {
20 | console.error(error);
21 | }
22 |
23 | }
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/app/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/app/favicon.ico
--------------------------------------------------------------------------------
/src/app/globals.css:
--------------------------------------------------------------------------------
1 | @tailwind base;
2 | @tailwind components;
3 | @tailwind utilities;
4 |
5 | .split {
6 | display: flex;
7 | flex-direction: row;
8 | }
9 |
10 | .gutter {
11 | background-color: #eee;
12 | background-repeat: no-repeat;
13 | background-position: 50%;
14 | }
15 |
16 | .gutter:hover{
17 | background-color: #282828;
18 | }
19 |
20 | .gutter.gutter-horizontal {
21 | background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAeCAYAAADkftS9AAAAIklEQVQoU2M4c+bMfxAGAgYYmwGrIIiDjrELjpo5aiZeMwF+yNnOs5KSvgAAAABJRU5ErkJggg==');
22 | cursor: col-resize;
23 | }
24 |
25 | .gutter.gutter-horizontal ::-webkit-scrollbar{
26 | width: 5px;
27 | }
28 |
29 | .gutter.gutter-vertical {
30 | background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAFAQMAAABo7865AAAABlBMVEVHcEzMzMzyAv2sAAAAAXRSTlMAQObYZgAAABBJREFUeF5jOAMEEAIEEFwAn3kMwcB6I2AAAAAASUVORK5CYII=');
31 | cursor: row-resize;
32 | }
33 |
34 | ::-webkit-scrollbar {
35 | width: 0.5rem;
36 | background-color: #282828;
37 | }
38 |
39 | ::-webkit-scrollbar-track {
40 | background: #282828;
41 | }
42 |
43 | ::-webkit-scrollbar-thumb {
44 | background: #4d4d4d;
45 | }
46 |
47 | code {
48 | border-radius: 5px;
49 | border-width: 1px;
50 | font-family: sans-serif;
51 | font-size: 0.75rem;
52 | font-weight: 500;
53 | line-height: 1rem;
54 | padding: 0.125rem;
55 | letter-spacing: 1px;
56 | white-space: pre-wrap;
57 | background-color: hsla(0, 0%, 100%, 0.07);
58 | border-color: rgba(247, 250, 255, 0.12);
59 | color: rgba(239, 241, 246, 0.75);
60 | }
61 |
62 |
63 | .example-card pre {
64 | background-color: hsla(0, 0%, 100%, 0.1);
65 | border-radius: 0.5rem;
66 | color: rgba(239, 241, 246, 0.75);
67 | font-size: 0.98rem;
68 | line-height: 1.25rem;
69 | margin-bottom: 1rem;
70 | margin-top: 1rem;
71 | padding: 1rem;
72 | white-space: pre-wrap;
73 | }
74 |
75 | .example-card pre strong {
76 | color: white;
77 | font-size: 1rem;
78 | }
79 |
80 |
81 |
82 | .cm-scroller {
83 | background-color: #282828 !important;
84 | }
85 | .cm-focused {
86 | outline: none !important;
87 | }
88 |
89 |
--------------------------------------------------------------------------------
/src/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import './globals.css'
2 | import type { Metadata } from 'next'
3 | import Footer from '@/components/Footer/footer'
4 | import { ToastContainer } from 'react-toastify';
5 | import 'react-toastify/dist/ReactToastify.css';
6 |
7 | export const metadata: Metadata = {
8 | title: 'LeetCode Clone',
9 | description: 'Created by Ayan Saha',
10 | }
11 |
12 | export default function RootLayout({
13 | children,
14 | }: {
15 | children: React.ReactNode
16 | }) {
17 | return (
18 |
19 |
20 | {children}
21 |
22 |
23 |
24 |
25 | )
26 | }
27 |
--------------------------------------------------------------------------------
/src/app/page.tsx:
--------------------------------------------------------------------------------
1 | import MainBody from '@/components/home/home'
2 | import Navbar from '@/components/Header/landingPageNavbar'
3 |
4 | export default function Home() {
5 | return (
6 |
7 |
8 |
9 |
10 | )
11 | }
12 |
--------------------------------------------------------------------------------
/src/assets/choiceLock.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/assets/choiceLock.pdf
--------------------------------------------------------------------------------
/src/assets/finalChoiceLock.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/assets/finalChoiceLock.pdf
--------------------------------------------------------------------------------
/src/assets/java.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/assets/java.png
--------------------------------------------------------------------------------
/src/assets/js.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/assets/js.png
--------------------------------------------------------------------------------
/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/assets/logo.png
--------------------------------------------------------------------------------
/src/assets/logo2.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/assets/logo2.webp
--------------------------------------------------------------------------------
/src/assets/me1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/assets/me1.png
--------------------------------------------------------------------------------
/src/assets/plate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/assets/plate.png
--------------------------------------------------------------------------------
/src/assets/python.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/assets/python.png
--------------------------------------------------------------------------------
/src/components/Footer/footer.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import {BsFacebook, BsTwitter, BsInstagram, BsLinkedin} from 'react-icons/bs'
3 |
4 |
5 | const footer = () => {
6 | return (
7 |
31 | )
32 | }
33 |
34 | export default footer
35 |
--------------------------------------------------------------------------------
/src/components/Header/acountNavbar.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Image from 'next/image'
3 | import Logo from '@/assets/logo2.webp'
4 | import Link from 'next/link'
5 |
6 |
7 |
8 | const acountNavbar = ({colour, hoverColour} : any) => {
9 | function handleProblemChange(arg0: boolean): void {
10 |
11 | }
12 |
13 | return (
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | Explore
24 | Problems
25 | Discuss
26 | Contest
27 |
28 |
29 | Premium
30 |
31 |
32 |
33 |
34 | )
35 | }
36 |
37 | export default acountNavbar
38 |
--------------------------------------------------------------------------------
/src/components/Header/landingPageNavbar.tsx:
--------------------------------------------------------------------------------
1 | import Image from 'next/image'
2 | import Link from 'next/link'
3 | import React from 'react'
4 | import Logo from '@/assets/logo.png'
5 |
6 | const navbar = () => {
7 | return (
8 |
9 |
10 |
11 |
12 |
13 |
14 |
LeetCode
15 |
16 |
17 |
18 |
19 | Premium
20 |
21 |
22 | Explore
23 |
24 |
25 | Product
26 |
27 |
28 | Developer
29 |
30 |
31 | Sign-In
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | )
40 | }
41 |
42 | export default navbar
43 |
--------------------------------------------------------------------------------
/src/components/Header/playgroundNavbar.tsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react'
2 | import { AiOutlineFullscreen, AiOutlineFullscreenExit, AiOutlineSetting } from 'react-icons/ai';
3 |
4 | const playgroundNavbar = () => {
5 | const [isFullScreen, setIsFullScreen] = useState(false);
6 |
7 | const handleFullScreen = () => {
8 | if (isFullScreen) {
9 | document.exitFullscreen();
10 | } else {
11 | document.documentElement.requestFullscreen();
12 | }
13 | setIsFullScreen(!isFullScreen);
14 | };
15 |
16 | useEffect(() => {
17 | function exitHandler(e: any) {
18 | if (!document.fullscreenElement) {
19 | setIsFullScreen(false);
20 | return;
21 | }
22 | setIsFullScreen(true);
23 | }
24 |
25 | if (document.addEventListener) {
26 | document.addEventListener("fullscreenchange", exitHandler);
27 | document.addEventListener("webkitfullscreenchange", exitHandler);
28 | document.addEventListener("mozfullscreenchange", exitHandler);
29 | document.addEventListener("MSFullscreenChange", exitHandler);
30 | }
31 | }, [isFullScreen]);
32 |
33 | return (
34 |
35 |
42 |
43 |
44 |
setSettings({ ...settings, settingsModalIsOpen: true })}
47 | >
48 |
51 |
52 |
53 |
54 |
55 |
56 | {!isFullScreen ?
:
}
57 |
58 |
59 |
60 |
61 | {/* {settings.settingsModalIsOpen &&
} */}
62 |
63 | );
64 | }
65 |
66 | export default playgroundNavbar
67 |
--------------------------------------------------------------------------------
/src/components/Header/problemPageNavbar.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Image from 'next/image'
3 | import Logo from '@/assets/logo2.webp'
4 | import { FaChevronLeft, FaChevronRight, FaUserAlt } from 'react-icons/fa'
5 | import { PiSignOutBold } from "react-icons/pi";
6 | import Timer from "@/components/Timer/timer";
7 | import { Problem } from '@/helpers/type';
8 | import { useParams } from 'next/navigation';
9 | import { useRouter } from 'next/navigation';
10 | import { toast } from 'react-toastify';
11 | import axios from 'axios';
12 |
13 | type props = {
14 | problems: [Problem]
15 | }
16 |
17 | const problemPageNavbar = ({ problems }: props) => {
18 | const router = useRouter();
19 | const {id} = useParams();
20 |
21 | const handleProblemChange = (isForward: boolean) => {
22 | const direction = isForward ? 1 : -1;
23 | const problemIds = problems.map((problem: any) => problem.id);
24 | const index = problemIds.indexOf(id as string);
25 |
26 | if (index !== -1) {
27 | if (direction === 1 && index < problemIds.length - 1) {
28 | router.push(`./${problemIds[index + 1]}`);
29 | } else if (direction === -1 && index > 0) {
30 | router.push(`./${problemIds[index - 1]}`);
31 | } else if (direction === 1) {
32 | router.push(`./${problemIds[0]}`);
33 | } else if (direction === -1) {
34 | router.push(`./${problemIds[problemIds.length - 1]}`);
35 | }
36 | }
37 | // Handle the case when index === -1 if needed
38 | };
39 |
40 | const handelSignOut = async ()=>{
41 | try {
42 | const res = await axios.get('../../api/auth/signOut');
43 | if (res.status==200) {
44 | toast.success("Successfully logged Out",{
45 | position: "top-center",
46 | autoClose: 2000,
47 | theme: "light"
48 | });
49 | }
50 | router.push('/accounts/signIn');
51 |
52 | } catch (error) {
53 |
54 | }
55 | }
56 |
57 |
58 | return (
59 |
94 | )
95 | }
96 |
97 | export default problemPageNavbar
98 |
--------------------------------------------------------------------------------
/src/components/Timer/timer.tsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react'
2 | import { MdAlarm } from 'react-icons/md';
3 | import { RiTimerFlashLine } from "react-icons/ri";
4 |
5 | const timer = () => {
6 | const [showTimer, setShowTimer] = useState(false);
7 | const [time, setTime] = useState(0);
8 |
9 | // Format timer into : hh:mm:ss format
10 | const formatTime = (time: number): string => {
11 | const hours = Math.floor(time / 3600);
12 | const minutes = Math.floor((time % 3600) / 60);
13 | const seconds = time % 60;
14 |
15 | return `${hours < 10 ? "0" + hours : hours}:${minutes < 10 ? "0" + minutes : minutes}:${
16 | seconds < 10 ? "0" + seconds : seconds }`;
17 | };
18 |
19 | useEffect(() => {
20 | let intervalId: NodeJS.Timeout;
21 |
22 | // increment the interval every second
23 | if (showTimer) {
24 | intervalId = setInterval(() => {
25 | setTime((time) => time + 1);
26 | }, 1000);
27 | }
28 |
29 | return () => clearInterval(intervalId);
30 | }, [showTimer]);
31 |
32 | return (
33 |
34 | {showTimer ?
35 | (
36 | {/*
*/}
37 | {formatTime(time)}
38 | {
40 | setShowTimer(false);
41 | setTime(0);
42 | }}
43 | />
44 |
45 | ) : (
46 |
47 | setShowTimer(true)}
49 | />
50 |
51 | )}
52 |
53 | )
54 | }
55 |
56 | export default timer;
57 |
--------------------------------------------------------------------------------
/src/components/Workspace/Playground/console/consoleRunner.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 | import { BsChevronUp } from 'react-icons/bs'
3 |
4 | type Props = {
5 | handleRun: () => void;
6 | handleSubmit: () => void;
7 | output: string | null;
8 | };
9 |
10 | const UserConsole = ({handleRun,handleSubmit, output}: Props) => {
11 |
12 |
13 | return (
14 | <>
15 |
16 |
17 |
18 |
19 | Console
20 |
21 |
22 |
23 |
24 |
25 |
26 |
30 | Run
31 |
32 |
36 | Submit
37 |
38 |
39 |
40 |
41 | >
42 | )
43 | }
44 |
45 | export default UserConsole
46 |
--------------------------------------------------------------------------------
/src/components/Workspace/Playground/playground.tsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react'
2 | import Navbar from '@/components/Header/playgroundNavbar'
3 | import Split from 'react-split';
4 | import CodeMirror from "@uiw/react-codemirror";
5 | import { python } from '@codemirror/lang-python';
6 | import { vscodeDark } from "@uiw/codemirror-theme-vscode";
7 | import { Problem, Users } from '@/helpers/type'
8 | import UserConsole from '@/components/Workspace/Playground/console/consoleRunner';
9 | import { useParams } from 'next/navigation';
10 | import axios from 'axios';
11 | import { toast } from 'react-toastify';
12 |
13 | type props = {
14 | user : Users,
15 | problems: [Problem],
16 | setSuccess: React.Dispatch>;
17 | }
18 |
19 | const playground = ({ user, problems, setSuccess}: props) => {
20 |
21 | const params = useParams();
22 |
23 |
24 | const [activeTestCaseId, setActiveTestCaseId] = useState(0);
25 | const [clickedProblemsId, setClickedProblemId] = useState();
26 | const [clickedProblems, setClickedProblems] = useState();
27 | const [userCode, setUserCode] = useState();
28 | const [output, setOutput] = useState(null);
29 |
30 | // Set the Main problems among all problems Which store in clickedProblems
31 | useEffect(() => {
32 | if (problems) {
33 | problems.forEach((problem: any, index) => {
34 | if (problem.id === params.id) {
35 | setClickedProblems(problem);
36 | setClickedProblemId(problem._id);
37 | }
38 | })
39 | }
40 | }, [problems])
41 |
42 | // console.log(clickedProblems);
43 |
44 | // When the user come to the particular code section the code automatically dispaly perviously written code
45 | useEffect(() => {
46 | const code = localStorage.getItem(`code -${clickedProblems?.id}`);
47 | // console.log(code);
48 | if (code === '""' || code === null) {
49 | // console.log(clickedProblems?.starterCode)
50 | setUserCode(clickedProblems?.starterCode)
51 | }else{
52 | setUserCode(JSON.parse(code))
53 | }
54 |
55 | }, [clickedProblems?.id])
56 |
57 | // Handle the onChange event
58 | const handleCodeChange = (value: string) => {
59 | setUserCode(value);
60 | }
61 | // Handle the user Written Code
62 | const handleRun = async() => {
63 | try {
64 | localStorage.setItem(`code -${clickedProblems?.id}`, JSON.stringify(userCode)); // Set the code into local storage
65 | const res= await axios.post("../../../api/languages/python/run",{
66 | code : JSON.parse(JSON.stringify(userCode)),
67 | });
68 |
69 | // console.log(JSON.parse(userCode))
70 |
71 | if (res.data.success === true) {
72 | setOutput(`Output : ${res.data.data}`);
73 | toast.success(res.data.message,{
74 | position: "top-center",
75 | autoClose: 2000,
76 | theme: "light"
77 | });
78 | }else{
79 | setOutput(`Error: ${res.data.error}`);
80 | toast.error(res.data.message,{
81 | position: "top-center",
82 | autoClose: 2000,
83 | theme: "dark"
84 | });
85 | }
86 |
87 |
88 | } catch (error: any) {
89 | setOutput(`Error: ${error.message}`);
90 | }
91 | }
92 |
93 |
94 |
95 | const handleSubmit = async () => {
96 | try {
97 | const ids = user?.problemList.map((prob: any) => prob?._id);
98 | const foundIndex = ids.indexOf(clickedProblemsId);
99 |
100 | const res= await axios.post("../../../api/languages/python/submit",{
101 | user : user,
102 | index: foundIndex,
103 | code : JSON.parse(JSON.stringify(userCode)),
104 | problem: clickedProblems
105 | });
106 |
107 | if (res.data.success === true) {
108 | setSuccess(true);
109 | setOutput(`Output : ${res.data.data}`);
110 | toast.success(res.data.message,{
111 | position: "top-center",
112 | autoClose: 2000,
113 | theme: "light"
114 | });
115 |
116 | }else{
117 | setOutput(`Error: ${res.data.error}`);
118 | toast.error(res.data.message,{
119 | position: "top-center",
120 | autoClose: 2000,
121 | theme: "dark"
122 | });
123 | }
124 |
125 | } catch (error) {
126 | console.log(error);
127 | }
128 | }
129 |
130 |
131 | return (
132 |
133 |
134 |
135 |
136 |
145 |
146 |
147 | {/* testcase section */}
148 |
149 |
150 |
151 |
Testcases
152 |
153 |
154 |
155 |
156 | {clickedProblems?.examples.map((example, index) => (
157 |
setActiveTestCaseId(index)}
161 | >
162 |
163 |
168 | Case {index + 1}
169 |
170 |
171 |
172 | ))}
173 |
174 |
175 |
176 |
Input:
177 |
178 | {clickedProblems?.examples[activeTestCaseId].inputText}
179 |
180 |
Output:
181 |
182 | {clickedProblems?.examples[activeTestCaseId].outputText}
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 | {output && <>
192 |
193 |
194 | {output}
195 |
196 |
197 |
198 | >}
199 |
200 |
201 | )
202 | }
203 |
204 | export default playground
205 |
--------------------------------------------------------------------------------
/src/components/Workspace/ProblemDescription/problemDescription.tsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react'
2 | import { useParams } from 'next/navigation'
3 | import { AiOutlineLike, AiFillLike, AiOutlineDislike, AiFillDislike } from "react-icons/ai";
4 | import { FaRegStar, FaStar } from "react-icons/fa";
5 | import { TiInputChecked } from "react-icons/ti";
6 | import { Problem, ProblemList, Users } from '@/helpers/type';
7 | import axios from 'axios';
8 | import { ImCheckboxUnchecked } from 'react-icons/im';
9 |
10 |
11 | type props = {
12 | user: Users,
13 | problems: [Problem],
14 | }
15 |
16 | const problemDescription = ({ user, problems }: props) => {
17 |
18 | const params = useParams();
19 | const [clickedProblems, setClickedProblems] = useState();
20 | const [clickedProblemsId, setClickedProblemId] = useState();
21 | const [like, setLike] = useState(false);
22 | const [disLike, setDisLike] = useState(false);
23 | const [favorite, setFavorite] = useState(false);
24 | const [difficultyColors, setDifficultyColor] = useState([
25 | {
26 | type: 'Hard',
27 | textColor: 'text-red-200',
28 | bgColor: 'bg-red-500',
29 | },
30 | {
31 | type: 'Medium',
32 | textColor: 'text-orange-200',
33 | bgColor: 'bg-orange-500',
34 | },
35 | {
36 | type: 'Easy',
37 | textColor: 'text-lime-200',
38 | bgColor: 'bg-lime-500',
39 | },
40 | ]);
41 |
42 |
43 | // console.log(user)
44 | useEffect(() => {
45 | if (problems) {
46 | problems.forEach((problem: any, index) => {
47 | if (problem.id === params.id) {
48 | setClickedProblems(problem);
49 | setClickedProblemId(problem._id);
50 | }
51 | })
52 | }
53 |
54 | }, [problems])
55 |
56 | useEffect(() => {
57 | const ids = (user?.problemList ?? []).map((prob: any) => prob?._id);
58 | const foundIndex = ids.indexOf(clickedProblemsId);
59 |
60 | if (foundIndex !== -1) {
61 | setLike(user.problemList[foundIndex].like);
62 | setDisLike(user.problemList[foundIndex].dislike)
63 | setFavorite(user.problemList[foundIndex].favorite);
64 | }
65 |
66 | }, [user, problems, clickedProblemsId]);
67 |
68 |
69 |
70 |
71 | const handelLikedproblems = async () => {
72 |
73 | const ids = user?.problemList.map((prob: any) => prob?._id);
74 | const foundIndex = ids.indexOf(clickedProblemsId);
75 |
76 | console.log(foundIndex);
77 |
78 | // Toggle the like state
79 | setLike((prevLike) => !prevLike);
80 |
81 | try {
82 | const res = await axios.post('../../../api/handler/handelLikedproblems', {
83 | like: !like, // Sending the updated like state
84 | index: foundIndex,
85 | user: user,
86 | });
87 |
88 | // console.log(res.data.message); // Assuming the server responds with some data
89 | } catch (error) {
90 | console.error('Error handling liked problems:', error);
91 | }
92 |
93 | };
94 |
95 | const handelDisLikedproblems = async () => {
96 |
97 | const ids = user?.problemList.map((prob: any) => prob?._id);
98 | const foundIndex = ids.indexOf(clickedProblemsId);
99 |
100 | console.log(foundIndex);
101 |
102 | // Toggle the like state
103 | setDisLike((prevDisLike) => !prevDisLike);
104 |
105 | try {
106 | const res = await axios.post('../../../api/handler/handelDisLikedproblems', {
107 | disLike: !disLike, // Sending the updated like state
108 | index: foundIndex,
109 | user: user,
110 | });
111 |
112 | // console.log(res.data.message); // Assuming the server responds with some data
113 | } catch (error) {
114 | console.error('Error handling liked problems:', error);
115 | }
116 |
117 | }
118 |
119 | const handelFavoritesproblems = async () => {
120 | const ids = user?.problemList.map((prob: any) => prob?._id);
121 | const foundIndex = ids.indexOf(clickedProblemsId);
122 |
123 | // console.log(foundIndex);
124 |
125 | setFavorite((prevFavorite) => !prevFavorite);
126 |
127 | try {
128 | const res = await axios.post('../../../api/handler/handelFavoritesproblems', {
129 | favorite: !favorite,
130 | index: foundIndex,
131 | user: user,
132 | });
133 |
134 | // console.log(res.data.message); // Assuming the server responds with some data
135 | } catch (error) {
136 | console.error('Error handling liked problems:', error);
137 | }
138 | }
139 |
140 | return (
141 |
142 |
143 |
144 | Description
145 |
146 |
147 |
148 |
149 |
150 | {clickedProblems?.order}. {clickedProblems?.title}
151 |
152 | {/* section 1 */}
153 |
154 |
{
156 | if (difficultyTypes.type === clickedProblems?.difficulty) {
157 | return " " + difficultyTypes.bgColor + " " + difficultyTypes.bgColor + " "
158 | }
159 | })}
160 | `} >
161 | {clickedProblems?.difficulty}
162 |
163 | {/* Solved Section */}
164 |
165 | {user?.problemList.map((userProblem: ProblemList, index: any) => (
166 |
167 | {userProblem?._id === clickedProblemsId ? (
168 | userProblem?.solved ? (
169 |
170 | ) : (
171 |
172 | )
173 | ) : (
174 | '' // An empty string is rendered when the IDs don't match
175 | )}
176 |
177 | ))}
178 |
179 |
180 | {/* Liked Section */}
181 |
187 | {/* Disliked Section */}
188 |
189 |
190 | {disLike ?
:
}
191 |
192 |
193 |
123
194 |
195 | {/* Favorite Section */}
196 |
197 |
198 | {favorite ? : < FaRegStar size={20} color={'yellow'} />}
199 |
200 |
201 |
202 | {/* section 2 */}
203 |
204 | {/* For HTML content Rendering */}
205 |
206 |
207 | {/* section 3 */}
208 |
209 | {clickedProblems?.examples.map((examples, index) => (
210 |
211 |
Example {examples.id + 1}
212 |
213 |
214 | Input: {examples.inputText}
215 |
216 | Output: {examples.outputText}
217 |
218 |
219 | {examples.explanation && (
220 | <>
221 | Explanation: {examples.explanation}
222 | >
223 | )}
224 |
225 |
226 |
227 |
228 |
229 | ))}
230 |
231 |
232 |
233 | {clickedProblems?.constraints && (
234 | <>
235 | Constraints:
236 |
237 |
238 |
239 | >
240 | )}
241 |
242 |
243 |
244 |
245 | )
246 | }
247 |
248 | export default problemDescription
249 |
--------------------------------------------------------------------------------
/src/components/Workspace/workspace.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 | import { useEffect, useState } from "react";
3 | import Split from "react-split";
4 | import ProblemDescription from "@/components/Workspace/ProblemDescription/problemDescription";
5 | import Playground from "@/components/Workspace/Playground/playground";
6 | import { Problem, Users } from '@/helpers/type';
7 | import Confetti from "react-confetti";
8 | import useWindowSize from "@/hooks/useWindowSize";
9 |
10 | type props = {
11 | users: Users,
12 | problems: [Problem],
13 | }
14 |
15 | const workspace = ({ users, problems }: props) => {
16 | const { width, height } = useWindowSize();
17 | const [success, setSuccess] = useState(false);
18 |
19 | useEffect(() => {
20 | // Automatically set success to false after 4 seconds
21 | if(success){
22 | const timer = setTimeout(() => {
23 | setSuccess(false);
24 | }, 5000);
25 |
26 | // Clear the timer when the component unmounts or when success changes
27 | return () => clearTimeout(timer);
28 | }
29 | }, [success]);
30 |
31 | return (
32 |
33 |
34 |
35 |
36 | {success &&
}
37 |
38 |
39 | );
40 | }
41 |
42 | export default workspace
43 |
--------------------------------------------------------------------------------
/src/components/home/home.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 | import React, { useEffect, useState } from 'react'
3 | import {BiSolidQuoteRight} from 'react-icons/bi'
4 | import Plate from '@/assets/plate.png'
5 | import Java from "@/assets/java.png";
6 | import JavaScript from "@/assets/js.png";
7 | import Python from "@/assets/python.png";
8 | import Me from "@/assets/me1.png";
9 | import Image from 'next/image'
10 | import { useRouter } from "next/navigation";
11 |
12 | const home = () => {
13 | const router = useRouter();
14 | const [isVisible, setIsVisible] = useState(false);
15 | const [firstSentenceCharacters, setFirstSentenceCharacters] = useState([]);
16 | const [secondSentenceCharacters, setSecondSentenceCharacters] = useState([]);
17 | const [firstSentenceIndex, setFirstSentenceIndex] = useState(0);
18 | const [secondSentenceIndex, setSecondSentenceIndex] = useState(0);
19 |
20 | const sentences = ["LeetCode is the best platform to help you enhance your skills, expand your knowledge and prepare for technical interviews.", "Explore is a well-organized tool that helps you get the most out of LeetCode by providing structure to guide your progress towards the next step in your programming career."]
21 |
22 | useEffect(() => {
23 |
24 |
25 | // Split the first sentence into characters
26 | const firstSentenceArray = sentences[0].split('');
27 | setFirstSentenceCharacters(firstSentenceArray);
28 |
29 | // Split the second sentence into characters
30 | const secondSentenceArray = sentences[1].split('');
31 | setSecondSentenceCharacters(secondSentenceArray);
32 |
33 | // Use intervals to update the indices for both sentences
34 | const firstSentenceInterval = setInterval(() => {
35 | setFirstSentenceIndex(prevIndex => prevIndex + 1);
36 | }, 50);
37 |
38 | const secondSentenceInterval = setInterval(() => {
39 | setSecondSentenceIndex(prevIndex => prevIndex + 1);
40 | }, 50);
41 |
42 | // Clear the intervals when all characters have been processed
43 | if (firstSentenceIndex === firstSentenceArray.length) {
44 | clearInterval(firstSentenceInterval);
45 | }
46 | if (secondSentenceIndex === secondSentenceArray.length) {
47 | clearInterval(secondSentenceInterval);
48 | }
49 |
50 | // Cleanup: clear the intervals if the component unmounts
51 | return () => {
52 | clearInterval(firstSentenceInterval);
53 | clearInterval(secondSentenceInterval);
54 | };
55 |
56 | }, []);
57 |
58 | useEffect(() => {
59 | const handleScroll = () => {
60 | const appearPosition = 400;
61 | const scrollY = window.scrollY;
62 |
63 | if (scrollY >= appearPosition) {
64 | setIsVisible(true);
65 | } else {
66 | setIsVisible(false);
67 | }
68 | };
69 |
70 | window.addEventListener('scroll', handleScroll);
71 |
72 | }, []);
73 | return (
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
A New Way to Learn
83 |
84 |
{firstSentenceCharacters.slice(0, firstSentenceIndex + 1).join('')}
85 |
86 | {
88 | router.push('/accounts/signUp');
89 | }}>
90 | Create Account
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
Start Exploring
102 |
103 |
{secondSentenceCharacters.slice(0, secondSentenceIndex + 1).join('')}
104 |
105 | Get Started {`>`}
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
"Code, test, and repeat. That's the way of the programmer."
127 |
128 |
129 |
130 |
131 | We now support 14 popular coding languages. At our core, LeetCode is about developers. Our powerful development tools such as Playground help you test, debug and even write your own projects online.
132 |
133 |
134 | {/* cards */}
135 |
136 |
137 |
138 |
139 |
PYTHON
140 |
TOP SCORER
141 |
Programming is the closest thing we have to a superpower.
142 |
143 |
144 |
145 |
146 |
147 |
JAVA
148 |
TOP SCORER
149 |
Programming is the closest thing we have to a superpower.
150 |
151 |
152 |
153 |
154 |
155 |
JAVASCRIPT
156 |
TOP SCORER
157 |
Programming is the closest thing we have to a superpower.
158 |
159 |
160 |
161 |
162 |
163 |
C
164 |
TOP SCORER
165 |
Programming is the closest thing we have to a superpower.
166 |
167 |
168 |
169 |
170 |
171 | {/* terminal */}
172 |
173 |
174 |
175 |
176 |
177 | If you are passionate about tackling some of the most interesting problems around, we would love to hear from you.
178 |
179 |
180 |
Ayan Saha
181 |
Senior Product Designer
182 |
183 |
184 |
185 |
186 | )
187 | }
188 |
189 | export default home
190 |
--------------------------------------------------------------------------------
/src/database/dbConfig.ts:
--------------------------------------------------------------------------------
1 | import mongoose from "mongoose";
2 |
3 | const connectDB = async () => {
4 | try {
5 | await mongoose.connect(process.env.MONGO_URl!);
6 | console.log("Connected to MongoDB");
7 | } catch (error) {
8 | console.error("MongoDB connection failed:", error);
9 | }
10 | };
11 |
12 | export default connectDB;
--------------------------------------------------------------------------------
/src/helpers/encryption.ts:
--------------------------------------------------------------------------------
1 | import crypto from 'crypto';
2 |
3 | export const authentication = (salt: string, password: string) =>{
4 | return crypto.createHmac('sha256',[salt,password].join('/')).update(process.env.SECRET_KEY!).digest('hex');
5 | }
6 |
7 | export const random = () => crypto.randomBytes(128).toString('base64');
--------------------------------------------------------------------------------
/src/helpers/type.ts:
--------------------------------------------------------------------------------
1 |
2 | export type Example = {
3 | id: number;
4 | inputText: string;
5 | outputText: string;
6 | explanation?: string;
7 | // img?: string;
8 | };
9 |
10 | export type TestCase = {
11 | Input: [];
12 | Output: [];
13 | }
14 |
15 | // local problem data
16 | export type Problem = {
17 | _id: string;
18 | id: string;
19 | title: string;
20 | problemStatement: string;
21 | examples: Example[];
22 | constraints: string;
23 | order: number;
24 | category: string;
25 | difficulty: string;
26 | starterCode: string;
27 | testCase: TestCase;
28 | };
29 |
30 | export type ProblemList = {
31 | _id: string;
32 | like: boolean,
33 | dislike: boolean,
34 | favorite: boolean,
35 | solved: boolean,
36 | solvedAnswer?: string
37 | }
38 |
39 | export type Users = {
40 | _id: any;
41 | username: string;
42 | email: string;
43 | totalLikes: Number,
44 | totalDisLikes: Number ,
45 | totalSolved: Number ,
46 | problemList: ProblemList[],
47 | }
--------------------------------------------------------------------------------
/src/hooks/useLocalStorage.ts:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react'
2 |
3 | const useLocalStorage = (key: string, initialvalue: string) => {
4 | const [value, setValue] = useState(()=>{
5 | try {
6 | if (typeof window !== 'undefined') {
7 | const item = window.localStorage.getItem(key);
8 | return item ? JSON.parse(item) : initialvalue;
9 | }else{
10 | return initialvalue;
11 | }
12 |
13 | } catch (error) {
14 | console.error(error);
15 | }
16 | });
17 |
18 | useEffect(() => {
19 | try {
20 | if (typeof window !== "undefined") {
21 | window.localStorage.setItem(key, JSON.stringify(value));
22 | }
23 | } catch (error) {
24 | console.error(error);
25 | }
26 | }, [key, value]);
27 |
28 | return [ value, setValue ];
29 | }
30 |
31 | export default useLocalStorage
32 |
--------------------------------------------------------------------------------
/src/hooks/useWindowSize.ts:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 |
3 | export default function useWindowSize() {
4 | const [windowSize, setWindowSize] = useState({
5 | width: typeof window !== "undefined" ? window.innerWidth : 1200,
6 | height: typeof window !== "undefined" ? window.innerHeight : 800,
7 | });
8 |
9 | function changeWindowSize() {
10 | if (typeof window !== "undefined") {
11 | setWindowSize({ width: window.innerWidth, height: window.innerHeight });
12 | }
13 | }
14 |
15 | useEffect(() => {
16 | if (typeof window !== "undefined") {
17 | window.addEventListener("resize", changeWindowSize);
18 |
19 | return () => {
20 | window.removeEventListener("resize", changeWindowSize);
21 | };
22 | }
23 | }, []);
24 |
25 | return windowSize;
26 | }
--------------------------------------------------------------------------------
/src/middleware.ts:
--------------------------------------------------------------------------------
1 | import { NextResponse } from 'next/server'
2 | import type { NextRequest } from 'next/server'
3 |
4 |
5 | export async function middleware(request: NextRequest) {
6 | const path = request.nextUrl.pathname;
7 | const isDashboardPath = path.startsWith('/accounts/dashboard');
8 | const isPublicPath = path === '/accounts/signIn' || path === '/accounts/signUp';
9 | const token = request.cookies.get(process.env.TOKEN_NAME!)?.value || '';
10 |
11 | if (isDashboardPath && !token) {
12 | // If trying to access /accounts/dashboard without a token, redirect to sign-in
13 | return NextResponse.redirect(new URL('/accounts/signIn', request.nextUrl));
14 | }
15 |
16 | if (isPublicPath && token) {
17 | // If trying to access private paths with a token, redirect to dashboard -> then it will redirect it to his accounts page
18 | return NextResponse.redirect(new URL(`/accounts/dashboard`, request.nextUrl));
19 |
20 | }
21 | if (!isPublicPath && !token) {
22 | // For any other path that is not public or dashboard, redirect to sign-in
23 | return NextResponse.redirect(new URL('/accounts/signIn', request.nextUrl));
24 | }
25 | }
26 |
27 |
28 | export const config = {
29 | matcher: [
30 | '/accounts/dashboard/:path*',
31 | '/accounts/signIn',
32 | '/accounts/signUp',
33 | ],
34 | }
--------------------------------------------------------------------------------
/src/models/problemModel.ts:
--------------------------------------------------------------------------------
1 | import mongoose, { Model } from "mongoose";
2 | import connectDB from "@/database/dbConfig";
3 |
4 | connectDB();
5 |
6 | const problemSchema = new mongoose.Schema({
7 | id: {
8 | type: String,
9 | required: true,
10 | },
11 | title: {
12 | type: String,
13 | required: true,
14 | },
15 | problemStatement: {
16 | type: String,
17 | required: true,
18 | },
19 | examples: [
20 | {
21 | id: {
22 | type: Number,
23 | required: true,
24 | },
25 | inputText: {
26 | type: String,
27 | required: true,
28 | },
29 | outputText: {
30 | type: String,
31 | required: true,
32 | },
33 | explanation: String,
34 | },
35 | ],
36 | constraints: {
37 | type: String,
38 | required: true,
39 | },
40 | difficulty: {
41 | type: String,
42 | required: true,
43 | },
44 | category: {
45 | type: String,
46 | required: true,
47 | },
48 | order: {
49 | type: Number,
50 | required: true,
51 | },
52 | videoId: {
53 | type: String,
54 | required: true,
55 | },
56 | starterCode: {
57 | type: String,
58 | required: true,
59 | },
60 | });
61 |
62 |
63 | let problemModel : Model;
64 |
65 | try {
66 | problemModel = mongoose.model('problems');
67 | } catch {
68 | problemModel = mongoose.model('problems', problemSchema);
69 | }
70 |
71 |
72 | //actions
73 | export const getProblems = () => problemModel.find();
74 | // export const getProblemByEmail = (email : string) => problemModel.findOne({email});
75 | // export const getProblemBySessionToken = (sessionToken :string) => problemModel.findOne({"authentication.sessionToken" : sessionToken});
76 | // export const getProblemById = (id : string) => problemModel.findById(id);
77 | // export const createProblem = (values: Record) => new problemModel(values).save().then((user: any) => user.toObject());
78 | // export const deleteProblemById = (id : string) => problemModel.findByIdAndDelete({_id : id});
79 | // export const updateProblemById = (id : string , value : Record) => problemModel.findByIdAndUpdate(id, value);
80 |
81 |
--------------------------------------------------------------------------------
/src/models/userModel.ts:
--------------------------------------------------------------------------------
1 | import mongoose, { Model, Schema } from "mongoose";
2 | import connectDB from "@/database/dbConfig";
3 |
4 | connectDB();
5 |
6 | const userSchema = new mongoose.Schema({
7 | username: {
8 | type: String,
9 | required: [true, "Please enter a username"],
10 | },
11 | email: {
12 | type: String,
13 | required: [true, "Please enter a email address"],
14 | },
15 | authentication: {
16 | password: {
17 | type: String,
18 | required: [true, "Please enter a password"],
19 | select: false
20 | },
21 | salt: {
22 | type: String,
23 | select: false,
24 | },
25 | sessionToken: {
26 | type: String,
27 | select: false,
28 | },
29 | },
30 | totalLikes: {
31 | type: Number,
32 | default: 0, // Set a default value if not provided
33 | required: true,
34 | },
35 | totalDisLikes: {
36 | type: Number,
37 | default: 0,
38 | required: true,
39 | },
40 | totalSolved: {
41 | type: Number,
42 | default: 0,
43 | required: true,
44 | },
45 | problemList: {
46 | type: [
47 | {
48 | _id: {
49 | type: Schema.Types.ObjectId,
50 | required: true,
51 | },
52 | like: {
53 | type: Boolean,
54 | default: false,
55 | },
56 | dislike: {
57 | type: Boolean,
58 | default: false,
59 | },
60 | favorite: {
61 | type: Boolean,
62 | default: false,
63 | },
64 | solved: {
65 | type: Boolean,
66 | default: false,
67 | },
68 | solvedAnswer: {
69 | type: String,
70 | default: "",
71 | },
72 | },
73 | ],
74 | select: true,
75 | },
76 |
77 | });
78 |
79 | let userModel : Model;
80 |
81 | try {
82 | userModel = mongoose.model('users');
83 | } catch {
84 | userModel = mongoose.model('users', userSchema);
85 | }
86 |
87 |
88 | //actions
89 | export const getUsers = () => userModel.find();
90 | export const getUserByEmail = (email : string) => userModel.findOne({email});
91 | export const getUserBySessionToken = (sessionToken : string) => userModel.findOne({"authentication.sessionToken" : sessionToken});
92 | export const getUserById = (id : string) => userModel.findById(id);
93 | export const createUser = (values: Record) => new userModel(values).save().then((user: any) => user.toObject());
94 | export const deleteUserById = (id : string) => userModel.findByIdAndDelete({_id : id});
95 | export const updateUserById = (id : string , value : Record) => userModel.findByIdAndUpdate(id, value);
96 |
97 |
--------------------------------------------------------------------------------
/tailwind.config.ts:
--------------------------------------------------------------------------------
1 | import type { Config } from 'tailwindcss'
2 |
3 | const config: Config = {
4 | content: [
5 | './src/pages/**/*.{js,ts,jsx,tsx,mdx}',
6 | './src/components/**/*.{js,ts,jsx,tsx,mdx}',
7 | './src/app/**/*.{js,ts,jsx,tsx,mdx}',
8 | ],
9 | theme: {
10 | extend: {
11 | backgroundImage: {
12 | 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))',
13 | 'gradient-conic':
14 | 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))',
15 | },
16 | keyframes: {
17 | sizeIncrease: {
18 | '0%': {
19 | transform: 'translateY(-25%)'
20 | },
21 | '50%': {
22 | transform: 'translateY(0)' /* Increase the size by 20% */
23 | },
24 | '100%': {
25 | transform: 'translateY(-25%)'
26 | }
27 | }
28 | },
29 | animation: {
30 | sizeIncrease: 'sizeIncrease 3s infinite',
31 | },
32 | transitionDuration: {
33 | '2000': '2000ms',
34 | },
35 |
36 |
37 |
38 | },
39 | },
40 | plugins: [],
41 | }
42 | export default config
43 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": ["dom", "dom.iterable", "esnext"],
5 | "allowJs": true,
6 | "skipLibCheck": true,
7 | "strict": true,
8 | "noEmit": true,
9 | "esModuleInterop": true,
10 | "module": "esnext",
11 | "moduleResolution": "bundler",
12 | "resolveJsonModule": true,
13 | "isolatedModules": true,
14 | "jsx": "preserve",
15 | "incremental": true,
16 | "plugins": [
17 | {
18 | "name": "next"
19 | }
20 | ],
21 | "paths": {
22 | "@/*": ["./src/*"]
23 | }
24 | },
25 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
26 | "exclude": ["node_modules"]
27 | }
28 |
--------------------------------------------------------------------------------