YouTube2Text

Build a Full Stack AI Website Builder with MERN Stack | Complete AI SaaS Project Step by Step — Transcript

by GreatStack · 60,068 words · 9,689 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hello and welcome back to another
  2. 0:02exciting tutorial of great stack. Today
  3. 0:05we are going to build a full stack AI
  4. 0:08website builder from a scratch using MER
  5. 0:11stack. This is a realworld AI SAS
  6. 0:14project where users can sign up, login
  7. 0:18and generate an entire React website
  8. 0:21using a simple text prompt. Once the
  9. 0:24website is generated, users can continue
  10. 0:27improving it by editing the source code
  11. 0:30manually or simply giving the new AI
  12. 0:33prompts to update any section of the
  13. 0:36website. So let's see the project demo
  14. 0:38that we are going to build in this
  15. 0:40tutorial. So let me log out from here.
  16. 0:43After sign out first it will display the
  17. 0:46signin page and if you are new on this
  18. 0:49website you can create an account using
  19. 0:51this create account form. So let me
  20. 0:53login with my existing account. We'll
  21. 0:55provide the existing email id and
  22. 0:58password. So we have added the email id
  23. 1:01and password and click on sign in. After
  24. 1:04sign in it will display the homepage and
  25. 1:06here we have the input field where we
  26. 1:09can enter our prompt to generate the
  27. 1:11website or we can also click on these
  28. 1:14buttons. So it will create these
  29. 1:15websites like rum website, personal
  30. 1:18website, business website, marketing
  31. 1:20website and here it will display the
  32. 1:22list of old project. So you can see we
  33. 1:25have already created another project.
  34. 1:26I'll click here. So this is the old
  35. 1:29project that we have created using this
  36. 1:32simple prompt. Let me just create a new
  37. 1:35project. So I'll come here and here
  38. 1:37we'll add a new prompt. So let's type
  39. 1:40create a modern
  40. 1:43website
  41. 1:45for a coffee shop
  42. 1:49and click on this send button.
  43. 1:53Now you can see the notification AI
  44. 1:55agent is planning a structure and here
  45. 1:58you can see the entire progress and in
  46. 2:01the left side also you can see the chat
  47. 2:03messages. So this is the message that we
  48. 2:05have added and here we have the response
  49. 2:07from AI and it will keep on updating
  50. 2:11when it complete the structure plan and
  51. 2:15after that it will generate the code
  52. 2:16file one by one and once the file is
  53. 2:19generated you can explore it in the file
  54. 2:22section in the left sidebar. So we have
  55. 2:24to wait for few minutes to get our
  56. 2:26project ready.
  57. 2:29Now you can see we have some response in
  58. 2:31the left side. And here also you can see
  59. 2:32the update AI agent is building. And now
  60. 2:35the file structure is ready. It is
  61. 2:38building total nine files. And currently
  62. 2:41it is building the hero.js file which is
  63. 2:44currently active. And one by one it will
  64. 2:47create all these files like app.js style
  65. 2:51dot CSS then header.js. You can see the
  66. 2:54progress 11% is completed. It means one
  67. 2:58file is completed out of nine. So style
  68. 3:01dot CSS is completed and it is creating
  69. 3:04the testimonial.js.
  70. 3:07So we have to wait for few minutes. And
  71. 3:10in the left side also you can see the
  72. 3:12updates like created file/styles
  73. 3:16dot CSS.
  74. 3:18Now you can see 22% completed and now it
  75. 3:22is creating the call toaction.js file.
  76. 3:26So instead of getting the entire code at
  77. 3:29once, you can see the entire development
  78. 3:32process a step by step.
  79. 3:35Now 33% is completed. It is building the
  80. 3:39footer.js and uh you can see these files
  81. 3:42are created. Appjs styles dot CSS
  82. 3:45header.js hero.js.
  83. 3:48Now we have five files left. Now you can
  84. 3:51see 89% progress completed and uh it is
  85. 3:56building our last file that is
  86. 3:58pricing.js.
  87. 4:01Now you can see our website has been
  88. 4:03generated using AI. Here we have the
  89. 4:05navigation bar, hero section and some
  90. 4:09features. And here we have the menu and
  91. 4:12reviews and then we have this footer.
  92. 4:16And in the left side you can see we have
  93. 4:18the updates and in the final message you
  94. 4:21can see website generation complete. You
  95. 4:24can view and edit the files. And to edit
  96. 4:27the website we can click here on the
  97. 4:29files. And here we have the list of
  98. 4:32files and the folder structure. Now if
  99. 4:35you want to update anything here let me
  100. 4:38go to
  101. 4:40hero.jsx. So we can update our hero
  102. 4:44section. Here you can see we have the
  103. 4:47content like this is the
  104. 4:50background image. If you want to replace
  105. 4:52it, you can add your own image URL. Then
  106. 4:56we have the title
  107. 4:59that is t the moment. You can update the
  108. 5:01title here. After that here you can see
  109. 5:03we have the description. Then we have
  110. 5:06our buttons. So this is the order now
  111. 5:09button and this is the view menu button.
  112. 5:13Let me change it instead of this order.
  113. 5:15Now let me change it to order online.
  114. 5:19So now you can see the update on the
  115. 5:21website also. Let me just come back to
  116. 5:24the preview mode again. So we can see
  117. 5:26the preview like this. And if you want
  118. 5:27to see the full page preview, you can
  119. 5:29click on this button open preview. So it
  120. 5:32will display the full page preview. It
  121. 5:34looks good. Now after that here we have
  122. 5:37the button to publish it. If I click
  123. 5:40here our website will be published. So
  124. 5:42that any user can view this website
  125. 5:45without authentication. It will be live.
  126. 5:48Let me open this link. So just click
  127. 5:50here and it will open this link. In the
  128. 5:52new tab you can see the path /publish
  129. 5:54and this project ID. Now this website is
  130. 5:58public and after that here we have the
  131. 6:01button to export it. If I click here you
  132. 6:04will get a zip file and here we have all
  133. 6:07the files and folders. Now let me update
  134. 6:10this website using the AI prompt also.
  135. 6:13So I'll just come back here in the
  136. 6:14sidebar and chat here. Let me add
  137. 6:17another prompt. So I'll provide the
  138. 6:18prompt change the navbar primary color
  139. 6:22from indigo to brown and send it. Now
  140. 6:26you can see here we have our prompt
  141. 6:29change the navar primary color from
  142. 6:31indigo to brown. And here you can see
  143. 6:33the loading. It means the AI is updating
  144. 6:37our website in the background. You can
  145. 6:39see the loading animation here also. Now
  146. 6:42here you can see we have the update
  147. 6:44updated navar primary color from indigo
  148. 6:47to brown across header.js and you can
  149. 6:50see the color has been updated in this
  150. 6:53navbar. Now after that let me just come
  151. 6:55back to the homepage and on this
  152. 6:57homepage you can see we have two
  153. 6:58projects. So this was the overview of
  154. 7:01our AI website builder.
  155. 7:04To power our AI website builder, we will
  156. 7:07use a free AI model from Open Router. So
  157. 7:10you can build and test this project
  158. 7:12without paying for expensive AI APIs.
  159. 7:16Throughout this tutorial, we will use
  160. 7:18Code Rabbit as our AI code reviewer. It
  161. 7:21will automatically review our code,
  162. 7:24suggest improvements, identify potential
  163. 7:26bugs, and help us write cleaner
  164. 7:29production ready code throughout the
  165. 7:31entire development process. Before we
  166. 7:34get started, if you enjoy these in-depth
  167. 7:37full stack tutorials, make sure to hit
  168. 7:40the like button, let's try to reach
  169. 7:425,000 likes on this video. And if you
  170. 7:45would like to see more AI SAS project
  171. 7:48like this in the future, comment AI
  172. 7:50website builder below. Your support
  173. 7:53really motivate me to create more free
  174. 7:55tutorials like this. Now, without
  175. 7:57wasting any more time, let's start
  176. 7:59building our full stack AI website
  177. 8:02builder. To create our project, we will
  178. 8:05come to desktop screen and here we will
  179. 8:07create a project folder and write the
  180. 8:09folder name builder AI.
  181. 8:15Now let's open this project folder with
  182. 8:19code editor. So we will use VS code.
  183. 8:22Now in this one first we have to create
  184. 8:24a react project. For creating the React
  185. 8:27project we will use the wheat package.
  186. 8:30So let's go to
  187. 8:34terminal and open a new terminal
  188. 8:38and in this one we will add npm
  189. 8:43create wheat at latest.
  190. 8:47Press Y to confirm the wheat version.
  191. 8:51After that it is asking for the project
  192. 8:53name. We will create a full stack
  193. 8:56project where we have to create the
  194. 8:58separate client and server. So first we
  195. 9:01have to create the client using react.
  196. 9:04So let's add the project name client.
  197. 9:08That will be our front end.
  198. 9:12Now it is asking to choose the variant.
  199. 9:15So here we will choose
  200. 9:19react.
  201. 9:20After that we will choose JavaScript.
  202. 9:26And here we'll press enter to confirm ox
  203. 9:30lint.
  204. 9:33After that it is asking install with npm
  205. 9:36and start now. So simply press yes.
  206. 9:42So it will install the required
  207. 9:44dependencies and start the project. So
  208. 9:47in the left sidebar you can see we have
  209. 9:50the client folder. If I expand this
  210. 9:52client, you can see the entire project
  211. 9:55structure like we have the node modules
  212. 9:57that includes all the packages. Here we
  213. 10:00have the public folder src and this is
  214. 10:03the main file index dot html. And in
  215. 10:07this terminal you can see we have this
  216. 10:09URL localhost
  217. 10:12port 5173. Let me open this link in the
  218. 10:15web browser.
  219. 10:18So you can see our basic V plus React
  220. 10:21project is successfully running in the
  221. 10:24web browser. Next we'll clear this
  222. 10:26project.
  223. 10:28Just come back to the VS code and we
  224. 10:31will hide this terminal.
  225. 10:33In this src you can see we have
  226. 10:37app dot CSS. We will delete this.
  227. 10:42And uh after that we have
  228. 10:45app dot JSX. So we will clear this file
  229. 10:48and here simply add RAFCE to create the
  230. 10:51React component structure. We are using
  231. 10:54this sort code because we have added one
  232. 10:56extension. If I open this extensions
  233. 10:59list
  234. 11:01here we'll search for
  235. 11:04ES7 react redux react native snippets.
  236. 11:07So we have to install this extension so
  237. 11:10that you can use the sort code to create
  238. 11:12this component structure.
  239. 11:15Now after that we have index dot CSS.
  240. 11:17Let's clear this one also and after that
  241. 11:21we have the main and then we have this
  242. 11:24index html. In this one you can see we
  243. 11:27have the project title which is client.
  244. 11:29So let me update this project title that
  245. 11:32will be webpage title. So here we will
  246. 11:35write builder AI
  247. 11:39and we'll add the channel name create a
  248. 11:42stag. Save the changes. After that we
  249. 11:46can update this favicon also. But before
  250. 11:48that let me save the changes and open
  251. 11:50the web page. So now you can see our
  252. 11:54default app is cleared. Here you can see
  253. 11:56the title also which is builder AI
  254. 12:00greatest stack and we have the default
  255. 12:02icon in the favicon. So we will update
  256. 12:04this icon. For that [gasps]
  257. 12:06let's just come here in the desktop and
  258. 12:09here you can see we have a folder called
  259. 12:11builder AI assets. So you can download
  260. 12:14this assets folder from the video
  261. 12:16description and in this one you will
  262. 12:18find the public folder server folder
  263. 12:23utils API.js
  264. 12:26assets.js and index dot CSS. So let's
  265. 12:30add these files in our project.
  266. 12:34So let me minimize it.
  267. 12:37I'll resize this one. This is the asset
  268. 12:39file or folder and this is the
  269. 12:43project [snorts] directory. Here we have
  270. 12:45the client and in this client you can
  271. 12:47see we have the src. So in this client
  272. 12:52src you can see we have the assets. So
  273. 12:55in this assets we have some default
  274. 12:58files right. So just remove all the
  275. 13:00files from here
  276. 13:02and after that let's open the assets
  277. 13:05folder and from this assets you will
  278. 13:08find the
  279. 13:10assets.js
  280. 13:13just copy and paste it here.
  281. 13:18After that let's come back here in the
  282. 13:21client. So in this client
  283. 13:25you will find the src. So within this
  284. 13:28src just paste this utils. So from here
  285. 13:32copy this utils and paste it here in
  286. 13:35this src.
  287. 13:37After that here you can see we have the
  288. 13:39public folder. So in this public folder
  289. 13:42we have the bg image favicon and logo.
  290. 13:45So just copy everything from this public
  291. 13:48folder and come here in the project. In
  292. 13:52this project also you will find the
  293. 13:54public and paste the files here.
  294. 13:58Replace the files in destination and
  295. 14:00remove this icon. SVG.
  296. 14:04That's it. So now we have added the
  297. 14:08files from public then utils. And now
  298. 14:12let's add this API also. In this API, we
  299. 14:15have created the dummy API that will be
  300. 14:17used in the client until we create our
  301. 14:20own backend server. So just copy this
  302. 14:23API.js from here and open our client
  303. 14:27project. In this client we have the src
  304. 14:31and uh in this src
  305. 14:34let's create a folder and write the
  306. 14:37folder name API and within this API
  307. 14:40folder provide this file that is API do
  308. 14:44js.
  309. 14:46So we have added the API.js JS assets
  310. 14:49and now just copy this index dot CSS
  311. 14:52also. Copy this index dot CSS and
  312. 14:55replace this one. In this client src you
  313. 14:58will find the index dot CSS. So replace
  314. 15:00it. So we'll paste it here and replace
  315. 15:02the file in destination.
  316. 15:05Now after that we'll open the VS code
  317. 15:08and here you can see
  318. 15:10we have the
  319. 15:12public folder. In this public folder we
  320. 15:15have these images. Then we have src. In
  321. 15:18the src we have assets and here we have
  322. 15:22the assets.js.
  323. 15:24In this one we have one
  324. 15:28array that is home tags. After that
  325. 15:33here you can see we have a utils folder.
  326. 15:37In this utils folder we have two files
  327. 15:40export project.js and sandpack utils.js.
  328. 15:46And after that in the API folder we have
  329. 15:48API.js
  330. 15:50file where we have created the
  331. 15:53demi APIs. And here this API will return
  332. 15:56some data like it will return the dummy
  333. 15:59user like this. Then initial projects.
  334. 16:04After updating this, let me save the
  335. 16:06changes and open the web page again.
  336. 16:11Here we are getting some error. no such
  337. 16:14file or directory
  338. 16:16that is Telvin CSS right so we have to
  339. 16:19add the dependencies also let me just
  340. 16:21come back and we'll add the dependencies
  341. 16:24for Telvin CSS to add the Telwind CSS in
  342. 16:28this wheat project we'll open the web
  343. 16:30browser and search for
  344. 16:34wheat plus Telwind
  345. 16:37let's open it and uh after that you can
  346. 16:41see the steps to create your project
  347. 16:44right so we have created our wheat
  348. 16:46project then you can see the second step
  349. 16:49install Telvin CSS for installing the
  350. 16:52Telvin CSS let's just copy this command
  351. 16:56copy this one and come back here in the
  352. 16:58VS code open the terminal and uh in this
  353. 17:02terminal
  354. 17:04let's add control C and you can see we
  355. 17:08are in the builder AI so we have to
  356. 17:10navigate into client so just add
  357. 17:12cdclient.
  358. 17:15Now we are in the client directory and
  359. 17:18here we'll paste this command npm
  360. 17:20install telvin css and add the rate
  361. 17:23telvin css/weet.
  362. 17:26So it is installing these packages.
  363. 17:30Till then we can see the next step. So
  364. 17:32the next step is to configure the wheat
  365. 17:36config.ts file. In this one, we have to
  366. 17:39add the Telwind CSS function and import
  367. 17:42it from this Telvin CSS/V. So, just copy
  368. 17:46this import statement first
  369. 17:50and come here and open vconfig.js.
  370. 17:54In this vconig js, just add this import
  371. 17:58statement and uh after this react, let's
  372. 18:02add comma and simply provide telvin css.
  373. 18:07Let's move it in the new line.
  374. 18:10Save the changes. Let's see the steps
  375. 18:12here. So you can see inside the plug-in
  376. 18:14we have to add telvin CSS that we have
  377. 18:16already added. Now after that we have to
  378. 18:19add this import telvin CSS in the CSS
  379. 18:23file. So that is already added here.
  380. 18:26Let's open
  381. 18:28src and uh in this src
  382. 18:32we have index dot css. So in this index
  383. 18:35dot CSS you can see we have already
  384. 18:37added import telind CSS
  385. 18:40let's see the next step. So now we can
  386. 18:43run our project and uh after that we can
  387. 18:46easily use the Telbint classes in any
  388. 18:49component in any HTML element. Right? So
  389. 18:55let's run our project again using npm
  390. 18:57rundev. Just come back here
  391. 19:01and add this command. But before
  392. 19:04starting this project, let me add the
  393. 19:06other dependencies also that will be
  394. 19:07used inside this client project. So
  395. 19:10after adding the telman CSS here we will
  396. 19:13add the routing right for that we have
  397. 19:17to add the react router DOM. So let's
  398. 19:20add
  399. 19:22npm install and the package name
  400. 19:26react router DOM.
  401. 19:30After that we'll add the next package
  402. 19:32that is react hot toast. Using this
  403. 19:35package we can display the toast
  404. 19:37notification. Then add a space and add
  405. 19:40the another package name that is lucid
  406. 19:43react. Using this lucid react package we
  407. 19:47can add the icons in our project. After
  408. 19:50that we'll add the moments package. So
  409. 19:53using this moments package we can format
  410. 19:57the date and time. Then we'll add the
  411. 20:00axios package. Using this axio package
  412. 20:03we will make the network request.
  413. 20:07Then we have to add the sandbox. Using
  414. 20:09the sandbox, we can enable the live
  415. 20:14editing for the code that we will
  416. 20:17generate using AI. So here we'll add at
  417. 20:21code sandbox/
  418. 20:24sandpack react.
  419. 20:27Add a space. Then we'll add the file
  420. 20:30server. Using this file server, we will
  421. 20:32add the codes in the sandbox. Because
  422. 20:36our codes are saved in the database and
  423. 20:39from the database, we have to display
  424. 20:41the codes in the sandbox. For that, we
  425. 20:43will use the file server and it will be
  426. 20:46used for exporting the code also, right?
  427. 20:49But for exporting the code, we have to
  428. 20:51create a zip. So here we'll add the next
  429. 20:54package that is js zip. Then add a
  430. 20:57space. And here we'll add one more
  431. 21:00package that is
  432. 21:02load
  433. 21:04debounce. Using this package we will
  434. 21:07enable autosaving of the code when we
  435. 21:09will edit the code in sandbox. So you
  436. 21:12can see we have added npm install and
  437. 21:14other packages name like react router
  438. 21:17DOM react hot toast Lucid React moments
  439. 21:21axios code sandbox/ sandpack-
  440. 21:25react then file server jsjip and load
  441. 21:30debounce press enter to install all
  442. 21:33these dependencies
  443. 21:38now you can see all dependencies has
  444. 21:41been inst installed. Let me verify it.
  445. 21:43We will hide this terminal and open the
  446. 21:46package.json file. So in this one you
  447. 21:49can see we have the dependencies and
  448. 21:51here we have code sandbox css exos file
  449. 21:56server jszip load dash debounce lucid
  450. 22:00react moment react react dom react hot
  451. 22:04toast react router and telvin css. So
  452. 22:08after adding these dependencies we can
  453. 22:10start the project again. So let's open
  454. 22:12the terminal and in this client
  455. 22:16directory we can add this command
  456. 22:20npm
  457. 22:22run dev.
  458. 22:26So it will start the project on the same
  459. 22:28URL. After that we can hide this and
  460. 22:31open the web page.
  461. 22:36So now you can see if I reload the web
  462. 22:38page you can see here we have the
  463. 22:40updated favicon icon and after this icon
  464. 22:44we have the text called builder AI
  465. 22:47greatest stack that is the title. Now we
  466. 22:50will connect our project with GitHub.
  467. 22:53For that we'll come back to the VS code
  468. 22:58and let's click on this source control
  469. 23:00icon
  470. 23:02initialize repository
  471. 23:04and here we'll add the message first
  472. 23:06commit.
  473. 23:10We'll click on publish branch
  474. 23:13and let's choose the repository type. So
  475. 23:16we will choose the GitHub private
  476. 23:18repository and the repository name is
  477. 23:21builder.ai. Let's click here. So it will
  478. 23:24upload our code on GitHub.
  479. 23:31Let me authenticate this.
  480. 23:35I'll click on this button. Authorize Git
  481. 23:37Ecosystem.
  482. 23:40Authentication succeeded.
  483. 23:43And uh after that let's come here in the
  484. 23:46VS code.
  485. 23:50So you can see our project is
  486. 23:52successfully uploaded on GitHub. Let me
  487. 23:54open the GitHub profile.
  488. 23:58So here you can see our project has been
  489. 24:00uploaded here. So we have uploaded our
  490. 24:03project on GitHub.
  491. 24:06Now that we have created our basic React
  492. 24:09project, it's time to start building the
  493. 24:11UI for our AI website builder
  494. 24:14application. But before we begin writing
  495. 24:16more code, let's set up an AI code
  496. 24:20review tool that will help us throughout
  497. 24:22this project. We will use Code Rabbit.
  498. 24:25Code Rabbit is an AI code review tool
  499. 24:27that analyzes your code, detects bugs,
  500. 24:32suggests fixes, and recommends
  501. 24:34improvements to make your code cleaner
  502. 24:36and more maintainable. It can save you a
  503. 24:40significant amount of development time
  504. 24:42by catching issues early so you can
  505. 24:45focus more on building features instead
  506. 24:47of debugging. Code Rabbit also comes
  507. 24:50with a powerful new feature called
  508. 24:53change a stack. It immediately groups
  509. 24:55related code changes, adds AI generated
  510. 24:58summaries and make large pool request
  511. 25:00much easier to understand and review. It
  512. 25:03also includes an agent chat where you
  513. 25:07can ask questions about the changes,
  514. 25:09understand the code better, and get
  515. 25:11instant explanations without leaving the
  516. 25:14review. I recommend using code rabbit
  517. 25:17for all your development projects, not
  518. 25:19just this one. If you are building
  519. 25:22projects with AI coding assistant or
  520. 25:24doing a lot of w coding, it's very
  521. 25:27common for a small bugs and code quality
  522. 25:29issues to slip into your project. Code
  523. 25:32Rabbit helps you identify those problems
  524. 25:35quickly and even suggest how to fix
  525. 25:38them, making your development workflow
  526. 25:40much more efficient. Code Rabbit offer
  527. 25:43multiple pricing plan. With the free
  528. 25:45plan, you can review your code directly
  529. 25:48from the CLI and within your IDE. If you
  530. 25:52upgrade to the Pro or Pro Plus plan, you
  531. 25:55can also get automated AI code review on
  532. 25:58every pull request, making it perfect
  533. 26:01for team collaboration and professional
  534. 26:03development. The pro plan also includes
  535. 26:07a 14 days free trial. And if you use the
  536. 26:10coupon code provided in the description
  537. 26:12below, you can get the pro plan
  538. 26:15completely free for 2 months. So just
  539. 26:17click on the link given in the
  540. 26:19description and sign up for code rabbit
  541. 26:21and let's integrate it into our project
  542. 26:24before we continue building our
  543. 26:26application. So I'll click on this get a
  544. 26:29free trial button
  545. 26:31and let me sign up using my GitHub
  546. 26:34account.
  547. 26:38Now I'll click on this button
  548. 26:41authorize code rabbit.
  549. 26:46After sign up, it is asking to select an
  550. 26:49organization. So let's select this one
  551. 26:51and click on install.
  552. 26:55After that here you can choose the
  553. 26:57individual repository or you can select
  554. 26:59this all repositories and click on
  555. 27:01install and authorize.
  556. 27:09After that we'll click on this skip
  557. 27:11onboarding.
  558. 27:13After that we will click on this button
  559. 27:15add repositories.
  560. 27:19So here we already have this builder AI
  561. 27:22that we want to analyze. Now after that
  562. 27:25we'll come back here in the
  563. 27:29GitHub and we'll go to settings
  564. 27:34and here let's go to
  565. 27:37GitHub apps. So here you can see the
  566. 27:40code rabbit is installed on this GitHub
  567. 27:43repo. So this code rabbit will analyze
  568. 27:45our code and suggest the improvements
  569. 27:47and bug fix. After that we have to
  570. 27:50create a new branch in our VS code. So
  571. 27:54let me just come here and click on this
  572. 27:56three dot and select branch create
  573. 28:00branch and write the branch name. So
  574. 28:02I'll write development.
  575. 28:06After that click on publish branch.
  576. 28:10That's it. Now whenever we will add a
  577. 28:12new code, write a new code, we will
  578. 28:14commit the changes in the development
  579. 28:16branch and after that we will create the
  580. 28:18pull request. So the code rabbit will
  581. 28:21review the pull request and after review
  582. 28:24we can merge the changes from
  583. 28:25development branch to the main branch.
  584. 28:29So after building the basic app and
  585. 28:31setting the AI code review tool code
  586. 28:34rabbit, now we will start building our
  587. 28:36project. And once we create our first
  588. 28:39feature, we will create one pull request
  589. 28:42to review our code using code rabbit. So
  590. 28:45let's start by creating the folder
  591. 28:47structure for our project. For that,
  592. 28:50let's come back to the VS code.
  593. 28:53Open this sidebar and in this one just
  594. 28:56create the folder structure. So in this
  595. 28:59src we have a folder called API, then
  596. 29:03assets and utils. Now we'll create the
  597. 29:07other folders. So in this src create a
  598. 29:10new folder and write the folder name
  599. 29:12pages.
  600. 29:14In this one we'll add all the pages for
  601. 29:16our project. Now we'll add the next
  602. 29:19folder for the components.
  603. 29:25After that we'll create another folder.
  604. 29:27So let's add the folder name. We'll add
  605. 29:30the folder name context.
  606. 29:35In this context folder, we'll create the
  607. 29:38context file to store the global states
  608. 29:41and function that will be used in entire
  609. 29:45application.
  610. 29:47Now after that let's start creating the
  611. 29:50pages also. So
  612. 29:54we'll come here in the pages folder. And
  613. 29:57here just create a new file and write
  614. 29:59the file name homepage.jsx.
  615. 30:06And here we'll add r a fce for creating
  616. 30:10the component structure.
  617. 30:13After that we'll create the
  618. 30:16next page. So in this pages
  619. 30:21let's create the new file and write the
  620. 30:24file name o page.jsx.
  621. 30:30So this o page will display the login or
  622. 30:34registration form.
  623. 30:37Here also we'll create the component
  624. 30:39structure. After that we'll add the new
  625. 30:42page. So write the page name builder
  626. 30:45page dot jsx.
  627. 30:52Now we'll create the
  628. 30:55next page that is preview page.
  629. 31:03After that we will create the next page
  630. 31:06that is publish page.
  631. 31:12And after that we'll add one more page
  632. 31:16that will be layout. So create a new
  633. 31:18file and add the page name or file name
  634. 31:22layout.
  635. 31:23Here also we'll add RAFCE
  636. 31:26layout. After that we will mount these
  637. 31:29pages on different routes. So whenever
  638. 31:32we'll change the route it will display
  639. 31:34different pages. For that
  640. 31:38let's open the
  641. 31:41app.jsx file. And in this one you can
  642. 31:45see we have a return. In this return we
  643. 31:48have a div. So let's remove this div.
  644. 31:52And here we can use the routes. But
  645. 31:56before using the routes let me undo this
  646. 32:00to add the div. And before using the
  647. 32:02routes, we have to enable the routing in
  648. 32:05entire project. For that, let's come
  649. 32:08here
  650. 32:10in the main.jsx.
  651. 32:13Here you can see we have a strict mode.
  652. 32:15So remove this a strict mode opening and
  653. 32:17closing tag. And here we'll add the
  654. 32:19browser router.
  655. 32:23We are not getting the suggestion here.
  656. 32:25So let's import it manually. Here just
  657. 32:29add
  658. 32:31import
  659. 32:33kal braces from and provide the package
  660. 32:38react router dom and from this react
  661. 32:41router dom we can get the browser router
  662. 32:45and provide this browser router here
  663. 32:48browser router opening tag and closing
  664. 32:50tag. Now in entire application we can
  665. 32:54use the routing. So let's come here in
  666. 32:57the app dot jsx and in this app dot jsx
  667. 33:01let's create one
  668. 33:04routes. So we will add the
  669. 33:08routes tag
  670. 33:11and import this routes tag from react
  671. 33:13router dom. Close this routes and within
  672. 33:16this we will add one comment. So let's
  673. 33:19add
  674. 33:21comment called login routes.
  675. 33:25So in this login routes, we'll create
  676. 33:29another route. So let's add
  677. 33:32route component.
  678. 33:35So let's click here to import it
  679. 33:38and close this route tag. So you can see
  680. 33:41we have added the routes and route both
  681. 33:45are imported from this react router DOM.
  682. 33:48Now in this route we have to add the
  683. 33:52element
  684. 33:55and in this element we will provide our
  685. 33:59layout.
  686. 34:01Let me correct it. We will add element
  687. 34:04equal to and then provide the opening
  688. 34:06arrow
  689. 34:08layout from pages
  690. 34:11like this. And within this let's add
  691. 34:15another route and it will be
  692. 34:17self-closing.
  693. 34:20In this route we have to add the path.
  694. 34:22So the path will be / login.
  695. 34:27Then we'll add the element. And in this
  696. 34:30element
  697. 34:32simply provide the o page.
  698. 34:36O page has been imported here. In this o
  699. 34:39page we have to add the props. So let's
  700. 34:42add the mode and in this mode provide
  701. 34:46login.
  702. 34:49Now duplicate this one and in the second
  703. 34:53one we'll add the path register.
  704. 34:57Then element and in this one also we'll
  705. 34:59add the o page and mode will be
  706. 35:01register.
  707. 35:03Right now after adding it, if I save the
  708. 35:06changes and uh come back here
  709. 35:13and here we'll add /
  710. 35:16login. So you can see it is displaying
  711. 35:18this layout at the top left corner
  712. 35:21because first we have mounted this
  713. 35:23layout here, right? But it should also
  714. 35:26display the o page. For that we have to
  715. 35:29modify our layout file. So just open the
  716. 35:33layout. JSX.
  717. 35:35In this layout file, let's wrap this div
  718. 35:38inside a fragment.
  719. 35:42So it will display the text called
  720. 35:44layout. And after that here we have to
  721. 35:46add the outlet. So just add
  722. 35:52outlet and import this outlet from react
  723. 35:55router DOM. Save the changes and open
  724. 35:58the web page. So now you can see first
  725. 36:00it is displaying the layout and after
  726. 36:02that it is also displaying the O page
  727. 36:06correct
  728. 36:08because it is also mounting this O page
  729. 36:13from here from the pages.
  730. 36:17Next we need the user data so that we
  731. 36:20can redirect the users. If the user is
  732. 36:22logged in then we will redirect the
  733. 36:25users on homepage and if the user is not
  734. 36:30logged in in this case we will redirect
  735. 36:32the users on login or registration page.
  736. 36:36For that we have to create one context
  737. 36:39file. So we have already created the
  738. 36:41context folder. Now in this context
  739. 36:44folder create a new file and write the
  740. 36:46file name app context.jsx. JSX
  741. 36:58in this app context. Let's create a new
  742. 37:02context using create context. So just
  743. 37:06add con
  744. 37:09app context
  745. 37:11equal to create context and import the
  746. 37:15create context from React. And in this
  747. 37:18one simply add undefined.
  748. 37:23Now after that we have to create the
  749. 37:26context provider function. So just add
  750. 37:29export function app context provider.
  751. 37:35And here we'll get the parameter. So
  752. 37:38just add the
  753. 37:41curly braces children.
  754. 37:45After that
  755. 37:47here we'll add the return statement
  756. 37:52and in this return
  757. 37:55simply provide
  758. 37:57app context dot provider. Close this tag
  759. 38:03and uh within this we will simply
  760. 38:06provide children
  761. 38:09and uh after that here we will provide
  762. 38:12the value. So in this value we can pass
  763. 38:15all the states and functions that will
  764. 38:18be used in entire application
  765. 38:21right. So let's simply add
  766. 38:26value and in this one just add the empty
  767. 38:30object for now.
  768. 38:32So we have created one
  769. 38:35app context provider function. After
  770. 38:38that we'll add one function using that
  771. 38:40we can easily access this context. So
  772. 38:42here just add export
  773. 38:47function and add the function name use
  774. 38:50app context.
  775. 38:54Now in this function just add const
  776. 38:58context
  777. 39:01equal to
  778. 39:03use context and import the use context
  779. 39:06from react and provide the app context
  780. 39:09here.
  781. 39:11After that we'll add the if statement.
  782. 39:13If
  783. 39:14context
  784. 39:16is equal to
  785. 39:18undefined.
  786. 39:20In this case we will throw the error. So
  787. 39:23just at throw new error and provide the
  788. 39:26message that is use app context must be
  789. 39:30used within an app context provider. And
  790. 39:34if it is false in this case simply
  791. 39:36return this context. So just add return
  792. 39:40context.
  793. 39:42So using this use app context we can
  794. 39:45easily access the context data. Now
  795. 39:48let's create some states that will be
  796. 39:51accessible in other components. So here
  797. 39:55let me create the state for user.
  798. 40:00Let's scroll up and here let's add
  799. 40:04comment that is o states. Just add const
  800. 40:10and provide the state name that is user
  801. 40:14and setter function is set user equal to
  802. 40:17use a state and initialize it using
  803. 40:20null.
  804. 40:23After that we'll add const
  805. 40:28and the state name is loading user
  806. 40:32and setter function is set loading user
  807. 40:36equal to user state and initialize it
  808. 40:38using true. So by default loading user
  809. 40:41will be true.
  810. 40:44Now we can use this user state in any
  811. 40:46component or any pages and based on this
  812. 40:49user we can display the homepage or
  813. 40:52login page. If the user is null then we
  814. 40:55will display the authentication page
  815. 40:57like login or register page and if the
  816. 41:00user is available in this case we will
  817. 41:02open the homepage or
  818. 41:05builder page and if the user is loading
  819. 41:09in this case we'll display the loading
  820. 41:11animation for that we have to create one
  821. 41:14loading component also so just come here
  822. 41:17in the components folder
  823. 41:19and here create a new file and write the
  824. 41:22file name loading.jsx.
  825. 41:29Here we'll add r a fce for creating the
  826. 41:33component structure. And uh in this one
  827. 41:38we have a div. So within this div
  828. 41:43we will add one
  829. 41:45icon. So just add opening arrow
  830. 41:48loader to icon from lucid react. It has
  831. 41:52been imported from Lucid React. And here
  832. 41:54we'll add the size 26. And with that
  833. 41:56we'll add some Telvin classes. So
  834. 41:58provide the class name property and
  835. 42:00animate spin text zinc 950.
  836. 42:05So we will add the class name property
  837. 42:07and provide the tailwind classes like
  838. 42:09height screen. Then flex item center
  839. 42:12justify center and background white.
  840. 42:16After that we can remove this import
  841. 42:19react. Save the changes and you can see
  842. 42:22we have exported this loading from here.
  843. 42:24So we can access this loading component
  844. 42:27in any file. Now after that we have to
  845. 42:30enable the context in entire
  846. 42:33application. Then only we can use the
  847. 42:35context data anywhere. So let's come
  848. 42:38here in the main.jsx. Again in this main
  849. 42:43jx we have to wrap our application using
  850. 42:46context provider. So here simply add
  851. 42:49import
  852. 42:51curly braces from and provide the path
  853. 42:55that is dot /
  854. 42:58context/
  855. 43:00app context.
  856. 43:04Let's simply add the app context. It
  857. 43:06will work. And uh after that we'll add
  858. 43:09the app context provider tag here. And
  859. 43:13now we'll wrap our application using
  860. 43:15this app context provider. So after this
  861. 43:18browser router just provide this app
  862. 43:21context provider and this closing tag
  863. 43:24and within this mount the app. So now
  864. 43:28the application have the support of
  865. 43:30context. So we can access the context
  866. 43:33data in any part of this app.
  867. 43:36After adding this app context provider
  868. 43:39tag now we will open our layout. So in
  869. 43:43this layout we'll add the functionality
  870. 43:44so that it will display different layout
  871. 43:48for different user states. So let me
  872. 43:52just remove this function from here and
  873. 43:54here we will create a new function and
  874. 43:57export it. So just add export function o
  875. 44:00layout
  876. 44:02and in this o layout we need the data
  877. 44:05from the context. So just add const
  878. 44:10braces equal to
  879. 44:13use app context. Use app context has
  880. 44:16been imported here. And from this one we
  881. 44:19can get the user and with that we can
  882. 44:23also get the loading user.
  883. 44:27So we'll get both a state. We are not
  884. 44:29getting the suggestion here because we
  885. 44:31have not provided it in the
  886. 44:34value. So just open the context file
  887. 44:36again that is app context dot jsx and uh
  888. 44:40we have to pass our context here in the
  889. 44:44value object right. So in this value
  890. 44:46object simply add
  891. 44:50user
  892. 44:53loading user save the changes. After
  893. 44:56that open the layout. Now if I type
  894. 45:00something we will get the suggestion.
  895. 45:04So we already have this user and loading
  896. 45:08user from context. Now after that
  897. 45:12let's add the if statement. If
  898. 45:16loading user is
  899. 45:18true. In this case we'll add the return
  900. 45:20and we'll return the loading component
  901. 45:22that we have just created. So just add
  902. 45:24the loading component here and close
  903. 45:26this tag.
  904. 45:28After that
  905. 45:31let's add another if statement. If not
  906. 45:34of user
  907. 45:38in this case just add the return and
  908. 45:42provide the
  909. 45:45navigation or navigate tag. Let's add
  910. 45:48navigate
  911. 45:53and import this navigate from react
  912. 45:56router DOM. Now in this navigate we can
  913. 45:59use the two and provide the path.
  914. 46:03So just add the path / login.
  915. 46:07Then we'll add replace.
  916. 46:11That's it. And after that we will
  917. 46:14provide return
  918. 46:16and in this return just add outlet.
  919. 46:22Now let's duplicate this function.
  920. 46:25Here we'll add the function name that is
  921. 46:27guest layout. For the guest layout again
  922. 46:31we'll get the user and loading user from
  923. 46:34context and we'll add if statement. If
  924. 46:37loading user is true, then it will
  925. 46:40display the loading component. And if
  926. 46:42the user is true, it means when the user
  927. 46:44is logged in, then we'll add the return.
  928. 46:48And uh after that, we'll add navigate to
  929. 46:52homepage.
  930. 46:55Save the changes.
  931. 47:01So in this one, we have created the o
  932. 47:03layout and guest layout. It means this
  933. 47:06layout will be displayed when the user
  934. 47:08is authenticated and still if the user
  935. 47:11does not exist then it will redirect
  936. 47:14them to the login page. This guest
  937. 47:16layout will open the
  938. 47:20login or registration page using this
  939. 47:22outlet. But if the user is already
  940. 47:26logged in then it will redirect them on
  941. 47:28the slash or homepage. Right. After
  942. 47:31creating it, we will open our main file
  943. 47:33that is app.jsx where we have created
  944. 47:36the
  945. 47:38routes. So in this one
  946. 47:43you can see we have added the layout. So
  947. 47:45instead of this layout we need the guest
  948. 47:49and o layout. We will update this one.
  949. 47:54So
  950. 47:56let me rename it
  951. 47:59here. We will add
  952. 48:01guest layout and import this guest
  953. 48:04layout from here. Just add curly braces
  954. 48:07guest layout from the pages/ layout.
  955. 48:11See this import statement
  956. 48:15and uh similarly we'll create the other
  957. 48:17routes here. So just copy this one paste
  958. 48:23it here. We will add the command that is
  959. 48:25protected routes. In this protected
  960. 48:28routes, we will use the
  961. 48:31O layout and uh import this O layout
  962. 48:35from the layout.
  963. 48:38See this importter statement we are
  964. 48:40importing the guest layout o layout from
  965. 48:42the pages/ layout and here we have added
  966. 48:45o layout and in this one we'll add the
  967. 48:48first route that will be for homepage.
  968. 48:51So just add slash and here we'll add the
  969. 48:54element and in this element
  970. 48:57let me provide
  971. 49:02homepage. Import this homepage.
  972. 49:05After that here we have the next route.
  973. 49:07So just clear it. Copy this one only.
  974. 49:11Paste it here. We will add the path. It
  975. 49:13will be /builder
  976. 49:15slash and provide the project ID using /
  977. 49:20id.
  978. 49:22Here we'll add the builder page and
  979. 49:27import the builder page. Now duplicate
  980. 49:30it. In the next one we'll add the
  981. 49:32preview. So just add preview/ colon id.
  982. 49:36And here we'll mount the preview page.
  983. 49:39Just import the preview page. Save the
  984. 49:41changes.
  985. 49:42After adding it,
  986. 49:45let me open the web page.
  987. 49:48Let's refresh it.
  988. 49:51So you can see it is displaying the
  989. 49:53loading animation because the user
  990. 49:55loading is true. If I come back to the
  991. 49:59context,
  992. 50:01let's open the context file. In this
  993. 50:05one, you can see we have added loading
  994. 50:07user true. So when the loading user is
  995. 50:09true, it will display the loading
  996. 50:11animation. Now here if I change it, if I
  997. 50:15make it false
  998. 50:18and the user is null in this case, if I
  999. 50:21come back to the web page, you can see
  1000. 50:23it is displaying the O page. It means in
  1001. 50:26this O page, we can display either login
  1002. 50:29or registration page. And it is
  1003. 50:33redirecting us on this / login. Let me
  1004. 50:36remove it and go to homepage. You can
  1005. 50:39see it is automatically redirecting us
  1006. 50:41on the login page. Right? We cannot open
  1007. 50:44the homepage. Let's try it. And you can
  1008. 50:47see we are redirected to login page. Now
  1009. 50:50just come back and instead of making it
  1010. 50:52false, let's make it true. By default,
  1011. 50:55it will be true. And here we'll make or
  1012. 50:58create a function
  1013. 51:01that will check the user state.
  1014. 51:04So
  1015. 51:06here only we will add
  1016. 51:09o actions
  1017. 51:11and provide const check session
  1018. 51:16equal to asynchronous add function
  1019. 51:22and uh in this function we will add the
  1020. 51:24try catch statement.
  1021. 51:27Now in this try block we will make the
  1022. 51:30API call. So simply add con data equal
  1023. 51:34to await and here we will use the API.
  1024. 51:40So let's add the API and uh we have to
  1025. 51:43import it. So simply open the API
  1026. 51:47dojs. Here you can see we have added the
  1027. 51:49axios. AOS is imported and we have
  1028. 51:52created the AIOS instance called API.
  1029. 51:56Right? So we will use this here.
  1030. 52:02Let's come back in the context and now
  1031. 52:06if I type API you can see we are getting
  1032. 52:08the suggestion to import it. Let's click
  1033. 52:10on this suggestion and you can see API
  1034. 52:13is imported from dot dot/ API folder/
  1035. 52:16API file. Right now here we will use the
  1036. 52:21method.get
  1037. 52:23and provide the path. So the path will
  1038. 52:26be / API slash O
  1039. 52:31slash me. Save the changes. Now after
  1040. 52:35that it will return some data. So just
  1041. 52:38use set user and provide the data dot
  1042. 52:44user.
  1043. 52:47After that here we'll add the
  1044. 52:50set user in the catch block that will be
  1045. 52:53null.
  1046. 52:55Now after that we'll add the finally and
  1047. 52:57in this finally we will set loading user
  1048. 53:03and let's add false. So it will set the
  1049. 53:07loading user false. Now after that we
  1050. 53:10have to add the use effect to execute
  1051. 53:12this function. So just add
  1052. 53:16use effect. In this use effect create
  1053. 53:18the arrow function and provide the
  1054. 53:21dependency array. In this dependency add
  1055. 53:24a just add
  1056. 53:27check session
  1057. 53:30and uh after that we'll add the check
  1058. 53:33session function here.
  1059. 53:36Simply call this function.
  1060. 53:39Now save the changes and open the web
  1061. 53:42page.
  1062. 53:43So you can see it is opening the
  1063. 53:45homepage because it is returning some
  1064. 53:47user data. Let's come here in the API.
  1065. 53:51You can see this will return one user
  1066. 53:54data that's why it is displaying this
  1067. 53:57homepage
  1068. 53:59correct.
  1069. 54:01Now we have to design our login page.
  1070. 54:03For that first we will see the o page.
  1071. 54:06So let's come here in the function that
  1072. 54:09is check session function. So in this
  1073. 54:13one you can see we are using this setter
  1074. 54:15function set user. So just comment this
  1075. 54:17one. If I comment it, it will not set
  1076. 54:20the user. We'll come back here. Let's
  1077. 54:23refresh it. You can see if I try to open
  1078. 54:25the homepage, it is opening / login. And
  1079. 54:28this is the O page. So now let's start
  1080. 54:30designing our O page for user login and
  1081. 54:34registration.
  1082. 54:36But before we create our login and
  1083. 54:39registration form, let me commit these
  1084. 54:42changes on GitHub and review our code
  1085. 54:45that we have written till now. We have
  1086. 54:47created the folder structure. We have
  1087. 54:49created the pages and set up the routes.
  1088. 54:52Right? So let's come back to the VS
  1089. 54:54code. And here we will commit the
  1090. 54:55changes. Let's click on this source
  1091. 54:58control icon. And here we'll add the
  1092. 54:59message
  1093. 55:02created
  1094. 55:04created pages and routes.
  1095. 55:08So it will commit the changes in
  1096. 55:11development branch.
  1097. 55:14That's it. After that we'll come back to
  1098. 55:15the VS code.
  1099. 55:18Let's come here on this repository.
  1100. 55:22Here you can see this button compared
  1101. 55:24and pull request.
  1102. 55:30After that we'll click on this button
  1103. 55:32create pull request.
  1104. 55:36So we have created a new pull request
  1105. 55:38and once we create the pull request. The
  1106. 55:41code rabbit will start analyzing our
  1107. 55:44code. You can see the code rabbit is
  1108. 55:46running.
  1109. 55:50So it is analyzing the code and after
  1110. 55:52analyzing our code it will suggest the
  1111. 55:55bug fixes if there is any bug and it
  1112. 55:57will also suggest the improvements and
  1113. 55:59it will also generate the detailed
  1114. 56:01review summary.
  1115. 56:05It is still running.
  1116. 56:07Now you can see all checks have passed.
  1117. 56:10It means the code rabbit has reviewed
  1118. 56:12our code. And here we have the complete
  1119. 56:14details of this code review. Here we
  1120. 56:17have the review summary. And after that
  1121. 56:21you can see the details of each files.
  1122. 56:24So in this first file you can see it is
  1123. 56:27suggesting
  1124. 56:28add a fallback route for unmatched URLs.
  1125. 56:33Right. And for this one here we have the
  1126. 56:36prompt also. So we can simply add this
  1127. 56:39prompt if we are using the web coding
  1128. 56:41and it will add this fallback route.
  1129. 56:45Correct. Or we can go to the next one.
  1130. 56:49Here you can see here also we have some
  1131. 56:51suggestion that is
  1132. 56:54add ro status in the loading component.
  1133. 56:58And for this one here we have the prompt
  1134. 57:01that we can use to implement this
  1135. 57:03changes. And here we have the proposed
  1136. 57:06fix also. So in this one it is also
  1137. 57:09providing the exact code that we can
  1138. 57:11manually add in our code file to fix
  1139. 57:14this one. Right? Similarly we have the
  1140. 57:18suggestion and fix for each file. And we
  1141. 57:22can see these changes and suggestions in
  1142. 57:25the organized way using this review
  1143. 57:28change stack. Just click on this button
  1144. 57:30review change stack
  1145. 57:32and it will open the code rabbit
  1146. 57:34platform where you can see the entire
  1147. 57:38summary and the each suggestions and bug
  1148. 57:41fix. So it will open the code rabbit UI
  1149. 57:45where you can see the files like this.
  1150. 57:49And let's come here in the layers and
  1151. 57:51we'll click on this one. So here we have
  1152. 57:54the files where we have added some
  1153. 57:57changes. And if I open the right
  1154. 57:59sidebar, it is also providing the
  1155. 58:01details about this review for each file.
  1156. 58:06Let's open the next one. And in the
  1157. 58:09right side, you can see the details.
  1158. 58:11After that, let me open the first one.
  1159. 58:15If we open this file here, you can see
  1160. 58:18we have the proposed fix that we have to
  1161. 58:21remove this command. So we have
  1162. 58:23intentionally added this comment. We
  1163. 58:25will keep it to display our o page and
  1164. 58:29later we will remove this. So just skip
  1165. 58:32this one. I'll come to the second
  1166. 58:35suggestion.
  1167. 58:36So here we have the suggestion
  1168. 58:40stability and availability.
  1169. 58:43So we have to update our check session
  1170. 58:45in this one. So here it is suggesting to
  1171. 58:49move it inside the use effect or wrap it
  1172. 58:51using use call back. And for this one we
  1173. 58:55can use this prompt to update this
  1174. 58:57changes or we can manually add it in our
  1175. 59:00code. Now let's see the next suggestion.
  1176. 59:07Let me open the route configuration. And
  1177. 59:10in this route configuration, it is
  1178. 59:12suggesting to add a fallback route. And
  1179. 59:14here we have the
  1180. 59:17option to update it using the AI.
  1181. 59:21Correct? And we can manually add it in
  1182. 59:24our code also. To implement this
  1183. 59:27fallback route, we'll come back to the
  1184. 59:28VS code and open our app. JSX.
  1185. 59:33And here let me add one comment that is
  1186. 59:37catch all.
  1187. 59:40And in this catch all just add one
  1188. 59:43route. So let me just copy this one.
  1189. 59:45Paste it here. Here we'll provide path.
  1190. 59:49So in this path simply add star
  1191. 59:52and after that we have the element. In
  1192. 59:54this element we will use the navigate.
  1193. 59:58So let me remove it and provide navigate
  1194. 1:00:03and import the navigate from react
  1195. 1:00:05router DOM. In this navigate we'll add
  1196. 1:00:08the path using this two property. In
  1197. 1:00:11this two property simply add slash and
  1198. 1:00:13then we'll add the replace.
  1199. 1:00:16So when we will open any unregistered
  1200. 1:00:19route it will open the homepage.
  1201. 1:00:22After that let's come back here.
  1202. 1:00:26So you can see all the suggestions here
  1203. 1:00:29one by one and you can go to overview.
  1204. 1:00:32In this overview let's click on this see
  1205. 1:00:36pull request description.
  1206. 1:00:40After that see the walk through like
  1207. 1:00:43this
  1208. 1:00:44and uh after that in the right side you
  1209. 1:00:47can see we have the agent. So in this
  1210. 1:00:50agent we can write our prompt to ask any
  1211. 1:00:54question about this pull request. So in
  1212. 1:00:57this pull request we have created the
  1213. 1:00:59context. So let me add one question
  1214. 1:01:01about the context.
  1215. 1:01:04Is the context implemented properly?
  1216. 1:01:07Send.
  1217. 1:01:10So here we have the response using the
  1218. 1:01:12agent and here we have the response in
  1219. 1:01:16different steps. So first it is
  1220. 1:01:18suggesting for comment out this code
  1221. 1:01:22that is set user right and after that it
  1222. 1:01:25is suggesting for the use call back and
  1223. 1:01:28uh in the third one it is saying we are
  1224. 1:01:32not exposing this set user. So we cannot
  1225. 1:01:35use it in other files.
  1226. 1:01:38And here we have one minor issue about
  1227. 1:01:40the network error that we will fix after
  1228. 1:01:43building the back end and integrating
  1229. 1:01:45the back end. Right? So this was the
  1230. 1:01:47entire overview of the code review by
  1231. 1:01:50code rabbit. And uh after the code
  1232. 1:01:52review, we can merge the changes in the
  1233. 1:01:55main branch. So let me just come back to
  1234. 1:01:58the GitHub repo. Before we come back to
  1235. 1:02:02the GitHub repo, let me implement one
  1236. 1:02:04changes also. And uh it will be here in
  1237. 1:02:07the session context. And uh let's scroll
  1238. 1:02:11down. So you can see we have one
  1239. 1:02:13suggestion for this loading component.
  1240. 1:02:15Right? In this one we have to add the
  1241. 1:02:18role status. So here we have proposed
  1242. 1:02:21fix. Just open it and copy this code.
  1243. 1:02:23Let me just come back to the VS code and
  1244. 1:02:26open the loading jsx. And here we will
  1245. 1:02:31paste this code.
  1246. 1:02:33And we will add this one here.
  1247. 1:02:40And let's remove this div.
  1248. 1:02:44That's it. Now after that we will come
  1249. 1:02:47back here and click on this link to come
  1250. 1:02:49back to the repository.
  1251. 1:02:53And here we'll click on this button
  1252. 1:02:56merge pull request.
  1253. 1:02:58Confirm merge.
  1254. 1:03:00That's it. Let's come here in the main
  1255. 1:03:04repository.
  1256. 1:03:06So we have added the changes in the main
  1257. 1:03:08branch. After that we'll come back to
  1258. 1:03:09the VS code and uh click on this
  1259. 1:03:14three dot then
  1260. 1:03:16pull. So it will pull the latest
  1261. 1:03:18changes.
  1262. 1:03:21That's it. Now after that we will start
  1263. 1:03:25designing our login and registration
  1264. 1:03:29form. For that here we have the
  1265. 1:03:32authage.jsx.
  1266. 1:03:34So just open this O page dot JSX file.
  1267. 1:03:39In this O page first we'll dstructure
  1268. 1:03:43the props. We'll add curly braces and
  1269. 1:03:45here we'll get the mode from the props.
  1270. 1:03:48After that here we have the return
  1271. 1:03:50statement. So in this return statement
  1272. 1:03:53we will add a div.
  1273. 1:03:55And in this div we'll add some Telvin
  1274. 1:03:58classes. So just add the class name
  1275. 1:04:00property and provided these classes and
  1276. 1:04:03then we'll add the comment for the left
  1277. 1:04:05and right side. So here just add the
  1278. 1:04:07comment that is left panel that is for
  1279. 1:04:10branding and then we'll add the right
  1280. 1:04:12panel and in the right panel we'll add a
  1281. 1:04:15form. Correct? Now after that here we'll
  1282. 1:04:18add the mode also whether the mode is
  1283. 1:04:22login or register. So here let's create
  1284. 1:04:25one variable. We will add cost is login
  1285. 1:04:30is login equal to we will use this mode
  1286. 1:04:34equal to we will add this comparison
  1287. 1:04:37login. So if the mode is equal to login
  1288. 1:04:40then it will be true else it will be
  1289. 1:04:42false. Correct? Now after that in this
  1290. 1:04:46left panel we have to display the
  1291. 1:04:48branding. For that we'll create a
  1292. 1:04:50separate component. So
  1293. 1:04:53let me open the sidebar and in this
  1294. 1:04:56components create a new file login dot
  1295. 1:05:00jsx.
  1296. 1:05:02Here we'll add rafce for creating the
  1297. 1:05:05component structure and uh after that
  1298. 1:05:08here you can see we have a div. So in
  1299. 1:05:11this div we'll add some classes just
  1300. 1:05:13provide these tin classes and in this
  1301. 1:05:16one you can see we have added the
  1302. 1:05:18background. in the background we have
  1303. 1:05:20added the URL and /bg image.png that is
  1304. 1:05:25available in our public folder. Now
  1305. 1:05:28after that within this div we have to
  1306. 1:05:31add the first div.
  1307. 1:05:34So here we have to add one brand logo
  1308. 1:05:37and the text and after that we'll add
  1309. 1:05:40the second div. So in this second div we
  1310. 1:05:44have to add some text and uh let's add
  1311. 1:05:49the brand logo in the first one. In this
  1312. 1:05:52first div we'll add the img and in this
  1313. 1:05:54image src we will add / logo. SVG
  1314. 1:05:58because it is available in our public
  1315. 1:06:00folder. Then in this alt tag we'll add
  1316. 1:06:03the logo. Then we have to add the size.
  1317. 1:06:07So just add the class name size 9.5.
  1318. 1:06:10Then we have to add one text in a span
  1319. 1:06:12tags. So the text is builder AI. After
  1320. 1:06:16that we'll add the class name. So in
  1321. 1:06:18this class name let's provide text for
  1322. 1:06:21Excel font medium and text white.
  1323. 1:06:26Now after that here we'll come to the
  1324. 1:06:28second div. So in this second div we'll
  1325. 1:06:30add the text in H2 tag. So the text is
  1326. 1:06:34build your presence on web.
  1327. 1:06:39Then we have to add the text in P tag.
  1328. 1:06:41So just add one P tag here. And in this
  1329. 1:06:44P we'll add one small description like
  1330. 1:06:48this. After that we'll add the another P
  1331. 1:06:52tag.
  1332. 1:06:53And here we have to add the text like
  1333. 1:06:55copyright. And then we have to add
  1334. 1:06:59the year. So we'll add curly braces new
  1335. 1:07:03date dot get full year. After that we'll
  1336. 1:07:09add the builder AI. So we have added the
  1337. 1:07:12copyright message. Now we'll add the
  1338. 1:07:14classes for this copyright message. So
  1339. 1:07:17we'll add the class name property and
  1340. 1:07:19provided these classes. Then we'll add
  1341. 1:07:21the classes for the another P tag which
  1342. 1:07:24is here. So provide the class name here.
  1343. 1:07:29And now we'll add the classes in the
  1344. 1:07:31text that is written in H2.
  1345. 1:07:37Now we have added the logo
  1346. 1:07:41then website title and other
  1347. 1:07:43description. After that we have to mount
  1348. 1:07:45this component. So we'll open the o page
  1349. 1:07:49and here let's mount this left panel. So
  1350. 1:07:53let's add the opening arrow left panel
  1351. 1:07:57or login left and import it from the
  1352. 1:08:00components. Save the changes. Close this
  1353. 1:08:02tag. Now let me open the web page and
  1354. 1:08:06here you can see on this / login path in
  1355. 1:08:10the left side we are getting the logo
  1356. 1:08:13icon text and some description at the
  1357. 1:08:15bottom and copyright message. Let's
  1358. 1:08:18align the icon and text side by side.
  1359. 1:08:21For that let me just come back here.
  1360. 1:08:25You can see here we have created the div
  1361. 1:08:29that contains the icon and text. So for
  1362. 1:08:31this div we have to add the flex layout.
  1363. 1:08:34So simply add class name flex item
  1364. 1:08:37center gap 3. Save the changes and you
  1365. 1:08:39can see it is aligned side by side. So
  1366. 1:08:42we have created the left side of the
  1367. 1:08:45authentication page and in the right
  1368. 1:08:47side we have to create the form. For
  1369. 1:08:50that we'll come back to the VS code.
  1370. 1:08:52Open
  1371. 1:08:54page.jsx.
  1372. 1:08:56Come here after this commandment that is
  1373. 1:08:58right panel
  1374. 1:09:00and uh here just create a div and in
  1375. 1:09:04this one we will use the flex one so
  1376. 1:09:07that it will use the entire space
  1377. 1:09:09available in the row and flex item
  1378. 1:09:11center justify center and padding. After
  1379. 1:09:15that we'll add one more div here.
  1380. 1:09:19So create a div.
  1381. 1:09:21Here we'll add the width full and then
  1382. 1:09:23we'll add the maximum width. So the
  1383. 1:09:26maximum width it will be small.
  1384. 1:09:30Now in this one create a div that will
  1385. 1:09:34contain our title right. So the title
  1386. 1:09:38will be sign in or create an account and
  1387. 1:09:42according to the title we will update
  1388. 1:09:43the description also. So in this div we
  1389. 1:09:47will add the classes
  1390. 1:09:50that is margin bottom and after that we
  1391. 1:09:54have to add the title in H1 tag. So
  1392. 1:09:58let's add curly braces
  1393. 1:10:00and use this is login
  1394. 1:10:03variable. If it is true in this case
  1395. 1:10:06we'll add the title called sign in. And
  1396. 1:10:10if it is false in this case we will
  1397. 1:10:13update the title. It should be create an
  1398. 1:10:16account
  1399. 1:10:19correct. Now we'll add the classes for
  1400. 1:10:23this title which is in H1 tag. So
  1401. 1:10:26provided this classes also. Now after
  1402. 1:10:30that we have to add the description in P
  1403. 1:10:32tag. Now in this P tag again use the
  1404. 1:10:36same turnary operator. Just copy and
  1405. 1:10:38paste it here. If is login is true. In
  1406. 1:10:41this case, we have to add the message
  1407. 1:10:44like this. And if it is false, we'll add
  1408. 1:10:47the another message for user
  1409. 1:10:50registration
  1410. 1:10:51like this.
  1411. 1:10:54After that provide the classes for this
  1412. 1:10:56description also. So in this P we'll add
  1413. 1:11:00class name and provide text small and
  1414. 1:11:02text color it will be zinc 400.
  1415. 1:11:06Right? Now after that here we have to
  1416. 1:11:09add one message if any error occurs. For
  1417. 1:11:13that first we have to create the state.
  1418. 1:11:16So let's scroll up and uh here we'll add
  1419. 1:11:20const
  1420. 1:11:24error and the setter function name is
  1421. 1:11:26set error equal to
  1422. 1:11:32use a state and initialize it using
  1423. 1:11:35empty string.
  1424. 1:11:37With that we'll add one more state. So
  1425. 1:11:40let me just duplicate it. And here we'll
  1426. 1:11:43add loading. And the setter function
  1427. 1:11:45name is set loading. And by default it
  1428. 1:11:48will be false. Just add the false here.
  1429. 1:11:52Now let's come here.
  1430. 1:11:54So here simply add curly braces
  1431. 1:12:00error. If the error is true in this case
  1432. 1:12:05we will add the div.
  1433. 1:12:09And within this div
  1434. 1:12:12we will simply provide this
  1435. 1:12:15error. And for this one provide some
  1436. 1:12:19Telvin classes also using the class name
  1437. 1:12:21property. Let's save the changes. And
  1438. 1:12:24just after this error we can display our
  1439. 1:12:27form. So just add the form tag here
  1440. 1:12:31like this. Let's save the changes and
  1441. 1:12:33review the changes. So you can see here
  1442. 1:12:35we have the title sign in and here we
  1443. 1:12:37have the small description. Enter your
  1444. 1:12:40credentials to access your website
  1445. 1:12:42builder. Now let me change the mode.
  1446. 1:12:47So if I make it like this not of login
  1447. 1:12:52save the changes and you can see here we
  1448. 1:12:54have create an account and get started
  1449. 1:12:56by entering your registration details.
  1450. 1:12:59Right. Let's come back and change it to
  1451. 1:13:03mode equal to login.
  1452. 1:13:06Save the changes.
  1453. 1:13:08Let's come here. And we can also change
  1454. 1:13:11it by updating the route. If I change
  1455. 1:13:14the route, it is login. So let's add
  1456. 1:13:16register.
  1457. 1:13:19You can see the message create an
  1458. 1:13:21account. And if I change the route to
  1459. 1:13:24login,
  1460. 1:13:25it is displaying sign in. It works. Now
  1461. 1:13:28after that we have to design our form.
  1462. 1:13:31So we will come back here. Let's come
  1463. 1:13:34here. So you can see here we have to add
  1464. 1:13:36our form. But before adding this form
  1465. 1:13:39let's come here.
  1466. 1:13:42Just after this form here we will add
  1467. 1:13:44some message. So we'll add the P tag.
  1468. 1:13:48And in this P tag we'll use the turnary
  1469. 1:13:50operator. Use is login. If is login is
  1470. 1:13:54true then we'll add this parenthesis and
  1471. 1:13:59add the
  1472. 1:14:01fragment
  1473. 1:14:02right and if it is false then we'll add
  1474. 1:14:06colon and another parenthesis and here
  1475. 1:14:10also we'll add this fragment
  1476. 1:14:14like this. Now in the first one we'll
  1477. 1:14:16add the text called new to builder.
  1478. 1:14:22Then we'll add kibs and provide the
  1479. 1:14:24space and after that we have to add a
  1480. 1:14:27link that will change the route. So just
  1481. 1:14:30add the
  1482. 1:14:33link tag from react router DOM.
  1483. 1:14:37Add the link opening and closing tag.
  1484. 1:14:39And in this link we'll add the message
  1485. 1:14:42called create an account. For this link
  1486. 1:14:44we have to add the two property that is
  1487. 1:14:46/register. So it will change the route
  1488. 1:14:48to register. And after that we have to
  1489. 1:14:50add the classes. So we have added these
  1490. 1:14:53classes here.
  1491. 1:14:56That's it. Now after that let me just
  1492. 1:14:58copy everything from here. Copy and
  1493. 1:15:01paste it here in the second one.
  1494. 1:15:04Here we will change the message. So it
  1495. 1:15:06is already have an account.
  1496. 1:15:11Then we'll change the path to login. And
  1497. 1:15:14we'll change the message also. So the
  1498. 1:15:16message is sign in here. Let's save the
  1499. 1:15:20changes and come here. So you can see
  1500. 1:15:22here we have a text new to builder
  1501. 1:15:24create an account. If I click on this
  1502. 1:15:26create an account, you can see create an
  1503. 1:15:28account. If I click on sign in here, you
  1504. 1:15:30can see sign in. It works. It is
  1505. 1:15:33changing the route. Now let me design
  1506. 1:15:35our form. So
  1507. 1:15:39I'll come back to the VS code
  1508. 1:15:43and uh come here in the form. Now in
  1509. 1:15:46this form we have the action. So simply
  1510. 1:15:48remove this action and uh in this one we
  1511. 1:15:52will provide the class name property and
  1512. 1:15:55provide the space y6.
  1513. 1:15:59Now within this form again use the
  1514. 1:16:01turnary operator not of is login
  1515. 1:16:06and in this case we will get the user's
  1516. 1:16:10name also right we will get the user's
  1517. 1:16:12name and if the state is login then we
  1518. 1:16:15don't need the name input field and to
  1519. 1:16:18store the name email and password we
  1520. 1:16:20have to create the state also. So first
  1521. 1:16:23we'll create those states. So scroll up
  1522. 1:16:26and here let's add the state called name
  1523. 1:16:31setter function name is set name and
  1524. 1:16:33initialize it using empty string. Then
  1525. 1:16:36we'll add the
  1526. 1:16:38email set email and initialize it using
  1527. 1:16:41empty string. Then we'll add the
  1528. 1:16:44password set password and initialize it
  1529. 1:16:47using empty string. And after that we'll
  1530. 1:16:50add the toggle option to display or hide
  1531. 1:16:53the password. So here we'll add so
  1532. 1:16:54password and set so password by default
  1533. 1:16:56it will be false. Right? Now after that
  1534. 1:17:00let's come here
  1535. 1:17:03and uh in this one we will add one div.
  1536. 1:17:11In this div we'll add the label tag. In
  1537. 1:17:14the label tag we'll add the text called
  1538. 1:17:16full name. After that for this label we
  1539. 1:17:19have to provide some classes. So we have
  1540. 1:17:21added these classes also. Then we have
  1541. 1:17:23to add the input after this label. So
  1542. 1:17:26we'll add the input. Type is text. After
  1543. 1:17:29this type, we'll add the value. So let's
  1544. 1:17:33add the value and the value will be name
  1545. 1:17:36state. Then we have to add on change. So
  1546. 1:17:40in this onchange create the add a
  1547. 1:17:42function and get the event in the
  1548. 1:17:44parameter and after that it will call
  1549. 1:17:47the setter function set name and provide
  1550. 1:17:51e.target. target dot value. So when we
  1551. 1:17:55will make the changes in this input
  1552. 1:17:57field, the data will get saved in the
  1553. 1:18:00name state. After that we'll add the
  1554. 1:18:03required property. So this input field
  1555. 1:18:06will be required to submit the form.
  1556. 1:18:08Then we'll add the class name. And here
  1557. 1:18:11we have to add these classes. And at the
  1558. 1:18:16end we'll add the placeholder also. So
  1559. 1:18:18let's add the placeholder. And in this
  1560. 1:18:20placeholder, let me add any dummy user's
  1561. 1:18:23name. So we'll add this dummy name. Save
  1562. 1:18:26the changes. And after that, let's come
  1563. 1:18:28here. So now you can see here we have
  1564. 1:18:30the text full name. And here we have the
  1565. 1:18:33input field. If I click on sign in here,
  1566. 1:18:36it will be removed. And if I go to
  1567. 1:18:38create an account and here it is asking
  1568. 1:18:40for the full name. It looks good. Now
  1569. 1:18:44let's come back and uh after that we'll
  1570. 1:18:47add the next input field. For that let's
  1571. 1:18:50simply copy this div
  1572. 1:18:53and paste it here.
  1573. 1:18:55Now in this div we will update the text.
  1574. 1:19:00So the text will be email address
  1575. 1:19:03right and uh after that we have the same
  1576. 1:19:07label tag here
  1577. 1:19:10and after that we have the input. So in
  1578. 1:19:12this input we'll add the type. Type will
  1579. 1:19:14be email.
  1580. 1:19:18Then we have to add the value. So the
  1581. 1:19:20value should be email.
  1582. 1:19:24Then we have the onchange. In this
  1583. 1:19:27onchange we'll use the set email. It
  1584. 1:19:30will be e.target dot value. Required
  1585. 1:19:33will be true. And then classes. So here
  1586. 1:19:36again we are using the same classes.
  1587. 1:19:41And after that we have to add the
  1588. 1:19:42placeholder. So in the placeholder we
  1589. 1:19:45will add the dummy email. So we have
  1590. 1:19:47added this dummy email here. In the
  1591. 1:19:50placeholder similarly we will add the
  1592. 1:19:53next input field. So just copy this div
  1593. 1:19:55paste it here. In this one we will add
  1594. 1:19:58the text called password. Label text is
  1595. 1:20:00password. Then we will add the type. So
  1596. 1:20:04in this type we will use the curly
  1597. 1:20:06braces
  1598. 1:20:08and use the
  1599. 1:20:10so password. If the so password is true
  1600. 1:20:14in this case we'll add the text
  1601. 1:20:17and if it is false we will add the type
  1602. 1:20:21password.
  1603. 1:20:24Now we'll add the value. So the value
  1604. 1:20:26will be password and uh here we will use
  1605. 1:20:28the setter function set password.
  1606. 1:20:32It will be e.target dot value required
  1607. 1:20:35true. Then we will update the telvin
  1608. 1:20:38classes here. And at the end we have the
  1609. 1:20:41placeholder. So in this placeholder we
  1610. 1:20:43will add the dots like this.
  1611. 1:20:48And uh after that
  1612. 1:20:52within this div only here we will add
  1613. 1:20:56one button so that we can toggle the
  1614. 1:20:58password visibility. But before that
  1615. 1:21:02let's wrap this input field inside a
  1616. 1:21:04div. So after this label create a div.
  1617. 1:21:08In this div just add the class name and
  1618. 1:21:11provide relative.
  1619. 1:21:14And within this we will move this input
  1620. 1:21:17and just after this input we will create
  1621. 1:21:20a button.
  1622. 1:21:24Now the button type will be button.
  1623. 1:21:28After that we'll add the on click.
  1624. 1:21:31In this on click add the add a function
  1625. 1:21:34and let's add set so password and simply
  1626. 1:21:40add not of
  1627. 1:21:42so password.
  1628. 1:21:44So it will toggle it and uh after that
  1629. 1:21:48we have to add some classes for this
  1630. 1:21:50button. So we have provided these
  1631. 1:21:52classes and uh in this one we have to
  1632. 1:21:55add the icon. So just add curly braces
  1633. 1:21:58and use the so password state. If it is
  1634. 1:22:01true in this case we will add
  1635. 1:22:05I
  1636. 1:22:07of icon and import it from the lucid
  1637. 1:22:10react and provide the size 14
  1638. 1:22:14and if it is false in this case we'll
  1639. 1:22:16add the colon and provide
  1640. 1:22:20I icon and it is also imported from
  1641. 1:22:22lucid react and here also we'll add the
  1642. 1:22:25size 14.
  1643. 1:22:27Save the changes and open the web page.
  1644. 1:22:30So now you can see we have the name,
  1645. 1:22:32email and password. And let's type
  1646. 1:22:35something in this password.
  1647. 1:22:37So you can see it is displaying the
  1648. 1:22:39dots. If I click on this I icon, it will
  1649. 1:22:42display the exact text. Let's click on
  1650. 1:22:44this I icon again, it will hide it. So
  1651. 1:22:46we can toggle the password visibility.
  1652. 1:22:49Now after that, we have to add a submit
  1653. 1:22:51button. So just come back and uh
  1654. 1:22:55after this div.
  1655. 1:22:59So this div is for this one and here we
  1656. 1:23:02have another div for this entire
  1657. 1:23:05input field. So here just before this
  1658. 1:23:08closing form tag we will add a button.
  1659. 1:23:12Now in this button we have to add the
  1660. 1:23:14type. So button type will be submit.
  1661. 1:23:18Then we have to add the disabled
  1662. 1:23:20property. So when the loading is true,
  1663. 1:23:22it will be disabled. After that we have
  1664. 1:23:24to add the classes. So just add the
  1665. 1:23:27class name property and here we will add
  1666. 1:23:31these tin classes. Next we have to add
  1667. 1:23:34the button text. For that just add curly
  1668. 1:23:37braces.
  1669. 1:23:39Use the loading. If the loading is true
  1670. 1:23:42in this case we'll add the loader to
  1671. 1:23:46icon from Lucid React.
  1672. 1:23:50And for this icon we'll add the
  1673. 1:23:52animation using the class name that is
  1674. 1:23:54animate as pin height width and margin
  1675. 1:23:57right. And after that we'll add another
  1676. 1:23:59curly braces where we have to add the
  1677. 1:24:02text. So just add is login state. If it
  1678. 1:24:04is true in this case we'll add the
  1679. 1:24:07button text sign in and if it is false
  1680. 1:24:10we'll add colon and provide the button
  1681. 1:24:12text sign up. Save the changes and uh
  1682. 1:24:16after that we will open the web page. So
  1683. 1:24:18now you can see here we have the sign up
  1684. 1:24:20button. If I click on sign in, it will
  1685. 1:24:23change it to signin form using the email
  1686. 1:24:27and password and if I click on this
  1687. 1:24:29create an account, it will open the sign
  1688. 1:24:31up form with the name, email and
  1689. 1:24:33password.
  1690. 1:24:35So we have to add some space before this
  1691. 1:24:38message. So I'll come back here.
  1692. 1:24:41Here you can see we have this P. So in
  1693. 1:24:43this P
  1694. 1:24:45let me add the class name property and
  1695. 1:24:49provided these classes. Now we'll come
  1696. 1:24:52back here. So you can see it looks good.
  1697. 1:24:55Let's click here. It is changing the
  1698. 1:24:58form from sign in to sign up. And you
  1699. 1:25:00can see the button is also changing. It
  1700. 1:25:02is sign up button. If I click here, it
  1701. 1:25:04is opening the new form with button text
  1702. 1:25:07sign in.
  1703. 1:25:09Now we will add the functions also.
  1704. 1:25:11Using that we can submit this form. It
  1705. 1:25:13will either call the sign in or sign up
  1706. 1:25:16function. So just come back to the VS
  1707. 1:25:17code and we'll create these functions in
  1708. 1:25:20the context. So let's open the app
  1709. 1:25:23context. In the app context, we have
  1710. 1:25:27this use effect. So after this use
  1711. 1:25:29effect, let's create a function
  1712. 1:25:33and write the name login. So just at con
  1713. 1:25:37login equal to
  1714. 1:25:41ascaro function in this parameter we'll
  1715. 1:25:44get the email and we'll get the password
  1716. 1:25:47for login we need the email and password
  1717. 1:25:50and uh after that we'll add the try
  1718. 1:25:53catcher statement. Now in this try block
  1719. 1:25:55we'll make the API call or network
  1720. 1:25:58request. So just add con data equal to
  1721. 1:26:01await and use the API
  1722. 1:26:05dot post method and uh in this one
  1723. 1:26:09provide the path that is / API/
  1724. 1:26:12login
  1725. 1:26:16and after that we'll add comma and here
  1726. 1:26:18we have to provide the data that will be
  1727. 1:26:20email and password for login correct and
  1728. 1:26:24after this network request we'll get the
  1729. 1:26:26response. So use the set
  1730. 1:26:29user and in this set user just add the
  1731. 1:26:33data dot user.
  1732. 1:26:38After that we will display the toast
  1733. 1:26:39notification. So just add the toast. We
  1734. 1:26:42are not getting the suggestion here. So
  1735. 1:26:45let's import the toast first. Let's see
  1736. 1:26:48the our
  1737. 1:26:50package.json
  1738. 1:26:51and see React hot toast is added or not.
  1739. 1:26:55So it is already added react hot toast.
  1740. 1:26:58So simply add this import statement
  1741. 1:27:01import toast from react hot toast. And
  1742. 1:27:04after that let's type the
  1743. 1:27:08toast dot
  1744. 1:27:12success. In this toast dots success just
  1745. 1:27:16add the message that is welcome back.
  1746. 1:27:20And after that we have to navigate the
  1747. 1:27:22users on homepage. So just add the
  1748. 1:27:25navigate
  1749. 1:27:27and get this navigate from react router
  1750. 1:27:29DOM and simply provide slash that is for
  1751. 1:27:32the home.
  1752. 1:27:34Let me update this one. It is capital N.
  1753. 1:27:38So let's update it.
  1754. 1:27:42We will use the navigate function from
  1755. 1:27:45use navigate. Let's scroll up
  1756. 1:27:48and uh here let's add con
  1757. 1:27:53equal to
  1758. 1:27:55use navigate from react router DOM and
  1759. 1:27:59after that let's call it here
  1760. 1:28:02navigate and in this navigate simply
  1761. 1:28:05provide the path slash. Now after that
  1762. 1:28:08come here in the catch block here we'll
  1763. 1:28:10get the
  1764. 1:28:12error and uh let's simply add console
  1765. 1:28:15dot error. It will be login failed with
  1766. 1:28:18the error. Then we'll add con error
  1767. 1:28:22message equal to error dot response dot
  1768. 1:28:26error
  1769. 1:28:28or
  1770. 1:28:29we will add invalid email or password.
  1771. 1:28:33Then we have to add the toast
  1772. 1:28:35notification. So simply provide
  1773. 1:28:39toast dot error. It will be error
  1774. 1:28:41message. Then we have to add throw new
  1775. 1:28:44error and simply add the error object
  1776. 1:28:46with error message. Save the changes. So
  1777. 1:28:50we have created the login function.
  1778. 1:28:52Similarly we have to create the
  1779. 1:28:53registration function. So just copy this
  1780. 1:28:55one
  1781. 1:28:58and paste it here.
  1782. 1:29:00Update the function name. So the
  1783. 1:29:02function name will be register.
  1784. 1:29:05In this one we'll get the three
  1785. 1:29:07parameter that will be name, email and
  1786. 1:29:09password. So just add name, email and
  1787. 1:29:12password.
  1788. 1:29:14After that we have the try catch. In
  1789. 1:29:16this try block we'll make the API call
  1790. 1:29:18using API.post and provide /
  1791. 1:29:21API/register.
  1792. 1:29:23This is the endpoint. And here we'll add
  1793. 1:29:26the data that will be name, email and
  1794. 1:29:29password. After that we will use set
  1795. 1:29:32user. It will be data do user and then
  1796. 1:29:35we'll add the toast notification using
  1797. 1:29:37the toast dot success and the
  1798. 1:29:41notification message is account created
  1799. 1:29:43successfully and navigate to homepage
  1800. 1:29:46and if error occurs then we'll add
  1801. 1:29:48console error registration failed then
  1802. 1:29:52we'll add the error message here it is
  1803. 1:29:54also
  1804. 1:29:56registration failed then toast dot error
  1805. 1:29:59error message and throw new error that's
  1806. 1:30:01it so we have added the login and
  1807. 1:30:03registration function. After that we
  1808. 1:30:05have to
  1809. 1:30:07add these functions in the value so that
  1810. 1:30:10we can access it in any other file. So
  1811. 1:30:14let's come here in this
  1812. 1:30:17value we'll add comma and provide
  1813. 1:30:21login and
  1814. 1:30:24register. Save the changes and now come
  1815. 1:30:27here in the O page. In this o page,
  1816. 1:30:30let's get the login and registration
  1817. 1:30:32from the context. So here only we'll add
  1818. 1:30:37con curly braces equal to use context or
  1819. 1:30:42use app context. Use app context has
  1820. 1:30:44been imported. And from here we'll get
  1821. 1:30:46the login
  1822. 1:30:50and register.
  1823. 1:30:53After that here we will create a
  1824. 1:30:55function that is handle subummit that
  1825. 1:30:56will submit the
  1826. 1:30:59form. So just add con
  1827. 1:31:03handle submit equal to
  1828. 1:31:07async add function. In this function
  1829. 1:31:10parameter we'll get the event and uh
  1830. 1:31:13after that let's add e dot
  1831. 1:31:17prevent default.
  1832. 1:31:20After that we'll add set error and
  1833. 1:31:24provide the empty string. After that
  1834. 1:31:27we'll use set loading and uh provide
  1835. 1:31:31true.
  1836. 1:31:34After that just add the try catch. In
  1837. 1:31:37this try block we will check the mode.
  1838. 1:31:40If
  1839. 1:31:42the mode is equal to login.
  1840. 1:31:47If the mode is equal to login in this
  1841. 1:31:49case simply add await and call the login
  1842. 1:31:51function. In this login function simply
  1843. 1:31:54provide the email and password. After
  1844. 1:31:58that we'll add the else statement.
  1845. 1:32:01In this else statement we will add await
  1846. 1:32:05and call the register function. In this
  1847. 1:32:08register function we'll add the name,
  1848. 1:32:11email and password.
  1849. 1:32:16And then we'll add navigate. So let's
  1850. 1:32:20get the navigate here. In this one just
  1851. 1:32:24add const
  1852. 1:32:27navigate equal to
  1853. 1:32:30use navigate
  1854. 1:32:33and uh use navigate has been imported.
  1855. 1:32:36Correct? And simply provide this
  1856. 1:32:38navigate and in this one provide the
  1857. 1:32:41path slash that is homepage. Now after
  1858. 1:32:44that come here in the catch block. Here
  1859. 1:32:46we'll add error. And then we'll add set
  1860. 1:32:49error like this. Then we'll add the
  1861. 1:32:52finally block and in this finally block
  1862. 1:32:55we will use set loading and we will make
  1863. 1:32:58it false.
  1864. 1:33:00That's it. Save the changes and uh after
  1865. 1:33:04that we will come back here. But before
  1866. 1:33:06opening the application or web page, let
  1867. 1:33:09me connect this form
  1868. 1:33:12with the submit function. So here you
  1869. 1:33:14can see we have the form tag. So in this
  1870. 1:33:16form tag, let's add on submit. In this
  1871. 1:33:20onsubmit, simply add
  1872. 1:33:23handle submit function. Save the
  1873. 1:33:25changes. Come back here.
  1874. 1:33:27So now you can see here we have the
  1875. 1:33:30sign-in form and sign up form. And uh if
  1876. 1:33:34I add any details here,
  1877. 1:33:46click on sign up. You can see it is
  1878. 1:33:49opening the homepage.
  1879. 1:33:51Right? Right now we have the dummy API.
  1880. 1:33:54That's why it will not create an account
  1881. 1:33:56in the database. But it will redirect us
  1882. 1:33:59to the homepage after successful sign up
  1883. 1:34:02or login. So you can see now we are
  1884. 1:34:04redirected to the homepage. It works
  1885. 1:34:07fine. So we have completed our login and
  1886. 1:34:10registration form. After that let me
  1887. 1:34:12just come back here and in the context
  1888. 1:34:15you can see we have added the comment
  1889. 1:34:18in the check session. So just remove
  1890. 1:34:21this comment. We will uncomment this set
  1891. 1:34:23user.
  1892. 1:34:25So once the application gets loaded it
  1893. 1:34:28will check the session and call the API
  1894. 1:34:31and if the user data is available it
  1895. 1:34:33will set the user so that instead of
  1896. 1:34:36displaying the login page it will
  1897. 1:34:37directly open the homepage. Now let's
  1898. 1:34:40commit these changes and review our
  1899. 1:34:42code. So here we'll click on this source
  1900. 1:34:44control icon and we'll add the message
  1901. 1:34:54created user authentication form
  1902. 1:34:58commit changes
  1903. 1:35:00and sync changes.
  1904. 1:35:03So it will commit the changes in the
  1905. 1:35:05development branch. After that we'll
  1906. 1:35:07come to GitHub repo.
  1907. 1:35:10Let's go to development branch.
  1908. 1:35:13and click on this
  1909. 1:35:16open pull request
  1910. 1:35:20then create pull request.
  1911. 1:35:23So we have created a new pull request
  1912. 1:35:25and now the code rabbit will start
  1913. 1:35:28analyzing our pull request.
  1914. 1:35:32Now the code rabbit has reviewed our
  1915. 1:35:34code and here we have the review
  1916. 1:35:36summary. You can see somebody by code
  1917. 1:35:38rabbit and after that if I scroll down
  1918. 1:35:42you can see here we have review change
  1919. 1:35:45stack where we can see the details about
  1920. 1:35:48this review and let's scroll down and
  1921. 1:35:51see the
  1922. 1:35:53reviews here. So you can see it is
  1923. 1:35:55providing the suggestion for this file
  1924. 1:35:58that is appc context.jsx.
  1925. 1:36:00In this one we have one minor issue and
  1926. 1:36:03for this one we have this prompt using
  1927. 1:36:07that we can fix our issue using the AI
  1928. 1:36:09agents or we can manually fix it right.
  1929. 1:36:13So after that let's see the next one. So
  1930. 1:36:16we have another minor issue in this o
  1931. 1:36:19page jsx
  1932. 1:36:22and here we have two options. We can use
  1933. 1:36:25this AI prompt to fix the issue or we
  1934. 1:36:28can manually fix it using this code. So
  1935. 1:36:32it is basically adding this role in this
  1936. 1:36:36element here. It is adding the HTML 4
  1937. 1:36:39and ID for this input and label. So this
  1938. 1:36:43is the best practice to add the label
  1939. 1:36:45and role and you can manually add it and
  1940. 1:36:49the code rabbit is suggesting this best
  1941. 1:36:51practice. Now let's click on this one
  1942. 1:36:54review change tag. So this is the core
  1943. 1:36:57rabbit UI where you can see the details
  1944. 1:36:59review and you can interact with the
  1945. 1:37:02chat agent also. And in the right side
  1946. 1:37:05you will find all the details of each
  1947. 1:37:08line.
  1948. 1:37:10You can see here we have the details of
  1949. 1:37:11this line 32 to 66. Let's click here.
  1950. 1:37:17You can see the details for this 21 and
  1951. 1:37:2021.
  1952. 1:37:22So it is providing the feedback on each
  1953. 1:37:24line where we have to update the code
  1954. 1:37:27and uh after that here we have the
  1955. 1:37:30agent. We can ask anything from this
  1956. 1:37:32agent also.
  1957. 1:37:34So you can go through all these
  1958. 1:37:36suggestions and bug fix just implement
  1959. 1:37:39these changes in the code and after that
  1960. 1:37:42you can make a new commit right and uh
  1961. 1:37:47after that let me just come back here in
  1962. 1:37:50the pull request and I'll click on this
  1963. 1:37:53button merge pull request and confirm
  1964. 1:37:56merge that's it now we will come back to
  1965. 1:38:00the VS code and click on this three dot
  1966. 1:38:05and then let's click on this
  1967. 1:38:09pull. So it will pull the latest
  1968. 1:38:10changes. After that we have to add the
  1969. 1:38:14UI on our homepage. So you can see right
  1970. 1:38:17now we are on the homepage. So here we
  1971. 1:38:19have to add the graphics on the entire
  1972. 1:38:23screen and then we'll add the welcome
  1973. 1:38:26message and one input field and uh below
  1974. 1:38:29that we'll display the list of projects
  1975. 1:38:31that is already generated. So let's just
  1976. 1:38:34come back to the VS code. Here we will
  1977. 1:38:37open the pages folder. In this pages you
  1978. 1:38:41will find the
  1979. 1:38:44homepage.jsx.
  1980. 1:38:48Now in this one let's remove this text
  1981. 1:38:52and we'll add some classes for the first
  1982. 1:38:55div. So provide the class name property
  1983. 1:38:57and here we have to provide the screen
  1984. 1:39:01height then overflow
  1985. 1:39:04then we'll add the text color
  1986. 1:39:07and uh after that we have added the font
  1987. 1:39:11then background. In the background we
  1988. 1:39:14will add the URL and the image path.
  1989. 1:39:17Right. So let me add double quote here
  1990. 1:39:21[snorts]
  1991. 1:39:23because we have already added the single
  1992. 1:39:24quote here for this image that is bg
  1993. 1:39:27image dotpng
  1994. 1:39:30and uh after that we have provided the
  1995. 1:39:32background cover background center and
  1996. 1:39:35background no repeat. Now in this one we
  1997. 1:39:38have to create the navigation bar. So
  1998. 1:39:42let me provide the comment here that is
  1999. 1:39:44nav and here we will use the nav tag.
  2000. 1:39:48Now in this nav tag we have to provide
  2001. 1:39:50some classes. So simply add the class
  2002. 1:39:53name property and these telin classes.
  2003. 1:39:56Next we'll add one div where we have to
  2004. 1:39:58add the logo. So we have added a div
  2005. 1:40:02here and in this div
  2006. 1:40:05we will add the flex layout. Then we'll
  2007. 1:40:08insert the logo and text. For the logo,
  2008. 1:40:12we will use the img tag. In this src,
  2009. 1:40:15simply provide the
  2010. 1:40:18path of the logo file or image. So let's
  2011. 1:40:21add the logo. SVG because it is
  2012. 1:40:24available in the public folder. And in
  2013. 1:40:27the alt tag, we can simply add the text
  2014. 1:40:30called logo. And now in this image, we
  2015. 1:40:34have to provide the size. So just add
  2016. 1:40:37the class name size six. Next we have to
  2017. 1:40:40add the blank text. So we'll add the
  2018. 1:40:42text in a span tag and the text will be
  2019. 1:40:46builder AI. For this text we have to
  2020. 1:40:49change the text size and font. So we
  2021. 1:40:53have added the text excel font semi bold
  2022. 1:40:57and tracking type. Now after that we
  2023. 1:41:01have to add the user's name. Right? So
  2024. 1:41:04first we need the user data from the
  2025. 1:41:06context. So before this return
  2026. 1:41:11we will provide const
  2027. 1:41:15curly braces equal to
  2028. 1:41:18use app context. Use app context is
  2029. 1:41:23imported here. Right? And from this use
  2030. 1:41:26app context we can access the
  2031. 1:41:30user.
  2032. 1:41:32Let me come back to the context file. In
  2033. 1:41:34this context file, you can see we have
  2034. 1:41:36the value. In this value object, we have
  2035. 1:41:39the user, right? So, we can access it in
  2036. 1:41:42any other file or pages. So, now we have
  2037. 1:41:45the user data here. After that, let's
  2038. 1:41:48come here and uh
  2039. 1:41:52just after this div that contains the
  2040. 1:41:54brand logo and text, we will create
  2041. 1:41:57another div. So this div will display
  2042. 1:42:01the user's name and with that we'll add
  2043. 1:42:03one log out button. So
  2044. 1:42:07let's add some classes to align the
  2045. 1:42:09button and text. So we will add the flex
  2046. 1:42:13layout. So we have added the flex
  2047. 1:42:15layout, text size, font and text color.
  2048. 1:42:19Then we'll insert the text in a span
  2049. 1:42:21tag. So it will be our
  2050. 1:42:25user
  2051. 1:42:29dot name.
  2052. 1:42:32Next we have to add one button that will
  2053. 1:42:35be the logout button. So here we have
  2054. 1:42:37added the button tag and just add the
  2055. 1:42:40button text called sign out. Now for
  2056. 1:42:43this button provide some classes also.
  2057. 1:42:46So I'll provide these TIN classes. Let
  2058. 1:42:51me save the changes and we'll open the
  2059. 1:42:54web page. So you can see here we have
  2060. 1:42:56the
  2061. 1:42:57color in the entire screen entire web
  2062. 1:43:00page and here we have a logo in the top
  2063. 1:43:04left side and in the top right side we
  2064. 1:43:06have the user's name that is the dummy
  2065. 1:43:08name and we have the sign out button.
  2066. 1:43:12Right now after that we have to add the
  2067. 1:43:15hero section where we will add the
  2068. 1:43:17welcome message some promo text we'll
  2069. 1:43:20add some description and then we'll add
  2070. 1:43:22the input field. So let's just come back
  2071. 1:43:26here and after closing of this nav here
  2072. 1:43:29let's add one comment called hero for
  2073. 1:43:33the hero section here simply provide the
  2074. 1:43:36div and uh in this div we have to
  2075. 1:43:39provide some relevant classes. So we
  2076. 1:43:42have added these classes here and within
  2077. 1:43:45this div we'll add another one. So we
  2078. 1:43:48have another div here and here we have
  2079. 1:43:50to provide the width and provide the
  2080. 1:43:53layout. It will be
  2081. 1:43:56flex flex column and item center.
  2082. 1:44:00Now in this one first we have to add one
  2083. 1:44:03small message that will be a small
  2084. 1:44:06badge. So just add the comment here that
  2085. 1:44:09is promotional badge or promo badge.
  2086. 1:44:13So let's add one div for this promo
  2087. 1:44:16badge. In this div we'll add the span
  2088. 1:44:19tag. In this aspan we'll add the text
  2089. 1:44:22called promo.
  2090. 1:44:24After that we'll add the another aspan.
  2091. 1:44:27And here we'll add the
  2092. 1:44:29text called create your first project
  2093. 1:44:32for free.
  2094. 1:44:34Now let's align everything. So in the
  2095. 1:44:38parent div we have to provide the
  2096. 1:44:40classes. So we have added these classes.
  2097. 1:44:43Let's save the changes and come back
  2098. 1:44:45here. So you can see here we have the
  2099. 1:44:47text promo and create your first project
  2100. 1:44:50for free. Let's add the classes for this
  2101. 1:44:53span tag also which is the first one. So
  2102. 1:44:55in this first one provide the class name
  2103. 1:44:58property and these delin classes. Let's
  2104. 1:45:00save the changes and come back here. So
  2105. 1:45:02now you can see this promo badge is
  2106. 1:45:05looking good. After that we have to add
  2107. 1:45:08one title. So just come back here and uh
  2108. 1:45:12let me add the comment also. So after
  2109. 1:45:14this one we'll add the comment called
  2110. 1:45:16title and for the title we will use H1
  2111. 1:45:19tag and in this H1 tag simply add the
  2112. 1:45:23text called let's build your app
  2113. 1:45:26together. Then we will add the class
  2114. 1:45:28name and in this class name
  2115. 1:45:31we are going to provide these TIN
  2116. 1:45:34classes. Now after this title we have to
  2117. 1:45:36add the description also. So we will
  2118. 1:45:38insert the description in P tag and in
  2119. 1:45:41this P tag we will add this small text.
  2120. 1:45:47Now for this description also we have to
  2121. 1:45:49provide some classes. So we have added
  2122. 1:45:52these TIN classes for the description.
  2123. 1:45:54Let me see the changes on web page. So
  2124. 1:45:57you can see here we have a title and a
  2125. 1:45:59small description.
  2126. 1:46:02Now after that we have to add one input
  2127. 1:46:05field. So we will come back here and uh
  2128. 1:46:09we will wrap this input field inside a
  2129. 1:46:12div. So first we will add a div here and
  2130. 1:46:15inside this div we will create the input
  2131. 1:46:19field. So let's add the class name and
  2132. 1:46:23uh in this class name provide width it
  2133. 1:46:27will be full and margin top six
  2134. 1:46:30and here we'll add some comment also. So
  2135. 1:46:33let me provide the comment that is
  2136. 1:46:36prompt input with glasmorphic variant
  2137. 1:46:40and uh here instead of simply adding the
  2138. 1:46:43input field let me create a separate
  2139. 1:46:45component because in this one we'll add
  2140. 1:46:48different icons also. So let's just come
  2141. 1:46:52back here in the sidebar and uh in this
  2142. 1:46:56one you can see we have the component
  2143. 1:46:58folder. So in this component folder
  2144. 1:47:01we'll create a new component. So create
  2145. 1:47:03a new file and write the file name
  2146. 1:47:06prompt input dot jsx.
  2147. 1:47:11Now in this prompt input dot jsx we will
  2148. 1:47:14get some data as props. So first we'll
  2149. 1:47:17add rafce
  2150. 1:47:22for creating the component structure.
  2151. 1:47:24And uh in this one let's destructure the
  2152. 1:47:29props. So just add curly braces. And
  2153. 1:47:32here we will get
  2154. 1:47:35onsubmit.
  2155. 1:47:37After that we'll get the loading. So
  2156. 1:47:39let's add the loading false. Then we
  2157. 1:47:42will get placeholder. So I'll provide
  2158. 1:47:45the placeholder here.
  2159. 1:47:48And uh after this placeholder we will
  2160. 1:47:51add large false.
  2161. 1:47:56Then we'll get autofocus it will be
  2162. 1:47:58false.
  2163. 1:48:00And then variant it will be default.
  2164. 1:48:05Right now in this one just create some
  2165. 1:48:08state. So we'll create the state called
  2166. 1:48:10value and search function name is set
  2167. 1:48:13value equal to user state and let's
  2168. 1:48:18initialize it using empty string. So
  2169. 1:48:21this will be the input field value and
  2170. 1:48:24after that we'll add the reference of
  2171. 1:48:27the element. So just add con
  2172. 1:48:30text area ref equal to
  2173. 1:48:33use user ref and import the user ref
  2174. 1:48:36from react and initialize it using null.
  2175. 1:48:41Now after that let's come here before
  2176. 1:48:45this return. Here
  2177. 1:48:49let's provide
  2178. 1:48:51if
  2179. 1:48:54variant is equal to
  2180. 1:48:59glass.
  2181. 1:49:00So if the variant is equal to glass here
  2182. 1:49:04we'll add another return statement. So
  2183. 1:49:06just add return and provide this
  2184. 1:49:08parenthesis. And here we'll add a form.
  2185. 1:49:12So let's add the form tag.
  2186. 1:49:15So we have added a form tag here and in
  2187. 1:49:18this form tag we'll add some classes. So
  2188. 1:49:21just add the class name property and
  2189. 1:49:24provide these TIN classes.
  2190. 1:49:27Now first we have to add one text area.
  2191. 1:49:30So let's add
  2192. 1:49:34text area tag and provide the
  2193. 1:49:38self-closing tag here.
  2194. 1:49:42Now in this text area we will provide
  2195. 1:49:45the reference. So provide ref and it
  2196. 1:49:48will be
  2197. 1:49:52text area ref.
  2198. 1:49:55Now after that we'll add the value and
  2199. 1:49:58provide the value state. Then we'll add
  2200. 1:50:02the onchange. So we will provide the
  2201. 1:50:04onchange property. In this onchange
  2202. 1:50:07property, add one add function with the
  2203. 1:50:09event in the parameter and then use the
  2204. 1:50:12setter function set value and just add
  2205. 1:50:15the e.target
  2206. 1:50:18dot value.
  2207. 1:50:20Now after that
  2208. 1:50:23here we'll add on key down.
  2209. 1:50:26In this on key down we'll add one
  2210. 1:50:30function that we'll create here before
  2211. 1:50:33this return. So let's add
  2212. 1:50:40a function here
  2213. 1:50:44const
  2214. 1:50:46handle key down
  2215. 1:50:49equal to
  2216. 1:50:52arrow function and get the event in the
  2217. 1:50:54parameter.
  2218. 1:50:56Right? And after that we'll add the if
  2219. 1:50:59statement.
  2220. 1:51:02If E dot key is equal to enter and
  2221. 1:51:08not of
  2222. 1:51:12event dot shift key in this case simply
  2223. 1:51:16add e dot prevent default
  2224. 1:51:19and after that we have to submit the
  2225. 1:51:22data right for that we'll create one
  2226. 1:51:24another function handle subummit right
  2227. 1:51:26so just scroll up here we'll add con
  2228. 1:51:31handle submit equal to
  2229. 1:51:35add a function and in this one also
  2230. 1:51:37we'll get the event as parameter and
  2231. 1:51:41provide if statement
  2232. 1:51:44if e in this case we'll add e dot
  2233. 1:51:51prevent default
  2234. 1:51:53after that we'll add con trimmed equal
  2235. 1:51:56to
  2236. 1:51:57our value
  2237. 1:51:59dot trim So it will remove the extra
  2238. 1:52:03space from the beginning and end of the
  2239. 1:52:06value that is written in the input
  2240. 1:52:08field. And after that we'll add another
  2241. 1:52:10if statement.
  2242. 1:52:14And let's add if
  2243. 1:52:16not of trimmed or loading.
  2244. 1:52:21Then simply add return.
  2245. 1:52:24Then we'll add onsubmit.
  2246. 1:52:27And in this onsubmit provide the trimmed
  2247. 1:52:31data. And after that we will use the
  2248. 1:52:33setter function set value. And we'll
  2249. 1:52:36clear the value like this using the
  2250. 1:52:39empty string. And let's call this
  2251. 1:52:42function here in the handle key down.
  2252. 1:52:45After e.pre default we can call this
  2253. 1:52:47function handle submit. Correct. Now
  2254. 1:52:51after that let's add this function in
  2255. 1:52:54the form also. So here we have the form.
  2256. 1:52:57So here let's provide the
  2257. 1:53:01onsubmit and in this onsubmit we can
  2258. 1:53:03provide the handle submit function. Save
  2259. 1:53:06the changes. Now after that let's come
  2260. 1:53:08here in the on key down. In this on key
  2261. 1:53:12down we can add handle key down.
  2262. 1:53:16Next we'll add the placeholder. So we
  2263. 1:53:19can simply provide the placeholder that
  2264. 1:53:22we are getting from
  2265. 1:53:24props. So just add
  2266. 1:53:27placeholder.
  2267. 1:53:29After that we'll add disabled property.
  2268. 1:53:31So this
  2269. 1:53:34field will be disabled when the loading
  2270. 1:53:36is true. So just add the loading and
  2271. 1:53:40after that let's add
  2272. 1:53:44rows. So provide the rows three
  2273. 1:53:47and then provide some classes for this
  2274. 1:53:50text area. So in this text area we have
  2275. 1:53:53to add the width. It will be full. And
  2276. 1:53:56we will add other tailwind classes like
  2277. 1:53:58this.
  2278. 1:54:00Save the changes. And uh after that
  2279. 1:54:03let's
  2280. 1:54:05add another div after this text area. So
  2281. 1:54:07after closing off this text area we will
  2282. 1:54:10add a div.
  2283. 1:54:15Now in this div we'll add the flex
  2284. 1:54:18layout to align the content. So provided
  2285. 1:54:21these classes here and uh then we'll add
  2286. 1:54:24the label tag. So just add this label
  2287. 1:54:26tag. In this label we have the HTML for.
  2288. 1:54:30So in this HTML for we'll add the file
  2289. 1:54:34and after that we have to add some
  2290. 1:54:37classes. So we have added these classes
  2291. 1:54:39and within this label let's add the
  2292. 1:54:45input. So we have added input type. So
  2293. 1:54:49let me add the type file so that we can
  2294. 1:54:51upload a file here. So input type is
  2295. 1:54:54file and provide the id
  2296. 1:54:57and in the id provide this file that is
  2297. 1:55:00available in the HTML 4. After that
  2298. 1:55:04we'll add the property hidden. So it
  2299. 1:55:06will be hidden. Next we have to add the
  2300. 1:55:10icon here. So just add opening arrow
  2301. 1:55:15cloud upload icon and import this icon
  2302. 1:55:18from Lucid React.
  2303. 1:55:21We are not getting this suggestion here.
  2304. 1:55:23So let me import it manually. We'll add
  2305. 1:55:26import
  2306. 1:55:29and uh just add curly braces
  2307. 1:55:33from Lucid React package. And from this
  2308. 1:55:36lucid react
  2309. 1:55:38let's get the
  2310. 1:55:41cloud upload icon
  2311. 1:55:45and uh just insert this icon here cloud
  2312. 1:55:49upload icon and close it. Now in this
  2313. 1:55:52icon we have to provide the size also.
  2314. 1:55:54So let me set the size 18.
  2315. 1:55:58So below the input field we have added
  2316. 1:56:01one upload icon. Using that we can
  2317. 1:56:04upload the files. Now after that we have
  2318. 1:56:08to add the another icon. Using that we
  2319. 1:56:11can add the voice. So we'll add the mic
  2320. 1:56:16icon and uh with that we will also add
  2321. 1:56:20one
  2322. 1:56:22icon like arrow right icon
  2323. 1:56:26to submit this form. So just after this
  2324. 1:56:32label we will create one div.
  2325. 1:56:36So this div will be in the right side.
  2326. 1:56:38So in the right side we'll add one mic
  2327. 1:56:40icon and one submit icon that is the
  2328. 1:56:42arrow icon. And let's add the classes
  2329. 1:56:47for this div that contains both icons.
  2330. 1:56:51So provide the flex item center and
  2331. 1:56:54justify end and the gap will be two. Now
  2332. 1:56:59in this one just add the button tag. In
  2333. 1:57:02the button we'll add the mic icon
  2334. 1:57:06and import the mic icon from Lucid React
  2335. 1:57:08and set the size. So again size will be
  2336. 1:57:1218
  2337. 1:57:15and uh after that provide the classes
  2338. 1:57:18for this button. So we have added these
  2339. 1:57:21classes and provide the type also. So
  2340. 1:57:24the button type will be button only.
  2341. 1:57:27That's it. So we have added the type
  2342. 1:57:29button.
  2343. 1:57:31Now let me add another button tag. So
  2344. 1:57:33just copy this one only. Paste it here.
  2345. 1:57:35In the second one we will add type. So
  2346. 1:57:39the type will be submit.
  2347. 1:57:42Then we will add the classes here. So we
  2348. 1:57:45have updated the classes as you can see
  2349. 1:57:47here. And after that we will add the
  2350. 1:57:50disabled property also. So here we'll
  2351. 1:57:54add the space. And you can see we will
  2352. 1:57:57add the disabled.
  2353. 1:58:01So it will be disabled when not of value
  2354. 1:58:05dot trim. We cannot submit it when the
  2355. 1:58:09value is not available or when the
  2356. 1:58:13loading is true. In this case this
  2357. 1:58:15button will be disabled. And after that
  2358. 1:58:18in this button we have to add the icon
  2359. 1:58:20based on the loading status. So remove
  2360. 1:58:23this icon and provide curly braces. And
  2361. 1:58:27here let's add the loading. So we will
  2362. 1:58:31check if the loading is true. In this
  2363. 1:58:33case we have to add the loaded icon. So
  2364. 1:58:35provide loader two icon from the lucid
  2365. 1:58:38react and uh
  2366. 1:58:42else we will add the arrow write icon.
  2367. 1:58:45So add this arrowite icon. Import it.
  2368. 1:58:49Now for these icons we have to add this
  2369. 1:58:53size. So we will set the size 18 for
  2370. 1:58:56both icon.
  2371. 1:58:59Here also we'll add 18. And in this one
  2372. 1:59:02also now in the first one we have to add
  2373. 1:59:04the animation also. So let's add the
  2374. 1:59:07class name and provide animate a spin.
  2375. 1:59:10That's it. Save the changes. So this
  2376. 1:59:14layout will be displayed when we will
  2377. 1:59:16provide the variant glass.
  2378. 1:59:19Now if the variant is not equal to class
  2379. 1:59:22it means the variant is default then
  2380. 1:59:24we'll display another UI for that let's
  2381. 1:59:28come here in the default return in this
  2382. 1:59:32default return statement remove the text
  2383. 1:59:36and for this div we will add the class
  2384. 1:59:40name now we'll add the dynamic class
  2385. 1:59:44here so just add the curly braces and
  2386. 1:59:46back text in this back X we will add
  2387. 1:59:49these fixed classes and after that we'll
  2388. 1:59:52use the dollar sign curly braces and
  2389. 1:59:54insert this
  2390. 1:59:57state large
  2391. 1:59:59if it is true in this case we will add
  2392. 2:00:02the padding four
  2393. 2:00:06else we will add
  2394. 2:00:08padding three that's it and after that
  2395. 2:00:12here also we have to add the text area
  2396. 2:00:14so I'll just copy this text area from
  2397. 2:00:17here.
  2398. 2:00:19Here we have the text area. Let's copy
  2399. 2:00:21and paste it here. So in this text area
  2400. 2:00:25again we'll add the reference that is
  2401. 2:00:27text area reference then value then on
  2402. 2:00:30change and uh after this on change
  2403. 2:00:34we have on key down then
  2404. 2:00:39placeholder
  2405. 2:00:41and after that disabled
  2406. 2:00:44and uh then we have the
  2407. 2:00:48rows and after that we have classes. So
  2408. 2:00:52let me update the rows here. Here we'll
  2409. 2:00:54check large. If it is true then we'll
  2410. 2:00:58add rows five else
  2411. 2:01:01one.
  2412. 2:01:03So we have added rows. If large is true
  2413. 2:01:06then five else one. Correct? Now after
  2414. 2:01:10that we have to update these classes. So
  2415. 2:01:13in this one also we'll use the dynamic
  2416. 2:01:15classes. So just remove it. We'll add
  2417. 2:01:18the curly braces and back tick.
  2418. 2:01:22And uh in this back tick first we'll add
  2419. 2:01:24some fixed classes like this and then
  2420. 2:01:27we'll add dollar sign curly braces and
  2421. 2:01:30provide the turnary operator. If large
  2422. 2:01:34is true then text base else text small.
  2423. 2:01:39After that we have to add a button.
  2424. 2:01:43So just add the button tag and in this
  2425. 2:01:46button tag we'll add curly braces
  2426. 2:01:49loading. If the loading is true then we
  2427. 2:01:52have to add the loaded icon. So just add
  2428. 2:01:54loaded to icon
  2429. 2:01:57and for this icon we will add the size.
  2430. 2:02:01So for this size also we'll check the
  2431. 2:02:03large state. If it is true then 20 else
  2432. 2:02:0715. Then we have to add the animation.
  2433. 2:02:10So just add the
  2434. 2:02:12animate a spin and uh if the loading is
  2435. 2:02:16false then we'll add the right arrow
  2436. 2:02:19icon so that we can submit this
  2437. 2:02:22data using the input field. So just add
  2438. 2:02:25else statement provide
  2439. 2:02:28arrow write icon.
  2440. 2:02:33In this arrow write icon we'll add the
  2441. 2:02:35size. So it could be 20 or 15 like this.
  2442. 2:02:41Now we'll add the on click property on
  2443. 2:02:43this button. So in this button we'll add
  2444. 2:02:47on click and uh simply add the add
  2445. 2:02:50function
  2446. 2:02:52provide handle submit. After that we'll
  2447. 2:02:56add
  2448. 2:02:58disabled. In this disabled we will add
  2449. 2:03:02not of
  2450. 2:03:04value dot trim then or loading.
  2451. 2:03:11Now in this button provide some classes
  2452. 2:03:14also. So provide the class name property
  2453. 2:03:16and here we have added these classes and
  2454. 2:03:20after that we'll add some custom styles.
  2455. 2:03:23So just add the
  2456. 2:03:26style property object and provide the
  2457. 2:03:30width. So the width will be either 36 or
  2458. 2:03:3424. And similarly we'll add the height
  2459. 2:03:37also. So let's add the height. If large
  2460. 2:03:40is true then height 36 is 24. Save the
  2461. 2:03:44changes. Now in this component we have
  2462. 2:03:48to add the functionality so that when we
  2463. 2:03:51load the component then the input field
  2464. 2:03:54will be autofocused. For that here let's
  2465. 2:03:58add one use effect.
  2466. 2:04:02So it will execute this
  2467. 2:04:05add function every time when you load
  2468. 2:04:07the component. So we have added the use
  2469. 2:04:10effect arrow function and provide the
  2470. 2:04:12dependency array here. In this
  2471. 2:04:14dependency array we'll add the
  2472. 2:04:16autofocus. Now in this function simply
  2473. 2:04:20add if statement if
  2474. 2:04:22autofocus is true and
  2475. 2:04:27text area reference dot current.
  2476. 2:04:31In this case, let's add the text area
  2477. 2:04:35reference dot current dot focus.
  2478. 2:04:41So it will automatically focus this
  2479. 2:04:44input field when we load this component
  2480. 2:04:46or our homepage. After creating this
  2481. 2:04:50component, let me mount it on our
  2482. 2:04:53homepage. So just come back here in the
  2483. 2:04:55homepage.jsx JSX and within this div
  2484. 2:04:58let's let's add our component that is
  2485. 2:05:02prompt input. This component has been
  2486. 2:05:04imported here. In this prompt input we
  2487. 2:05:07will add onsubmit and in this onsubmit
  2488. 2:05:11we have to add one function. After that
  2489. 2:05:14we'll add the loading. In this loading
  2490. 2:05:17we have to add the
  2491. 2:05:21state that is generating prompt. Then it
  2492. 2:05:24will be loading. After that we have to
  2493. 2:05:26add the placeholder. So let's add the
  2494. 2:05:29placeholder text called create a
  2495. 2:05:32portfolio website.
  2496. 2:05:34Then we have to add the variant. Let's
  2497. 2:05:37add the variant here. And in the variant
  2498. 2:05:39we'll add class.
  2499. 2:05:42Next we'll add autofocus.
  2500. 2:05:46Let's save the changes. And uh after
  2501. 2:05:49that now you can see here we have some
  2502. 2:05:51message like we have to provide the
  2503. 2:05:54onsubmit here it could not be empty
  2504. 2:05:57object right so I'll just come back here
  2505. 2:06:01let's provide the
  2506. 2:06:04empty arrow function here in this
  2507. 2:06:06onsubmit and in this loading let's
  2508. 2:06:10provide false we will save the changes
  2509. 2:06:12and open our application so you can see
  2510. 2:06:15here we have one text area And we have
  2511. 2:06:18one upload icon. Using that we can
  2512. 2:06:21upload the files. And here we have the
  2513. 2:06:23mic icon. And this is the submit icon.
  2514. 2:06:25That is the arrow right icon.
  2515. 2:06:28Now we'll come back here. And if I
  2516. 2:06:31change it to true. Let's add loading
  2517. 2:06:34true. Save the changes and come back
  2518. 2:06:37here. So you can see here we have the
  2519. 2:06:38loading animation instead of the arrow
  2520. 2:06:41right icon. So this field will be
  2521. 2:06:44disabled. We cannot type here. And if I
  2522. 2:06:47come back make it false. So this field
  2523. 2:06:51is already focused. And here we can type
  2524. 2:06:54anything in this text area.
  2525. 2:06:58Next we have to display the list of
  2526. 2:07:00projects. For that we'll create our
  2527. 2:07:02project data in the context that we can
  2528. 2:07:05share in different component. And we'll
  2529. 2:07:09also create our functions that will be
  2530. 2:07:12this onsubmit function
  2531. 2:07:14in our context. So let's come back to
  2532. 2:07:18app context.jsx.
  2533. 2:07:20In this app context dot jsx, we'll
  2534. 2:07:23create some states first. So scroll up
  2535. 2:07:28here you can see we have added author
  2536. 2:07:31states. So after that let's add the
  2537. 2:07:34other states also. So simply add the
  2538. 2:07:37comment states and provide
  2539. 2:07:40this state and we'll change the name. So
  2540. 2:07:42state name is projects then setter
  2541. 2:07:46function set projects equal to use state
  2542. 2:07:49and initialize it using empty array. Now
  2543. 2:07:53duplicate it.
  2544. 2:07:56In this one we'll add the loading
  2545. 2:07:58projects and the setter function set
  2546. 2:08:00loading projects.
  2547. 2:08:03By default it will be true. Duplicate
  2548. 2:08:06it. In the next one we'll add active
  2549. 2:08:09project and set active project.
  2550. 2:08:14Default value will be null.
  2551. 2:08:17Now duplicate it. Here we'll add loading
  2552. 2:08:20active project and set function set
  2553. 2:08:23loading active project
  2554. 2:08:26and initialize it using true.
  2555. 2:08:30After that we'll add
  2556. 2:08:33chat loading and set a function set chat
  2557. 2:08:37loading.
  2558. 2:08:39Initialize it using false.
  2559. 2:08:42Next we'll add generating project and
  2560. 2:08:45the setter function name is set
  2561. 2:08:47generating project.
  2562. 2:08:49By default it should be false. Now
  2563. 2:08:53duplicate it.
  2564. 2:08:56Here we'll add active file and set
  2565. 2:08:59function name is set active file
  2566. 2:09:03equal to user state and provide
  2567. 2:09:06slash
  2568. 2:09:09app.js.
  2569. 2:09:11Now after that just duplicate it. Here
  2570. 2:09:13we'll add so code and uh setter function
  2571. 2:09:18set so code.
  2572. 2:09:20Here we'll add use a state and by
  2573. 2:09:23default it will be false. We will use it
  2574. 2:09:26to display our code using sandbox
  2575. 2:09:31and by default the active file will be
  2576. 2:09:33app.js.
  2577. 2:09:36Now in this context you can see we have
  2578. 2:09:38already created the login and
  2579. 2:09:40registration function. After this
  2580. 2:09:41registration function we'll create the
  2581. 2:09:44next function that will be for logout.
  2582. 2:09:46So let's add const
  2583. 2:09:52log out equal to async arrow function.
  2584. 2:09:55Now in this one we'll add the try
  2585. 2:09:58catcher statement and in the try block
  2586. 2:10:00we'll make the network request using
  2587. 2:10:02await API dot post method
  2588. 2:10:08and uh here we'll add the
  2589. 2:10:11path. It will be / ai/ o/
  2590. 2:10:15logout. After that we'll add the setter
  2591. 2:10:19function set user and uh we'll set the
  2592. 2:10:23user null. After that set projects
  2593. 2:10:29in this set projects provide the empty
  2594. 2:10:31array. Then we'll add set active
  2595. 2:10:36project.
  2596. 2:10:39In this active project we'll add null.
  2597. 2:10:44After that we'll add toast notification.
  2598. 2:10:47So we'll add toast dot success and
  2599. 2:10:51provide the message that is logged out
  2600. 2:10:54successfully.
  2601. 2:10:57And after log out we have to navigate
  2602. 2:10:59the users on
  2603. 2:11:02login page. Right? So for that
  2604. 2:11:07here we have the navigate function. So
  2605. 2:11:08let's use it here. After this
  2606. 2:11:11notification, simply add
  2607. 2:11:14navigate and provide the path / login.
  2608. 2:11:19So it will open the login page after log
  2609. 2:11:21out. Now come to the catch block. Here
  2610. 2:11:23we'll add error.
  2611. 2:11:27Then we'll add console.
  2612. 2:11:29And then we'll add the toast
  2613. 2:11:31notification that is toast. Login
  2614. 2:11:33failed. To display the toast
  2615. 2:11:35notification, we have to open our app
  2616. 2:11:38dot jsx. And in this one, we have to add
  2617. 2:11:41the toaster tag. So let's add one
  2618. 2:11:43fragment in this return. Within this
  2619. 2:11:46fragment, we'll insert this routes
  2620. 2:11:51like this. And uh before this routes,
  2621. 2:11:54we'll add the toaster tag.
  2622. 2:11:58Import the toaster from react hot toast.
  2623. 2:12:01Just close it. You can see toaster tag
  2624. 2:12:03has been imported. Now we'll come back
  2625. 2:12:05here in the app context and we have
  2626. 2:12:08created the logout function. After that
  2627. 2:12:10we'll create the function to load the
  2628. 2:12:12projects from API. Right? So
  2629. 2:12:16let's add the comment here that is
  2630. 2:12:20projects actions. So just add the
  2631. 2:12:23function
  2632. 2:12:25that is con load projects and create a
  2633. 2:12:31sync arrow function.
  2634. 2:12:34So here we'll add the if statement if
  2635. 2:12:36not of user. If user is not available
  2636. 2:12:40in this case simply add return
  2637. 2:12:44and if the user is available we will
  2638. 2:12:46continue it. So just add the try catch
  2639. 2:12:49and in this try block we'll add con data
  2640. 2:12:52equal to await and provide the API dot
  2641. 2:12:57get method and provide the endpoint that
  2642. 2:13:00is / API/ projects. Now after that
  2643. 2:13:03simply use the set projects in this set
  2644. 2:13:06projects provide the data.
  2645. 2:13:10Now come here in the catch we'll add the
  2646. 2:13:12error and provide console dot error.
  2647. 2:13:16Then provide the toast dot error that is
  2648. 2:13:20failed to load project list. Then we'll
  2649. 2:13:24add the finally block and in the finally
  2650. 2:13:26block we'll provide the set loading
  2651. 2:13:30projects and make it false. So by
  2652. 2:13:32default the set loading projects will be
  2653. 2:13:34true. It means the loading projects will
  2654. 2:13:36be true and after that we'll make it
  2655. 2:13:39false. And after that let's add another
  2656. 2:13:42function to load the individual project.
  2657. 2:13:46Right? So here we'll add the another
  2658. 2:13:48function.
  2659. 2:13:50So simply add const load project equal
  2660. 2:13:54to async arrow function. To load the
  2661. 2:13:56individual project we have to provide
  2662. 2:13:59the project id. So just add the
  2663. 2:14:02parameter here that will be ID and we'll
  2664. 2:14:05add the next parameter that is silent
  2665. 2:14:08equal to false.
  2666. 2:14:10So default value is false. Now again we
  2667. 2:14:13will use the same statement. If not of
  2668. 2:14:16user then return
  2669. 2:14:19then we'll add if not of silent.
  2670. 2:14:24In this case just add set loading active
  2671. 2:14:28project and make it true.
  2672. 2:14:32After that provide the try catch. So in
  2673. 2:14:35this try block let's add this statement
  2674. 2:14:39that is data equal to await API.get and
  2675. 2:14:43provide the endpoint. So we will add the
  2676. 2:14:46back tix here
  2677. 2:14:48instead of quote
  2678. 2:14:51just add the backix
  2679. 2:14:55and provide / ai/ projects and slash
  2680. 2:14:59dollar sign curly braces id. So we'll
  2681. 2:15:03insert the id in the parameter. Now
  2682. 2:15:06after that just use the set active
  2683. 2:15:09project and provide the data.
  2684. 2:15:15Then let's add the command default file
  2685. 2:15:19selection.
  2686. 2:15:20So here we'll add con file equal to
  2687. 2:15:24object dot keys data do files. Then
  2688. 2:15:28we'll add if statement. If
  2689. 2:15:30files.length length is greater than
  2690. 2:15:32zero. In this case, we'll add set active
  2691. 2:15:36file
  2692. 2:15:38and uh in this one insert one
  2693. 2:15:43add a function. Here we'll get the
  2694. 2:15:45previous data and then we'll add if
  2695. 2:15:48statement if file dot includes
  2696. 2:15:53and previous.
  2697. 2:15:55If it is true then simply add return
  2698. 2:15:58previous.
  2699. 2:16:00Then we'll add another if statement
  2700. 2:16:03files doinccludes
  2701. 2:16:05app.js.
  2702. 2:16:07Then we'll add return app.js.
  2703. 2:16:12After that we'll add the return and
  2704. 2:16:15provide the file using this files index
  2705. 2:16:19zero.
  2706. 2:16:21Then we'll add the statement in the
  2707. 2:16:24catch block. So just come here in the
  2708. 2:16:25catch block we'll add the error. Then
  2709. 2:16:28add console dot error. Then we'll add if
  2710. 2:16:32statement if not of silent.
  2711. 2:16:36In this case just add the toast
  2712. 2:16:38notification using toast dot error.
  2713. 2:16:42And then we'll add the navigate. So
  2714. 2:16:44we'll navigate the users on homepage.
  2715. 2:16:47Then we have to add the finally block.
  2716. 2:16:49So here we'll add finally.
  2717. 2:16:54And uh let's add if not of silent
  2718. 2:17:00then provide set loading active project
  2719. 2:17:05and make it false.
  2720. 2:17:08After that we'll
  2721. 2:17:10automatically call the active project a
  2722. 2:17:13status.
  2723. 2:17:16So
  2724. 2:17:17let's add the command here.
  2725. 2:17:20automatically Paul active project a
  2726. 2:17:22status and uh let's add if generating or
  2727. 2:17:27pending
  2728. 2:17:28right so if the status is generating or
  2729. 2:17:31pending it will automatically try to
  2730. 2:17:33fetch the latest update so here we'll
  2731. 2:17:36add the use effect in this use effect we
  2732. 2:17:39have added one add function and then
  2733. 2:17:41comma dependency array in the dependency
  2734. 2:17:44array we'll add the active project
  2735. 2:17:48if it is available then dot
  2736. 2:17:50underscore id
  2737. 2:17:54then add comma
  2738. 2:17:57active project
  2739. 2:18:00dot status
  2740. 2:18:02then comma provide the load project
  2741. 2:18:07then provide
  2742. 2:18:10user. So if any of these data changes
  2743. 2:18:14then it will execute this add a
  2744. 2:18:15function. Now in this one just add if
  2745. 2:18:21not of active project dot id or not of
  2746. 2:18:25user then simply add return.
  2747. 2:18:29Next we'll add const is ongoing
  2748. 2:18:34equal to
  2749. 2:18:37active project dot status is equal to
  2750. 2:18:39generating it means the it is generating
  2751. 2:18:43the project. Then we'll add or
  2752. 2:18:47active project a status is pending. If
  2753. 2:18:49the status is pending
  2754. 2:18:52or
  2755. 2:18:54active project dot a status is equal to
  2756. 2:18:58revising.
  2757. 2:19:00So in these cases this is ongoing will
  2758. 2:19:03be true and when ongoing is true
  2759. 2:19:07just add the if statement.
  2760. 2:19:11If it is true in this case we will use
  2761. 2:19:16set chat loading make it true then we'll
  2762. 2:19:19add con
  2763. 2:19:22interval
  2764. 2:19:24equal to
  2765. 2:19:26set interval
  2766. 2:19:28in the set interval add the arrow
  2767. 2:19:30function and provide the time
  2768. 2:19:352,000 mconds
  2769. 2:19:37and in this add function let's add load
  2770. 2:19:40project
  2771. 2:19:42in this load project
  2772. 2:19:45provide the active project dot id and
  2773. 2:19:50comma true
  2774. 2:19:52after this here we will add the return
  2775. 2:19:56and provide the arrow function like this
  2776. 2:20:00and simply add clear interval in this
  2777. 2:20:03clear interval provide our interval
  2778. 2:20:07now we'll add the else statement also In
  2779. 2:20:10this else statement, we'll add set chat
  2780. 2:20:13loading and make it false.
  2781. 2:20:16Save the changes.
  2782. 2:20:18Next, we have to add another function
  2783. 2:20:19using that generate the project. So,
  2784. 2:20:24just add con handle generate
  2785. 2:20:28equal to use call back. In this use call
  2786. 2:20:33back, let's add asynchronous add
  2787. 2:20:36function.
  2788. 2:20:38And after that we'll add comma and
  2789. 2:20:40dependency array it will be navigate and
  2790. 2:20:44user. Now in this function we have to
  2791. 2:20:48add the prompt as parameter
  2792. 2:20:51because using the prompt we have to
  2793. 2:20:53generate the project. So let's add if
  2794. 2:20:56not of user
  2795. 2:20:59then simply add return.
  2796. 2:21:02Then we'll add set generating project
  2797. 2:21:04and make it true. Then to generate the
  2798. 2:21:07project we have to make the network
  2799. 2:21:09request. So we'll make it inside the try
  2800. 2:21:11block. So we have added try catch and
  2801. 2:21:14here we'll add con data equal to await
  2802. 2:21:17API.post and provide the endpoint/ API/
  2803. 2:21:21projects and provide our prompt that
  2804. 2:21:23will be used to generate the project.
  2805. 2:21:26Then we have to add the notification. So
  2806. 2:21:28just add to dot success and uh let's add
  2807. 2:21:32the message AI agent is planning a
  2808. 2:21:36structure.
  2809. 2:21:38Then we have to add the navigate here.
  2810. 2:21:41So just add navigate and we will
  2811. 2:21:43navigate the users on builder page. So
  2812. 2:21:45just add the back tick path will be
  2813. 2:21:47/builder/
  2814. 2:21:48then data dot id that will be the
  2815. 2:21:51project id and come here in the catch.
  2816. 2:21:54In this catch we'll add the error.
  2817. 2:21:57Then add console dot error. Then we'll
  2818. 2:22:00add the toast notification. So just add
  2819. 2:22:02toast dot error.
  2820. 2:22:05And then we'll add the finally block. In
  2821. 2:22:07this finally block
  2822. 2:22:10we will add set generating and provide
  2823. 2:22:12set generating project. Make it false.
  2824. 2:22:18That's it. So we have created this
  2825. 2:22:20handle generate function.
  2826. 2:22:23After that we'll add another function
  2827. 2:22:25that is handle delete. So let me just
  2828. 2:22:28copy this one only. Paste it here.
  2829. 2:22:33And this one just change the name. It
  2830. 2:22:36will be handle delete.
  2831. 2:22:38And uh let's add the parameter. It will
  2832. 2:22:42be ID. And here we'll add if not of user
  2833. 2:22:45then return. Then we'll add the try
  2834. 2:22:47catch. In this try block we'll add await
  2835. 2:22:52API dot delete.
  2836. 2:22:56Then we'll add the end point. So simply
  2837. 2:22:59add back text / API/ projects and
  2838. 2:23:04provide the project ID using dollars and
  2839. 2:23:06curly braces.
  2840. 2:23:08Then we'll add the
  2841. 2:23:11setter function. So let me clear this.
  2842. 2:23:15And here we'll add set projects. Provide
  2843. 2:23:18the arrow function with the previous
  2844. 2:23:20data in the parameter. And provide the
  2845. 2:23:24previous
  2846. 2:23:25dot filter.
  2847. 2:23:29And uh here let's get the individual
  2848. 2:23:34project and provide
  2849. 2:23:37p dot
  2850. 2:23:40id
  2851. 2:23:41not equal to id. Then we'll add toast
  2852. 2:23:46dot success
  2853. 2:23:48and uh let's add project deleted
  2854. 2:23:51successfully.
  2855. 2:23:53Now we'll update the code in the catch
  2856. 2:23:55block. So here we'll update this console
  2857. 2:23:58dot error and then toast dot error and
  2858. 2:24:03from here we can remove this finally
  2859. 2:24:05block.
  2860. 2:24:06Let's update this dependency. So here
  2861. 2:24:08we'll add only user. That's it. Save the
  2862. 2:24:12changes. So we have added the handle
  2863. 2:24:14delete function also. After creating
  2864. 2:24:17these states and function let me pass it
  2865. 2:24:20through this value. So in this value
  2866. 2:24:23let's add comma and provide the
  2867. 2:24:26projects. Then we will add loading
  2868. 2:24:30projects.
  2869. 2:24:31Then we will add active project. After
  2870. 2:24:35that
  2871. 2:24:37loading active project
  2872. 2:24:40then chat loading.
  2873. 2:24:43Next we will add generating project then
  2874. 2:24:47active file. After that so code then
  2875. 2:24:52user is already there and uh next we'll
  2876. 2:24:56add
  2877. 2:24:58set active file.
  2878. 2:25:00After this set add tip file we'll add
  2879. 2:25:02set so code.
  2880. 2:25:05Then we'll add load projects. This is
  2881. 2:25:09the function. After that load project
  2882. 2:25:12function that will load individual
  2883. 2:25:14project. Then handle generate function.
  2884. 2:25:18After this handle generate we'll add
  2885. 2:25:21handle delete.
  2886. 2:25:23Now we can access these state and
  2887. 2:25:26function in any component. So let me
  2888. 2:25:29open the homepage dot jsx file and here
  2889. 2:25:33we'll get the required data. So from
  2890. 2:25:36this use app context we'll get the user.
  2891. 2:25:39After this user let's get projects
  2892. 2:25:45then we will get the loading projects.
  2893. 2:25:49After that
  2894. 2:25:51generating project
  2895. 2:25:53then load projects function.
  2896. 2:25:57After that handle generate function.
  2897. 2:26:02Next we'll add handle delete
  2898. 2:26:06and uh then we'll add the log out.
  2899. 2:26:11After that let me connect this log out
  2900. 2:26:13with our nav bar. So in the navbar you
  2901. 2:26:16can see we have this button right? So in
  2902. 2:26:18this button we'll add on click and in
  2903. 2:26:21this on click simply add
  2904. 2:26:24log out.
  2905. 2:26:27After that scroll down you can see here
  2906. 2:26:30we have the
  2907. 2:26:32prompt input. So in this prompt input we
  2908. 2:26:35have onsubmit. So in this onsummit we
  2909. 2:26:38can provide our
  2910. 2:26:40handle generate. So it will generate a
  2911. 2:26:43new project and in this loading just add
  2912. 2:26:49generating project. So when the
  2913. 2:26:50generating project is true then the
  2914. 2:26:53loading will be true. That's it. Now
  2915. 2:26:56save the changes and uh we'll come back
  2916. 2:26:58here. So you can see it is displaying
  2917. 2:27:02our input field here and when we enter
  2918. 2:27:06the prompt and submit this form it will
  2919. 2:27:09execute this handle generate function.
  2920. 2:27:12Now just below this we have to display
  2921. 2:27:15the list of projects. But before that we
  2922. 2:27:18have to add some tags also. So let me
  2923. 2:27:21just come back and uh
  2924. 2:27:25after closing off this div that is for
  2925. 2:27:28the input area or text area here we will
  2926. 2:27:32add the comment scrolling marku tags. So
  2927. 2:27:36let's add one div here.
  2928. 2:27:38In this div provide these classes.
  2929. 2:27:43Then we'll add another div.
  2930. 2:27:47Here we'll add the animate
  2931. 2:27:50mark and we will write the gap three.
  2932. 2:27:53Now we have to display our list of tags.
  2933. 2:27:56So just add the curly braces and get
  2934. 2:28:00home tags.
  2935. 2:28:03We are not getting the suggestions. So
  2936. 2:28:04it is available in the assets. If I open
  2937. 2:28:06assets.js, you can see it is available
  2938. 2:28:08here. So after opening it, if I start
  2939. 2:28:10typing home tags, we are getting the
  2940. 2:28:13suggestion to import it from the assets.
  2941. 2:28:15It has been imported. Now we'll add home
  2942. 2:28:17tags dot map. It is an array. So we can
  2943. 2:28:21use the map method. And then we'll add
  2944. 2:28:23the add a function. Here we'll get
  2945. 2:28:26individual tag
  2946. 2:28:28and index.
  2947. 2:28:30Then we'll add parenthesis and return a
  2948. 2:28:33button. So just add the button tag.
  2949. 2:28:37So we have added a button tag here. And
  2950. 2:28:40button text will be our tag.
  2951. 2:28:44Now in this button provide the key
  2952. 2:28:47property first. So let's add the key. It
  2953. 2:28:49will be our index. Next we will add the
  2954. 2:28:52on click. So in this onclick property
  2955. 2:28:56simply add
  2956. 2:28:59add a function and provide handle
  2957. 2:29:01generate. And in this handle generate we
  2958. 2:29:03have to provide the prompt. So the
  2959. 2:29:05prompt will be our tag.
  2960. 2:29:08Next we'll add the disabled. So in this
  2961. 2:29:12disabled again add the same thing that
  2962. 2:29:15is generating project then it will be
  2963. 2:29:18disabled then we'll add the class name
  2964. 2:29:21and uh here we have to add the
  2965. 2:29:26TIN classes like this save the changes
  2966. 2:29:29after that let's come here so you can
  2967. 2:29:31see here we have the list of tags which
  2968. 2:29:33is scrolling horizontally
  2969. 2:29:40after that let me just come back here.
  2970. 2:29:43Here we will provide this space and
  2971. 2:29:46provide the comment that is
  2972. 2:29:49all projects. So we have to display all
  2973. 2:29:52the projects here. Just below this
  2974. 2:29:55comment let's add the curly braces and
  2975. 2:29:58we will add not of
  2976. 2:30:01loading projects
  2977. 2:30:03and
  2978. 2:30:06when the projects do.length length is
  2979. 2:30:10greater than zero. It means we have the
  2980. 2:30:13projects available then only we will
  2981. 2:30:15display the project here. So we'll add
  2982. 2:30:17and operator and this parenthesis.
  2983. 2:30:20Now within this parenthesis simply add a
  2984. 2:30:23div to display our projects.
  2985. 2:30:27Now in this one we'll add the class name
  2986. 2:30:30and provide margin top and then provide
  2987. 2:30:34the width full.
  2988. 2:30:36Here we have to add one title and uh in
  2989. 2:30:41the right side we'll display the number
  2990. 2:30:43of projects. So let's create one div.
  2991. 2:30:49Here we'll provide the classes that will
  2992. 2:30:52be flex layout to align the title and
  2993. 2:30:54number of projects side by side. So just
  2994. 2:30:57add the P tag for the title. So the
  2995. 2:31:00title is all projects. Then we'll add
  2996. 2:31:04the number of projects in the span tag.
  2997. 2:31:06So just add the span and in this span
  2998. 2:31:10just add the
  2999. 2:31:13projects dot length.
  3000. 2:31:17After that we have to add the text like
  3001. 2:31:21project or projects. So here again use
  3002. 2:31:24this same thing projects.length
  3003. 2:31:28is equal to 1. In this case, we will add
  3004. 2:31:33the string that is project.
  3005. 2:31:37Else we will add the string that is
  3006. 2:31:39projects.
  3007. 2:31:41Now provide the classes here. So start
  3008. 2:31:43with the P tag. In this P tag provide
  3009. 2:31:47the class name and these classes. Then
  3010. 2:31:50we'll add the classes for the span tag.
  3011. 2:31:53So we have added these classes here in
  3012. 2:31:55the span tag. Save the changes and come
  3013. 2:31:58back here. So now it should display the
  3014. 2:32:03all projects and number of projects
  3015. 2:32:05here. So let me refresh this web page
  3016. 2:32:09after reloading the web page. It is not
  3017. 2:32:11displaying the projects here because we
  3018. 2:32:12have to load the project first. We have
  3019. 2:32:14to call that function load project. So
  3020. 2:32:17here in the homepage just add the use
  3021. 2:32:20effect.
  3022. 2:32:23In this use effect add the arrow
  3023. 2:32:25function and a dependency array.
  3024. 2:32:30In the dependency array we will provide
  3025. 2:32:32the load projects. And in the function
  3026. 2:32:36simply call the load projects. Save the
  3027. 2:32:39changes. And now it will call this
  3028. 2:32:42function and then you can see here we
  3029. 2:32:44have all projects at the bottom and two
  3030. 2:32:46projects
  3031. 2:32:48it is visible.
  3032. 2:32:50After that we have to display the list
  3033. 2:32:52of projects. So just come back to the VS
  3034. 2:32:56code. Scroll down
  3035. 2:32:59and uh just after
  3036. 2:33:02this div
  3037. 2:33:05which is here
  3038. 2:33:08let's add a space and here we'll add a
  3039. 2:33:11div
  3040. 2:33:14provide the classes here. So we'll
  3041. 2:33:16provide the space Y2
  3042. 2:33:19then maximum height and overflow and
  3043. 2:33:21padding right. Now use the curly braces
  3044. 2:33:26and projects
  3045. 2:33:28dot map get the individual project in
  3046. 2:33:31this parameter of the arrow function and
  3047. 2:33:35add the parenthesis. So it will directly
  3048. 2:33:38return this div.
  3049. 2:33:40Now for this div we have to add the key
  3050. 2:33:43property and in the key let's add p dot
  3051. 2:33:48id. Then we will add the classes. So
  3052. 2:33:51just add the class name and uh here we
  3053. 2:33:54will add these delvin classes. And next
  3054. 2:33:57we'll add the onclick property here. So
  3055. 2:33:59let's add on click. In this on click we
  3056. 2:34:04will add the add function
  3057. 2:34:06and provide the navigate.
  3058. 2:34:11So let's add the navigate also from use
  3059. 2:34:14navigate.
  3060. 2:34:17We'll add con
  3061. 2:34:20equal to
  3062. 2:34:23use navigate from the react router DOM.
  3063. 2:34:27After that let's come here
  3064. 2:34:30and provide the navigate function and in
  3065. 2:34:33this navigate function we can provide
  3066. 2:34:35our path that will open the project
  3067. 2:34:38page. So just add the back ticks/
  3068. 2:34:44builder/
  3069. 2:34:46dollar sign and curly braces and provide
  3070. 2:34:49the project dot id.
  3071. 2:34:53So it will open this path.
  3072. 2:34:56Now within this we have to add a div
  3073. 2:35:00again.
  3074. 2:35:02So in this first div we'll add the
  3075. 2:35:07project name and then we'll add the
  3076. 2:35:11updated date time and we'll add the
  3077. 2:35:16version and then we'll create the
  3078. 2:35:18another div. So this is the second div
  3079. 2:35:21and in this one we'll add some action
  3080. 2:35:24buttons. So start with the first one. In
  3081. 2:35:27the first one, just add flex one and
  3082. 2:35:30minimum width zero.
  3083. 2:35:34Now create a P tag here. In this P tag,
  3084. 2:35:37we'll add the name. So just add P dot
  3085. 2:35:41name. Now for this name, provide some
  3086. 2:35:44classes. So we have added these TIN
  3087. 2:35:47classes. Next, we'll create a div just
  3088. 2:35:50after this P tag. Here we have to add
  3089. 2:35:53the date, time and clock icon. So just
  3090. 2:35:57add
  3091. 2:35:59these classes and then provide the span
  3092. 2:36:02tag.
  3093. 2:36:05In the span we'll add
  3094. 2:36:07clock icon and import this clock icon
  3095. 2:36:11from Lucid React. And for this icon set
  3096. 2:36:14the size 10
  3097. 2:36:17and after that we have to display the
  3098. 2:36:20time. So just add P dot updated at
  3099. 2:36:27or
  3100. 2:36:29P dot created at and after this span
  3101. 2:36:34we'll create another span tag in this
  3102. 2:36:38we'll add the
  3103. 2:36:40V for version and just add the P dot
  3104. 2:36:44version.
  3105. 2:36:46Now for this version we'll add the
  3106. 2:36:48classes like this and then we'll add the
  3107. 2:36:51classes for the span that contains our
  3108. 2:36:53icon and date time.
  3109. 2:36:56Let's save the changes and open the web
  3110. 2:36:59page. So you can see here we have all
  3111. 2:37:02projects and now you can see the project
  3112. 2:37:04name and below that we have the version
  3113. 2:37:08v1 and here we have the time. So now
  3114. 2:37:10let's update the date time format. For
  3115. 2:37:13that we'll use the moment package that
  3116. 2:37:15is already installed. Right? So just
  3117. 2:37:18import the moment here. Let's scroll up
  3118. 2:37:23and provide import moment from the
  3119. 2:37:26moment package and uh let's come here
  3120. 2:37:31and instead of simply adding this
  3121. 2:37:34p.tupdated and p.treated got created.
  3122. 2:37:37Here we can use moment
  3123. 2:37:41and uh in this moment function let's
  3124. 2:37:44provide this one and at the end we will
  3125. 2:37:47add dot
  3126. 2:37:49from now.
  3127. 2:37:51Save the changes and let's see the
  3128. 2:37:55updated data here. You can see now it is
  3129. 2:37:58displaying the time like 3 hours ago, 1
  3130. 2:38:02day ago.
  3131. 2:38:04It looks good.
  3132. 2:38:07Now we have to display the actions and
  3133. 2:38:09buttons. So just come back and uh we'll
  3134. 2:38:13come here in the another div. So in this
  3135. 2:38:15div again we have to add the flex
  3136. 2:38:18layout. So we have added these classes
  3137. 2:38:20and then we'll add a button. So we'll
  3138. 2:38:22add the button tag and uh after this
  3139. 2:38:27button we have to add the arrow icon. So
  3140. 2:38:29let's add opening arrow arrow right
  3141. 2:38:32icon. Now in this icon we will set the
  3142. 2:38:35size 14.
  3143. 2:38:38Then we will add the classes. So just
  3144. 2:38:41add the class name property and these
  3145. 2:38:42classes.
  3146. 2:38:44After that we have to provide the button
  3147. 2:38:48text here. So instead of adding the text
  3148. 2:38:50here also we'll add the icon that is
  3149. 2:38:53trash icon. So just add the trash icon
  3150. 2:38:56imported from the Lucid React and then
  3151. 2:38:58add the size 14.
  3152. 2:39:01Next, we will add the onclick property
  3153. 2:39:04on this button. And before adding that,
  3154. 2:39:06we'll add the classes. Let's add the
  3155. 2:39:08class name and provide these classes.
  3156. 2:39:13Next, just add the on click.
  3157. 2:39:17In this on click, add the arrow function
  3158. 2:39:21and uh provide the event in the
  3159. 2:39:24parameter
  3160. 2:39:25here. Just add E dot
  3161. 2:39:29a stop propagation
  3162. 2:39:31semicolon and provide the handle delete
  3163. 2:39:35function. In this handle delete, we have
  3164. 2:39:37to provide the project ID. So just add P
  3165. 2:39:39dot ID.
  3166. 2:39:43Let's save the changes. After adding it,
  3167. 2:39:45let's come here. So you can see in the
  3168. 2:39:47right side, we have the arrow icon. When
  3169. 2:39:50we click here, it will change the route.
  3170. 2:39:52It will open the
  3171. 2:39:54builder page where we can update this
  3172. 2:39:56project. And if I hover it, you can see
  3173. 2:39:59here we have the trash icon or delete
  3174. 2:40:02icon so that we can delete this project.
  3175. 2:40:05After that, let me click on this
  3176. 2:40:08project. So you can see it is opening
  3177. 2:40:10the another route that is builder/
  3178. 2:40:14project 1. That is the project ID and
  3179. 2:40:18you can see it is opening the builder
  3180. 2:40:20page. So we can click on any project to
  3181. 2:40:24open the project builder page where we
  3182. 2:40:26can update this project or we can
  3183. 2:40:28publish this project. We can preview the
  3184. 2:40:30project. So we have to design this
  3185. 2:40:32project builder page. But before that
  3186. 2:40:35let me commit these changes and review
  3187. 2:40:37our code. So just come back here.
  3188. 2:40:42Here we'll open the sidebar. Let's click
  3189. 2:40:45on this source control icon. We'll add
  3190. 2:40:47the message. So just add the message
  3191. 2:40:51created homepage
  3192. 2:40:58commit changes and sync changes.
  3193. 2:41:01So it will commit the changes in the
  3194. 2:41:03development branch. After that we'll
  3195. 2:41:06come back to the GitHub.
  3196. 2:41:11Let's open the repository.
  3197. 2:41:14So here you can see this button. Let's
  3198. 2:41:16click on this button compare and pull
  3199. 2:41:18request. So click on this button create
  3200. 2:41:21pull request.
  3201. 2:41:24So once we create a new pull request
  3202. 2:41:27then the code rabbit will start
  3203. 2:41:29analyzing our code. Now you can see the
  3204. 2:41:32code rabbit is running and it is
  3205. 2:41:35analyzing our code and after analysis it
  3206. 2:41:38will display the suggestions, feedback
  3207. 2:41:41and review summary.
  3208. 2:41:45Now our review has been completed by
  3209. 2:41:47code rabbit and here you can see we have
  3210. 2:41:49the review summary. So these are new
  3211. 2:41:53feature added in this update and here we
  3212. 2:41:56have some UI improvements. After that if
  3213. 2:41:59I scroll down you can see we have some
  3214. 2:42:03suggestions. Here we have some minor
  3215. 2:42:05issue for this
  3216. 2:42:08handle submit and uh it is also
  3217. 2:42:12suggesting this fix
  3218. 2:42:15right after that let us scroll and see
  3219. 2:42:17the next issue or suggestions. So here
  3220. 2:42:20we have the major issue. It says
  3221. 2:42:24[snorts] the
  3222. 2:42:26unmemorized load project and uh load
  3223. 2:42:30projects. So it is suggesting to wrap
  3224. 2:42:33this inside the use call back. So we can
  3225. 2:42:35add inside the use call back. And after
  3226. 2:42:38that let's see the next one. Here it
  3227. 2:42:41says it is also critical issue. Here we
  3228. 2:42:44have used the logout function in the
  3229. 2:42:50homepage right and uh it is not exported
  3230. 2:42:54using this value object in the context.
  3231. 2:42:56So we have to insert this log out inside
  3232. 2:42:58the value object in app context. So you
  3233. 2:43:03can see the suggestions and bug fixes
  3234. 2:43:06using this code rabbit. So let me
  3235. 2:43:08implement this one. I'll just come back
  3236. 2:43:10to the VS code and open our app context.
  3237. 2:43:14And uh in this app context
  3238. 2:43:19we have this value object. Here we have
  3239. 2:43:21the login register but we didn't add the
  3240. 2:43:25logout. So just add the comma and
  3241. 2:43:27provide
  3242. 2:43:28log out. Save the changes.
  3243. 2:43:32After that let me just come here and uh
  3244. 2:43:35you can click on this button
  3245. 2:43:38merge pull request
  3246. 2:43:41and confirm merge. After that let's come
  3247. 2:43:45here in the VS code. We'll click on this
  3248. 2:43:47three dot and pull. So it will pull the
  3249. 2:43:49latest changes in the
  3250. 2:43:52VS code.
  3251. 2:43:54So after completing our homepage, next
  3252. 2:43:57we have to create our
  3253. 2:44:00builder page. Let me just come back to
  3254. 2:44:01the application. So you can see this is
  3255. 2:44:04our builder page. So we have to design
  3256. 2:44:06this page.
  3257. 2:44:08To create our builder page, let's open
  3258. 2:44:11the sidebar and here you will find
  3259. 2:44:13builder page. JSX.
  3260. 2:44:16Now in this one, we need some data from
  3261. 2:44:19context. So here
  3262. 2:44:23we will add con
  3263. 2:44:26and extract the data from
  3264. 2:44:29use app context. Use app context has
  3265. 2:44:32been imported. Now from here we'll get
  3266. 2:44:34the active project.
  3267. 2:44:37After that let's get the
  3268. 2:44:40loading active project.
  3269. 2:44:44After that let's get the
  3270. 2:44:48active file
  3271. 2:44:50then we'll get
  3272. 2:44:53so code
  3273. 2:44:55then
  3274. 2:44:56set active file
  3275. 2:44:59after that set so code
  3276. 2:45:02then we'll get the load project to load
  3277. 2:45:05the individual project data then we'll
  3278. 2:45:09get the log out
  3279. 2:45:13and we are getting all these data from
  3280. 2:45:16context. Now after that here we need the
  3281. 2:45:19ID also. So if I open the web page you
  3282. 2:45:22can see we have the ID in the URL right?
  3283. 2:45:24So we have to find the ID from URL. For
  3284. 2:45:27that just add const
  3285. 2:45:31curly braces id
  3286. 2:45:34is equal to
  3287. 2:45:37use padams. So here we are getting the
  3288. 2:45:40id and after that let's get the navigate
  3289. 2:45:43function also. So just add con equal to
  3290. 2:45:48use navigate and uh let's import this
  3291. 2:45:53use navigate from react router DOM.
  3292. 2:45:57After that here we have to create some
  3293. 2:45:59state.
  3294. 2:46:02So I'll provide const left tab and set a
  3295. 2:46:06function set left tab is equal to use a
  3296. 2:46:11state and let's initialize it using
  3297. 2:46:14chat. So we have the initial value chat
  3298. 2:46:18in the left tab. After that we'll add
  3299. 2:46:21the another state. So just duplicate
  3300. 2:46:23this one only. And here we'll add
  3301. 2:46:26a state name called publishing and
  3302. 2:46:29setter function name is set publishing
  3303. 2:46:33and by default it will be false. So just
  3304. 2:46:36change it to false.
  3305. 2:46:38Again duplicate it. Here we'll add the
  3306. 2:46:41next state. So the next state is publish
  3307. 2:46:45URL and the setter function name is set
  3308. 2:46:47publish URL.
  3309. 2:46:50So let's initialize it using null. So
  3310. 2:46:54the publish URL will be null by default.
  3311. 2:46:57Save the changes. Now after that we have
  3312. 2:47:00to load the project data. For that here
  3313. 2:47:04we will add one use effect.
  3314. 2:47:08In the use effect create the arrow
  3315. 2:47:10function and provide a dependency array.
  3316. 2:47:13Now within this function first we'll
  3317. 2:47:16check the ID is available or not. So if
  3318. 2:47:18I add not of id in this case simply add
  3319. 2:47:22return and stop the execution of this
  3320. 2:47:24function. Now suppose the id is
  3321. 2:47:27available in this case we will use the
  3322. 2:47:29load project and provide the parameter
  3323. 2:47:32that is ID.
  3324. 2:47:34Now after that here let's add the
  3325. 2:47:37dependency. So in the dependency we will
  3326. 2:47:39add the id and load project. So if any
  3327. 2:47:42of this changes it will again reload the
  3328. 2:47:46project data.
  3329. 2:47:48Now after that we'll add another use
  3330. 2:47:50effect. So I'm going to copy this one
  3331. 2:47:52only. Paste it here.
  3332. 2:47:55Here in this one we'll add if not of id
  3333. 2:48:00or
  3334. 2:48:02not of
  3335. 2:48:04active project.
  3336. 2:48:06In this case we'll add the return and
  3337. 2:48:08after that we'll add next if statement.
  3338. 2:48:12Again we'll add the if and here we'll
  3339. 2:48:14use the active project
  3340. 2:48:17dot status. So we'll check the status of
  3341. 2:48:21our active project. So if the status is
  3342. 2:48:24equal to pending or
  3343. 2:48:28active project dot a status is equal to
  3344. 2:48:31generating.
  3345. 2:48:33So in this case we have to wait for few
  3346. 2:48:36more seconds. So let's add
  3347. 2:48:41const
  3348. 2:48:42interval equal to
  3349. 2:48:45set interval.
  3350. 2:48:48In the set interval create the arrow
  3351. 2:48:51function and provide the time 1500
  3352. 2:48:54milliseconds.
  3353. 2:48:56And here let's add the load project
  3354. 2:48:58again. In the load project provide the
  3355. 2:49:01ID and comma true. Now after that here
  3356. 2:49:05we can add the return
  3357. 2:49:09and in the return simply add the arrow
  3358. 2:49:12function that will call our clear
  3359. 2:49:14interval.
  3360. 2:49:16In the clear interval provide the
  3361. 2:49:18interval
  3362. 2:49:20that is available here and now update
  3363. 2:49:23the dependency here. So in the
  3364. 2:49:25dependency we have added the id then
  3365. 2:49:28load project and then we'll add comma
  3366. 2:49:32active project. So now it will fetch the
  3367. 2:49:36individual project data and we'll get
  3368. 2:49:38the project ID from the padams.
  3369. 2:49:41After that we can display these data on
  3370. 2:49:44our web page. So let's scroll down and
  3371. 2:49:49here we have the return statement. But
  3372. 2:49:51before this return, let's add one if
  3373. 2:49:53statement. And here we'll add if
  3374. 2:49:58loading active project or not of active
  3375. 2:50:03project.
  3376. 2:50:05So if the active project is still
  3377. 2:50:07loading or project is not available, it
  3378. 2:50:11means active project is not available.
  3379. 2:50:12So in this case, simply add the return
  3380. 2:50:15and we'll return the loading component.
  3381. 2:50:17So let's add the loading and import it
  3382. 2:50:20from the components folder. It has been
  3383. 2:50:22mounted. Save the changes. So if the
  3384. 2:50:26project is loading then it will display
  3385. 2:50:28the loading component. Else it will come
  3386. 2:50:31to this another return statement and
  3387. 2:50:33here we will clear this text and let's
  3388. 2:50:37add some classes for the parent div. So
  3389. 2:50:40here we'll set the height using height
  3390. 2:50:42screen and flex layout with the
  3391. 2:50:46background white and uh we'll add the
  3392. 2:50:49text color and relative. Now within this
  3393. 2:50:51we have to add the header section of our
  3394. 2:50:55builder page. So to display the header
  3395. 2:50:58we will create a separate component. For
  3396. 2:51:00that let me just add one comment here
  3397. 2:51:03that is top bar or header. Right. And
  3398. 2:51:08after that we'll add the next command
  3399. 2:51:09that is main layout. So we have to add
  3400. 2:51:11the header and then main layout. And to
  3401. 2:51:15create this header let's create a new
  3402. 2:51:18component.
  3403. 2:51:20So let me open the sidebar components
  3404. 2:51:23folder. And in the components folder
  3405. 2:51:25create a file called builder header.jsx.
  3406. 2:51:29Let's add rafce for creating the
  3407. 2:51:31component structure. And here we will
  3408. 2:51:34dstructure some data from props. So
  3409. 2:51:37let's add curly braces
  3410. 2:51:39and here we will restructure the project
  3411. 2:51:42name after that
  3412. 2:51:45version
  3413. 2:51:47then so code
  3414. 2:51:51after that publishing
  3415. 2:51:54then on toggle so code
  3416. 2:51:59then on open preview
  3417. 2:52:03then on publish then on download
  3418. 2:52:09then on back and on log out.
  3419. 2:52:13So we'll destructure these data from
  3420. 2:52:15props and let's come here in the return.
  3421. 2:52:18In the return we will remove this div
  3422. 2:52:21and we will use the header tag.
  3423. 2:52:25So we have added the header opening and
  3424. 2:52:27closing tag. In this header tag just add
  3425. 2:52:30some TIN classes like this. Now after
  3426. 2:52:34that we'll create a div where we will
  3427. 2:52:36add the back arrow icon. Then we'll add
  3428. 2:52:39the logo then project name and version.
  3429. 2:52:43So to group all these we'll create a div
  3430. 2:52:48and provide the flex layout for this
  3431. 2:52:51div. Now in this div first we have to
  3432. 2:52:54add a button tag where we will insert
  3433. 2:52:57the back arrow icon. So let's add the
  3434. 2:53:00arrow left icon
  3435. 2:53:05from the Lucid React and in this icon
  3436. 2:53:08set the size 16. Next we'll add the
  3437. 2:53:11classes in this button. So in this
  3438. 2:53:14button tag provide these Telvin classes.
  3439. 2:53:17Next we'll add the on click. So let's
  3440. 2:53:20add on click and in this on click
  3441. 2:53:24we have to provide on back. After this
  3442. 2:53:29button we have to add our logo. To
  3443. 2:53:31insert the logo we will use the image
  3444. 2:53:33tag. And in this image src
  3445. 2:53:36let's add / logo. SVG. So this SVG file
  3446. 2:53:42is available in the public folder. After
  3447. 2:53:45that provide the classes for this logo.
  3448. 2:53:48So we have added the invert and size
  3449. 2:53:50five. Next we have to add the project
  3450. 2:53:53name. So insert one span tag. In this
  3451. 2:53:57span tag just add curly braces and
  3452. 2:54:00provide the project name.
  3453. 2:54:03Then we'll add the classes. In this
  3454. 2:54:05project name. So we have added these
  3455. 2:54:08classes. And then again one span tag. In
  3456. 2:54:11this one we have to add the version. So
  3457. 2:54:13just add the
  3458. 2:54:15version. And before that we'll add V. So
  3459. 2:54:18we'll add some classes for this version
  3460. 2:54:20also. So just add these classes. Save
  3461. 2:54:24the changes. So we have added this
  3462. 2:54:28row with the back arrow icon, logo,
  3463. 2:54:31project name and version.
  3464. 2:54:33Now we'll add another div. So create
  3465. 2:54:37another div here. In this one provide
  3466. 2:54:40the flex layout again. So we have added
  3467. 2:54:44flex item center gap 1.5.
  3468. 2:54:48After that here we have to add a button.
  3469. 2:54:51In this button we will add the toggle
  3470. 2:54:54option to
  3471. 2:54:56display the code or hide the code. So
  3472. 2:55:00let me provide button tag. In this
  3473. 2:55:03button tag we will use the turnary
  3474. 2:55:05operator. So just add the so code state.
  3475. 2:55:08If it is true then we'll add the
  3476. 2:55:10parenthesis and fragment. Within this
  3477. 2:55:13fragment just add the I
  3478. 2:55:17icon
  3479. 2:55:19imported from Lucid React and in this I
  3480. 2:55:23icon we'll add the size. So just add the
  3481. 2:55:25size 13 and just after this icon we have
  3482. 2:55:29to add the text also that is preview.
  3483. 2:55:32Now after that we'll add the else
  3484. 2:55:33statement. So here we'll add colon and
  3485. 2:55:36another parenthesis and just copy this
  3486. 2:55:39one. Paste it here. Here we'll add the
  3487. 2:55:42code to icon and import this icon from
  3488. 2:55:45Lucid React. Here we'll add the text
  3489. 2:55:48called code.
  3490. 2:55:50Now we have to add the classes in this
  3491. 2:55:52button and one
  3492. 2:55:55function. So just add the onclick
  3493. 2:55:57property and uh in this on click provide
  3494. 2:56:01our function that is on toggle. flow
  3495. 2:56:03code
  3496. 2:56:04then provide the classes. So we have to
  3497. 2:56:06add the dynamic classes. So let's add
  3498. 2:56:09the curly braces and back tick in this
  3499. 2:56:13one.
  3500. 2:56:14Let me provide the fixed classes first.
  3501. 2:56:17So we have added these fixed classes
  3502. 2:56:22and after that insert the
  3503. 2:56:25dynamic classes using dollar sign curly
  3504. 2:56:27braces and just use the so code state.
  3505. 2:56:29If it is true then provide background
  3506. 2:56:34and text color. Else we will add the
  3507. 2:56:38empty string. So just add colon empty
  3508. 2:56:40string. Save the changes. So we have
  3509. 2:56:44added one button for the toggle code
  3510. 2:56:47view. Next we'll add the another button.
  3511. 2:56:51Using that we can display the preview.
  3512. 2:56:54So after closing up this button create
  3513. 2:56:56another button.
  3514. 2:56:59We have added another button tag. In
  3515. 2:57:01this second button we'll add on click
  3516. 2:57:04property. In this on click just add on
  3517. 2:57:07open preview.
  3518. 2:57:09Then add the classes. So we have added
  3519. 2:57:12the class name property and these
  3520. 2:57:14classes.
  3521. 2:57:16Now here we have to add the icon. So
  3522. 2:57:19let's add the opening arrow and provide
  3523. 2:57:21external link icon from Lucid React.
  3524. 2:57:27Then add the size 13
  3525. 2:57:30and just after this icon we'll add the
  3526. 2:57:33text also that is open preview.
  3527. 2:57:35So we have added the button for open
  3528. 2:57:38preview.
  3529. 2:57:39Now we'll add the next button. So here
  3530. 2:57:43we'll add a space and provide the button
  3531. 2:57:46tag again.
  3532. 2:57:48And this button we'll add on click and
  3533. 2:57:51simply add on publish.
  3534. 2:57:55After that we'll add disabled.
  3535. 2:57:58So this button will be disabled when the
  3536. 2:58:00publishing is true. So just add
  3537. 2:58:03publishing.
  3538. 2:58:06Then we'll add the classes. So let's add
  3539. 2:58:08the class name property. And we have
  3540. 2:58:12added these classes.
  3541. 2:58:14Now here we'll add the curly braces and
  3542. 2:58:16use the publishing state. If the
  3543. 2:58:19publishing is true in this case we have
  3544. 2:58:21to add the loading animation. So just
  3545. 2:58:24add the loader to icon from Lucid React
  3546. 2:58:29and uh provide the size and animation
  3547. 2:58:33using class name animate a spin and if
  3548. 2:58:36it is false then add the colon and
  3549. 2:58:39provide the
  3550. 2:58:42globe icon.
  3551. 2:58:45Import this icon from Lucid React and
  3552. 2:58:47with this icon provide the size 13.
  3553. 2:58:50That's it. And after that we'll add the
  3554. 2:58:54space here and provide publish.
  3555. 2:58:58Save the changes. So we have added the
  3556. 2:59:00button for publish. And if the
  3557. 2:59:02publishing is true, it will display the
  3558. 2:59:04loading animation inside the button.
  3559. 2:59:07After that we have to add the button for
  3560. 2:59:10download. Using that we can download the
  3561. 2:59:12code. So after this button add another
  3562. 2:59:16one.
  3563. 2:59:18In this one add on click.
  3564. 2:59:21In this on click add on download.
  3565. 2:59:26Then add the class name. And uh here we
  3566. 2:59:30have added the same classes. And after
  3567. 2:59:34that let's add the icon. So I'll just
  3568. 2:59:38copy this icon
  3569. 2:59:40and text paste it here. Let's update our
  3570. 2:59:44icon. So we'll add download icon and
  3571. 2:59:47import it from lucid react. Size will be
  3572. 2:59:5013 and the text will be export.
  3573. 2:59:53Correct. Now after that we'll add the
  3574. 2:59:56last button. So let me just duplicate
  3575. 2:59:59this button only.
  3576. 3:00:02Here we'll add on click. It will be on
  3577. 3:00:05log out.
  3578. 3:00:08Then the classes will be same. And just
  3579. 3:00:11update the button text. It will be sign
  3580. 3:00:13out. So remove this icon and simply add
  3581. 3:00:16sign out. Save the changes. So we have
  3582. 3:00:18created this complete component and now
  3583. 3:00:21we'll mount this component on our
  3584. 3:00:23builder page. So we will open the
  3585. 3:00:24builder.jsx
  3586. 3:00:26and here only we will add
  3587. 3:00:29builder
  3588. 3:00:32header from the components.
  3589. 3:00:36After that here we have to provide the
  3590. 3:00:39props. So first we'll add the project
  3591. 3:00:41name. So in this project name just add
  3592. 3:00:44the
  3593. 3:00:46active project dot name.
  3594. 3:00:51Then we'll add the version.
  3595. 3:00:54In the version just add
  3596. 3:00:56active project
  3597. 3:00:59dot version.
  3598. 3:01:02After that we'll add the so code.
  3599. 3:01:05In the so code provide the same so code.
  3600. 3:01:09Then we'll add the publishing.
  3601. 3:01:13Here also we'll add the publishing.
  3602. 3:01:17After that we'll add the on toggle so
  3603. 3:01:20code. It will be one adder function
  3604. 3:01:26and provide set so code
  3605. 3:01:30provide not of so code.
  3606. 3:01:35Next we'll add on open preview.
  3607. 3:01:39In this on open preview we'll add a
  3608. 3:01:42function. So let me create that function
  3609. 3:01:44first. That is handle open preview.
  3610. 3:01:47Let's add it here
  3611. 3:01:50con handle open
  3612. 3:01:54preview.
  3613. 3:01:55It will be one add function. In this
  3614. 3:01:58handle open preview let's add if
  3615. 3:02:02statement. If
  3616. 3:02:06not of id then simply add return
  3617. 3:02:12else we'll add the window dot open and
  3618. 3:02:17uh provide the
  3619. 3:02:20path. So just add back text / preview/
  3620. 3:02:25dollar sign curly braces and provide our
  3621. 3:02:28id. So it will open this path. Then
  3622. 3:02:31we'll add comma
  3623. 3:02:35blank. So we have added handle open
  3624. 3:02:38preview and let's provide this function
  3625. 3:02:40here in on open preview.
  3626. 3:02:44After that we'll add on publish.
  3627. 3:02:48So just add on publish.
  3628. 3:02:53In this one we will add the
  3629. 3:02:56next function that is handle publish. So
  3630. 3:03:00let's add this handle publish here using
  3631. 3:03:04the con
  3632. 3:03:06handle publish equal to
  3633. 3:03:09async arrow function. Let's keep this
  3634. 3:03:12function empty for now. And uh after
  3635. 3:03:15that let's add the function here that is
  3636. 3:03:18handle publish.
  3637. 3:03:20Now we'll add our next props. So it will
  3638. 3:03:24be on download
  3639. 3:03:28equal to and in this on download we'll
  3640. 3:03:31add the handle download and let's create
  3641. 3:03:34this handle download also. So just
  3642. 3:03:36duplicate this one
  3643. 3:03:38write the name handle download. Let me
  3644. 3:03:42remove this.
  3645. 3:03:45So we have added handle download
  3646. 3:03:46function here. And uh let's add our
  3647. 3:03:51next props. So the next props is on
  3648. 3:03:54back.
  3649. 3:03:56In this on back we'll add the arrow
  3650. 3:03:59function. Simply call our navigate
  3651. 3:04:03function and provide the path. It will
  3652. 3:04:05be slash that is the homepage.
  3653. 3:04:08Now we'll add on
  3654. 3:04:10logout. In this on logout we will call
  3655. 3:04:14our logout function.
  3656. 3:04:16Save the changes. After mounting this
  3657. 3:04:19component and providing all the props,
  3658. 3:04:21let me just open our web page.
  3659. 3:04:24After opening this web page, you can see
  3660. 3:04:26the top bar is continuously reloading.
  3661. 3:04:31So, let me just come back here in the VS
  3662. 3:04:33code and uh here you can see we have
  3663. 3:04:37added this use effect where we are
  3664. 3:04:39loading the project using load project.
  3665. 3:04:42So from here we will just remove this
  3666. 3:04:44dependency called load project. Save the
  3667. 3:04:47changes and come back here. Now you can
  3668. 3:04:50see here we have the top bar where you
  3669. 3:04:52can see the back arrow icon. Then our
  3670. 3:04:55logo and then we have the project name
  3671. 3:05:00and then we have the version v1. In the
  3672. 3:05:03right side we have this button for code
  3673. 3:05:06that will toggle the
  3674. 3:05:09state.
  3675. 3:05:11Then we have the open preview. Then
  3676. 3:05:13publish, export and sign out.
  3677. 3:05:16After that we have to display our main
  3678. 3:05:18content. So we'll divide this main
  3679. 3:05:21content area in two part in the left and
  3680. 3:05:23right side. So just come back to the VS
  3681. 3:05:26code.
  3682. 3:05:28Scroll down.
  3683. 3:05:30Here you can see we have this main
  3684. 3:05:32layout. So under this main layout create
  3685. 3:05:35a div
  3686. 3:05:37and create the flex layout here. So we
  3687. 3:05:40have added flex
  3688. 3:05:43then overflow hidden and here we have
  3689. 3:05:45added flex once. So it will use the
  3690. 3:05:47entire space available in the row. Then
  3691. 3:05:50we have to add the layout in two column
  3692. 3:05:55in the left and right side. So just add
  3693. 3:05:57the comment for left sidebar.
  3694. 3:06:00After that we'll add the comment here
  3695. 3:06:02that is preview or code area. So here we
  3696. 3:06:06have to add the sidebar and in the right
  3697. 3:06:09side we'll display the preview of the
  3698. 3:06:11generated project or we can display the
  3699. 3:06:14code also. So let's start adding the
  3700. 3:06:18content in the left sidebar. So in this
  3701. 3:06:20left sidebar create a div
  3702. 3:06:24and uh for this div we'll set the width.
  3703. 3:06:26It will be 320 pixel. Then we'll add the
  3704. 3:06:31shrink zero flex flex column border
  3705. 3:06:34right and uh border color and
  3706. 3:06:37background.
  3707. 3:06:38Now in this one we have to add the tabs.
  3708. 3:06:41So just add the comment that is sidebar
  3709. 3:06:45tabs and here create a div.
  3710. 3:06:49Now in this div just use the flex layout
  3711. 3:06:54provide the border
  3712. 3:06:56bottom and border color. Here we have to
  3713. 3:07:00add the button for each tabs. So just
  3714. 3:07:02add the button here and uh in this
  3715. 3:07:05button we will add the icon. So let's
  3716. 3:07:09add message squared icon and import this
  3717. 3:07:13icon from Lucid React. Next provide the
  3718. 3:07:16size for this icon. And after adding the
  3719. 3:07:19size we have to add the text. So the
  3720. 3:07:22text is chat.
  3721. 3:07:25After that here we will add the on click
  3722. 3:07:28property. Let's add the on click. And in
  3723. 3:07:31this on click we will add the
  3724. 3:07:35add function. And in this add a function
  3725. 3:07:40we will use one
  3726. 3:07:43setter function that is already created
  3727. 3:07:45above. So just add set
  3728. 3:07:48left tab
  3729. 3:07:50and let's add the value here. So the
  3730. 3:07:52value will be chat. After that we have
  3731. 3:07:55to add some classes in this first
  3732. 3:07:58button. So provide the class name
  3733. 3:08:01property and insert the dynamic classes
  3734. 3:08:05using this template lit. So just add the
  3735. 3:08:09fixed classes first. So we have added
  3736. 3:08:11these fixed classes. Then insert the
  3737. 3:08:13template lit like this. Here we'll add
  3738. 3:08:16the left tab equal to chat if it is
  3739. 3:08:19true. In this case just provide these
  3740. 3:08:25text color border color and uh border.
  3741. 3:08:30Then we'll add the colon for else. Here
  3742. 3:08:34we'll update the color for
  3743. 3:08:39left tab. Save the changes.
  3744. 3:08:42Now after adding it if I come back here
  3745. 3:08:45you can see here we have the left
  3746. 3:08:46sidebar where you can see the first tab
  3747. 3:08:48that is chat
  3748. 3:08:50right now after that let me just come
  3749. 3:08:53here and just duplicate this button. So
  3750. 3:08:57we have added another button in this
  3751. 3:08:59second button we'll add the
  3752. 3:09:02left tab or set left tab it will be
  3753. 3:09:06files. So in the left side we can
  3754. 3:09:09display the chat or we can display the
  3755. 3:09:11files
  3756. 3:09:13right now after that here we will use
  3757. 3:09:15the classes again. So here also we have
  3758. 3:09:18to add some dynamic classes. So let's
  3759. 3:09:21update it like this.
  3760. 3:09:28Now we'll update the icon. So it will be
  3761. 3:09:30folder tree icon. Import this icon from
  3762. 3:09:34Lucid React. And then we'll add the
  3763. 3:09:37text. So the text will be files. Now let
  3764. 3:09:40me just come here. You can see here we
  3765. 3:09:42have chat and files.
  3766. 3:09:46Let's click here. So the files is
  3767. 3:09:48enabled. If I click here, the chat is
  3768. 3:09:50enabled.
  3769. 3:09:52Now after that,
  3770. 3:09:55let's come back here and here we'll add
  3771. 3:09:58the next comment just after this div.
  3772. 3:10:02So provide the comment that is sidebar
  3773. 3:10:05content.
  3774. 3:10:07So just below this sidebar content
  3775. 3:10:10create a div.
  3776. 3:10:12In this one we'll add the flex one
  3777. 3:10:14overflow hidden.
  3778. 3:10:16Then we'll use the turnary operator.
  3779. 3:10:19Let's add curly braces.
  3780. 3:10:23Left tab is equal to
  3781. 3:10:27chat. So if the left tab is equal to
  3782. 3:10:30chat in this case we'll add question
  3783. 3:10:33mark parenthesis and uh here we have to
  3784. 3:10:36display the chat panel. So let's add a
  3785. 3:10:39div
  3786. 3:10:44and add the text chat panel.
  3787. 3:10:53After that we'll add the
  3788. 3:10:56colon parenthesis. And here we'll add
  3789. 3:10:59another div.
  3790. 3:11:01Here we have to display the file
  3791. 3:11:04explorer.
  3792. 3:11:06So let's add the text called file
  3793. 3:11:09explorer like this. Save the changes and
  3794. 3:11:12we'll come back here. So now you can see
  3795. 3:11:14it is displaying the chat panel here. If
  3796. 3:11:16I click on files, it is displaying file
  3797. 3:11:18explorer.
  3798. 3:11:19So we have to create the separate
  3799. 3:11:20component for chat panel. and uh file
  3800. 3:11:23exploder that will be displayed here.
  3801. 3:11:27To create these components, let me just
  3802. 3:11:29come back to the VS code and uh here
  3803. 3:11:35let's create a new component called chat
  3804. 3:11:38panel. So just open the sidebar
  3805. 3:11:40components and in this folder create a
  3806. 3:11:43new file chat panel dot jsx right rafce
  3807. 3:11:49for creating the component structure.
  3808. 3:11:51Now in this one we'll destructure some
  3809. 3:11:54props. So we'll get the messages that
  3810. 3:11:57will be displayed in the chat area. Then
  3811. 3:12:00we'll add the function on send and uh
  3812. 3:12:04then we'll add the loading.
  3813. 3:12:07After that we have to scroll the chat
  3814. 3:12:12section when a new message comes. Right?
  3815. 3:12:14So we have to add one reference. So just
  3816. 3:12:17add const bottom ref equal to use ref
  3817. 3:12:25and get this use ref from react and
  3818. 3:12:28initialize it using null. Now after that
  3819. 3:12:31here we'll add one use effect also. So
  3820. 3:12:35just add use effect. In this use effect
  3821. 3:12:39add the add function and provide the
  3822. 3:12:41dependency array. In the dependency
  3823. 3:12:43array just add the messages. So when the
  3824. 3:12:46messages are changing it will scroll the
  3825. 3:12:50chat box then we'll add the loading
  3826. 3:12:52also. Now in this function just use the
  3827. 3:12:56bottom reference dot current
  3828. 3:13:00dot scroll into view and here we will
  3829. 3:13:04add the
  3830. 3:13:06behavior it will be auto.
  3831. 3:13:10So it will scroll the chat box at the
  3832. 3:13:13bottom. Now come here in the return. In
  3833. 3:13:15this return we'll create a div.
  3834. 3:13:18So we already have this div and in this
  3835. 3:13:21div we have to add the flex layout with
  3836. 3:13:23the white background. Then we'll display
  3837. 3:13:26the messages. So just add the messages
  3838. 3:13:29comment here and uh after displaying the
  3839. 3:13:33messages we have to add one input field
  3840. 3:13:35also. So let's add the comment here for
  3841. 3:13:38input. Using this input field we can add
  3842. 3:13:41our new chat message. So first we'll
  3843. 3:13:44display the messages. So here under this
  3844. 3:13:46messages command create a div. Let's add
  3845. 3:13:50some classes in this div. So we have
  3846. 3:13:52added these telin classes. And after
  3847. 3:13:55that let's use the messages array. So
  3848. 3:13:59just add the messages dot length is
  3849. 3:14:03equal to zero and
  3850. 3:14:07parenthesis and here provide a div. So
  3851. 3:14:11if the messages length is zero in this
  3852. 3:14:13case we have to display one message. So
  3853. 3:14:18let's wrap this message inside a div and
  3854. 3:14:21add these classes
  3855. 3:14:23and within this div create the message
  3856. 3:14:27in p tag. Now in this p tag we'll add
  3857. 3:14:30the message ask AI to modify your
  3858. 3:14:33website.
  3859. 3:14:36Then provide the classes here. So we
  3860. 3:14:39have added these classes for the text
  3861. 3:14:41which is in P tag.
  3862. 3:14:44Now after that let's come here. Here we
  3863. 3:14:47will again add the curly braces and
  3864. 3:14:50messages
  3865. 3:14:52dot map.
  3866. 3:14:56In this map add the arrow function
  3867. 3:15:00and simply add this parenthesis. Now in
  3868. 3:15:03this parameter we'll get the individual
  3869. 3:15:05message and index number that is I
  3870. 3:15:09and simply return a div. Now in this div
  3871. 3:15:13we have to add the key property. So the
  3872. 3:15:16key will be our index.
  3873. 3:15:19Then we'll add the
  3874. 3:15:21another div here. Here we'll add the
  3875. 3:15:24flex then gap and item start.
  3876. 3:15:29Now let's create two other div here like
  3877. 3:15:32this.
  3878. 3:15:35Now in the first one
  3879. 3:15:37we have to add these classes.
  3880. 3:15:42And here we will check the
  3881. 3:15:45role. So just add curly braces.
  3882. 3:15:48This message dot role property
  3883. 3:15:53is equal to user.
  3884. 3:15:56So if the role is equal to user in this
  3885. 3:15:59case just add this parenthesis and here
  3886. 3:16:02we will add the user icon. So just add
  3887. 3:16:05the user icon from Lucid React and
  3888. 3:16:08provide the size here it will be 14 and
  3889. 3:16:12then provide some classes. So just add
  3890. 3:16:14the text zinc 500 and if it is not equal
  3891. 3:16:18to user then we'll add the another
  3892. 3:16:20parenthesis and provide the another
  3893. 3:16:23icon. So just add bot message square
  3894. 3:16:27icon and import this icon from Lucid
  3895. 3:16:29React and provide the same size and uh
  3896. 3:16:32color. So we have added the size and
  3897. 3:16:34color for this one. Now after closing up
  3898. 3:16:38this div
  3899. 3:16:40here we have another div. In this one we
  3900. 3:16:44have to display the name like U or AI.
  3901. 3:16:48So just add the
  3902. 3:16:51flex layout and provide the text in P.
  3903. 3:16:55We have added the P tag. So in this P
  3904. 3:16:57tag just add the message
  3905. 3:17:02dot ro.
  3906. 3:17:05So if the role is equal to user
  3907. 3:17:10in this case we will display U.
  3908. 3:17:18else we will display AI
  3909. 3:17:20and for this P we will add some classes.
  3910. 3:17:24So we have added these classes and uh
  3911. 3:17:26after that let's add another P tag in
  3912. 3:17:30this another P
  3913. 3:17:32provide the classes
  3914. 3:17:36like this
  3915. 3:17:38and within this P provide the curly
  3916. 3:17:40braces
  3917. 3:17:43message dot
  3918. 3:17:46content
  3919. 3:17:48dot
  3920. 3:17:50split It
  3921. 3:17:54provide the
  3922. 3:17:57dash
  3923. 3:17:59back slash
  3924. 3:18:02in the double quote.
  3925. 3:18:05Here we have to add the space also.
  3926. 3:18:06After this dash
  3927. 3:18:09then we'll add
  3928. 3:18:11dot map.
  3929. 3:18:15In this map provide the text and index
  3930. 3:18:21here. Let's add a span tag.
  3931. 3:18:24So we have added the span and provide
  3932. 3:18:27the key. Key will be index.
  3933. 3:18:31And after that we'll add the class name
  3934. 3:18:34and provide the block and margin top.
  3935. 3:18:41Then we'll add the another aspan
  3936. 3:18:44in this aspan provide the
  3937. 3:18:48dash space back slash and then we'll add
  3938. 3:18:52the class name here. So in this class
  3939. 3:18:55name we'll add curly braces
  3940. 3:18:59I equal to zero then hidden else empty
  3941. 3:19:02string and after this aspan
  3942. 3:19:05let's add curly braces text. Save the
  3943. 3:19:09changes.
  3944. 3:19:12Now let's come here and here we'll add
  3945. 3:19:15curly braces loading. If the loading is
  3946. 3:19:18true in this case just add a div. For
  3947. 3:19:23this divide
  3948. 3:19:26the flex gap 2.5 and item start.
  3949. 3:19:32After that we will display the bot icon
  3950. 3:19:36and then we'll display some loader
  3951. 3:19:39icons. So let's create one div and
  3952. 3:19:42inside this div we'll add the bot icon
  3953. 3:19:46from lucid react for this icon. Just set
  3954. 3:19:49the size
  3955. 3:19:5113 and provide the class name and add
  3956. 3:19:55the text zinc 900 and provide the
  3957. 3:19:59classes in the div also that contains
  3958. 3:20:01this icon. So in this div we have added
  3959. 3:20:04these classes. Now here we'll add
  3960. 3:20:07another div.
  3961. 3:20:10In this one simply add flex one. Then
  3962. 3:20:13we'll add the text inp tag. So the text
  3963. 3:20:17is
  3964. 3:20:21AI
  3965. 3:20:23and provide the classes in this text. So
  3966. 3:20:26we have added these classes and then
  3967. 3:20:29we'll create one div. Inside this div
  3968. 3:20:32create multiple spans. So just copy and
  3969. 3:20:35paste it.
  3970. 3:20:37Now here we'll add the class name called
  3971. 3:20:40dot loader. Let's add the class name
  3972. 3:20:43here dot loader. Save the changes. After
  3973. 3:20:47that here
  3974. 3:20:49just before this
  3975. 3:20:51closing div
  3976. 3:20:55and it will be self-closing div
  3977. 3:20:59and provide the reference and the
  3978. 3:21:02reference will be bottom ref that will
  3979. 3:21:05help us to scroll the chat area
  3980. 3:21:08right and uh after that let's come here
  3981. 3:21:12and here we'll display our input field.
  3982. 3:21:14So simply add a div and in this div
  3983. 3:21:17provide some classes like this and then
  3984. 3:21:21we have to add our
  3985. 3:21:23component. So we have already created
  3986. 3:21:25this
  3987. 3:21:28prompt input component.
  3988. 3:21:31It has been imported. And here we'll add
  3989. 3:21:33the
  3990. 3:21:34props that is on submit. It will be on
  3991. 3:21:38send. Then loading. It will be
  3992. 3:21:43loading. Then we'll add the
  3993. 3:21:47placeholder. So just add the text ask AI
  3994. 3:21:50to modify.
  3995. 3:21:54Then we'll add
  3996. 3:21:57autofocus.
  3997. 3:21:58That's it. Save the changes. So we have
  3998. 3:22:01created one component here. Now let's
  3999. 3:22:04mount this component on our builder
  4000. 3:22:06page. So just open the builder page.
  4001. 3:22:08JSX. And here you can see we have the
  4002. 3:22:11text called chat panel. So just remove
  4003. 3:22:14this text and simply mount our
  4004. 3:22:19chat panel component. It has been
  4005. 3:22:21mounted here. And provide the messages.
  4006. 3:22:25It will be active project dot
  4007. 3:22:29messages. Then add on send. In this on
  4008. 3:22:33send we'll add one function that will
  4009. 3:22:36handle chat. So let's create this
  4010. 3:22:39function first.
  4011. 3:22:42So
  4012. 3:22:44let's come here.
  4013. 3:22:47We'll add con
  4014. 3:22:51handle chat.
  4015. 3:22:53For now we are creating this function
  4016. 3:22:55here. But later we'll create this
  4017. 3:22:57function in context and get it from the
  4018. 3:23:01app context. So let's provide this
  4019. 3:23:04handle chat here.
  4020. 3:23:08And uh after that let me add one more
  4021. 3:23:11props that is loading. So it will be
  4022. 3:23:16chat loading.
  4023. 3:23:19So we don't have the chat loading. So
  4024. 3:23:22let's create this variable also.
  4025. 3:23:26Let's add con
  4026. 3:23:31chat loading.
  4027. 3:23:33set chat loading
  4028. 3:23:38equal to
  4029. 3:23:39user state and uh by default it will be
  4030. 3:23:45false.
  4031. 3:23:47So let's add chat loading here.
  4032. 3:23:50Now let me just come here and you can
  4033. 3:23:52see here we have the chatter screen
  4034. 3:23:55where you can see two messages by you
  4035. 3:23:57and by AI.
  4036. 3:24:00Correct? And here we have the input
  4037. 3:24:03field where we can submit our query.
  4038. 3:24:08Now let me provide our function or we
  4039. 3:24:12will complete this function which is
  4040. 3:24:15here that is handle chat and this chat
  4041. 3:24:19loading. So let me just remove it from
  4042. 3:24:21here
  4043. 3:24:23and open our app context. In this app
  4044. 3:24:26context
  4045. 3:24:27here we have the chat loading right. So
  4046. 3:24:29we can simply get this chat loading from
  4047. 3:24:31this context. So just add comma and
  4048. 3:24:34provide chat loading. And after that in
  4049. 3:24:36this context we'll create our function
  4050. 3:24:39to load the chat
  4051. 3:24:44or handle the chat.
  4052. 3:24:46So scroll down
  4053. 3:24:48after this
  4054. 3:24:52load project we have the use effect then
  4055. 3:24:56handle generate then handle delete. So
  4056. 3:24:59after this handle delete let's add con
  4057. 3:25:04handle chat
  4058. 3:25:07equal to use call back.
  4059. 3:25:11In this use call back just add the
  4060. 3:25:14asynchronous add function
  4061. 3:25:17and after this function we'll add comma
  4062. 3:25:20and provide the array where we'll add
  4063. 3:25:23active project
  4064. 3:25:26user.
  4065. 3:25:28Now in this function just add the prompt
  4066. 3:25:33as parameter and then
  4067. 3:25:37let's add if statement. If not of active
  4068. 3:25:41project or not of user then simply add
  4069. 3:25:46return
  4070. 3:25:49then we'll use the setup function set
  4071. 3:25:52chat loading and make it true.
  4072. 3:25:57After that we'll add the try catch. So
  4073. 3:26:00we have added the try catch statement.
  4074. 3:26:01In this try block we'll make the API
  4075. 3:26:04call. So just add con data equal to
  4076. 3:26:06await and use the API dot
  4077. 3:26:10post. In this one just add the back
  4078. 3:26:13ticks and provide the / API/ projects
  4079. 3:26:17and provide the project id using this
  4080. 3:26:20dollar sign curly braces active project
  4081. 3:26:22dot ID and then / chat. So this is the
  4082. 3:26:26endpoint. Then provide our prompt. So
  4083. 3:26:28just add curly braces
  4084. 3:26:31prompt.
  4085. 3:26:32Now after that here we will add
  4086. 3:26:37set active
  4087. 3:26:39project
  4088. 3:26:42and in this setter function just provide
  4089. 3:26:44this data.
  4090. 3:26:46After that we'll add if statement if
  4091. 3:26:50data dot errors and data dot
  4092. 3:26:53errors.length is greater than zero.
  4093. 3:26:59In this case we'll display the toast
  4094. 3:27:00notification. So just add toast dot
  4095. 3:27:02error
  4096. 3:27:04and this error message. After that we'll
  4097. 3:27:07add the else statement also. In this
  4098. 3:27:09else statement we'll add toast dots
  4099. 3:27:11success and the message is updated to
  4100. 3:27:15version.
  4101. 3:27:16Then we'll come here in the catch block.
  4102. 3:27:18We'll get the error
  4103. 3:27:21and then we'll add console dot error.
  4104. 3:27:25Then we'll add to dot error
  4105. 3:27:29and this message. Then we'll add the
  4106. 3:27:32finally block and in this finally block
  4107. 3:27:35we will use set
  4108. 3:27:37chat loading and make it false.
  4109. 3:27:40Save the changes.
  4110. 3:27:43So we have added handle chat function.
  4111. 3:27:46After that let's get it here. We will
  4112. 3:27:50add comma and provide handle chat. Save
  4113. 3:27:55the changes. Now you can see it should
  4114. 3:27:58run the page right. It works fine.
  4115. 3:28:02Here you can see in both chat it is
  4116. 3:28:04displaying the same bot icon. So let me
  4117. 3:28:07update it. We'll come back here and uh
  4118. 3:28:10in this chat panel you will find this
  4119. 3:28:13message roll equal to user. So just
  4120. 3:28:15correct this one user save the changes
  4121. 3:28:19and uh after that if I come back you can
  4122. 3:28:21see here we have the user icon in the
  4123. 3:28:23first one and in the second one we have
  4124. 3:28:25the bot icon. Now it is correct.
  4125. 3:28:28After that we have to create the
  4126. 3:28:30component for our files. If I click here
  4127. 3:28:33it is opening this file explorer. So we
  4128. 3:28:36have to create this file explorer
  4129. 3:28:38component.
  4130. 3:28:41To create our file explorer component
  4131. 3:28:44let's come back to the VS code and uh we
  4132. 3:28:47will open the sidebar.
  4133. 3:28:49In this one we have the components
  4134. 3:28:51folder. So here let's create a new file
  4135. 3:28:55and write the file name file explorer
  4136. 3:28:59jsx.
  4137. 3:29:01Let's add rafce
  4138. 3:29:05for creating the component structure.
  4139. 3:29:08Now in this one we'll add a div and for
  4140. 3:29:12this div we will provide some telin
  4141. 3:29:14classes and in this one we have to add a
  4142. 3:29:17text inp tag. So the text will be files.
  4143. 3:29:22Now provide some
  4144. 3:29:25CSS properties in this P. So we have
  4145. 3:29:28added these TIN classes for this P tag.
  4146. 3:29:31And after that we have to display the
  4147. 3:29:34tree item. For that we'll create the
  4148. 3:29:38component. And uh let me add the props
  4149. 3:29:42here. In this props first we'll get the
  4150. 3:29:45files.
  4151. 3:29:47After that we'll get the active file
  4152. 3:29:53and then we will get the on file select
  4153. 3:29:56function.
  4154. 3:29:58So we'll get the all files active file
  4155. 3:30:01and on file select function. Now after
  4156. 3:30:05that
  4157. 3:30:07in this function we will add con
  4158. 3:30:11tree equal to
  4159. 3:30:14use memo import it from react and uh in
  4160. 3:30:19this one
  4161. 3:30:20let's add the arrow function
  4162. 3:30:25and let's use build tree function
  4163. 3:30:30and we have to create this function.
  4164. 3:30:33So before this file explorer here we
  4165. 3:30:36will add function and uh the function
  4166. 3:30:40name is build tree. In this one we'll
  4167. 3:30:43add the paths
  4168. 3:30:46and here just provide the
  4169. 3:30:49object
  4170. 3:30:51dot
  4171. 3:30:53keys
  4172. 3:30:54dot or we'll use this keys function. In
  4173. 3:30:59this case function add the files. After
  4174. 3:31:03that add the comma and in this array
  4175. 3:31:07provide the files.
  4176. 3:31:11Now let's complete our function that is
  4177. 3:31:13build tree. So in this one just create a
  4178. 3:31:16variable with the name root. It will be
  4179. 3:31:19empty array. Then we'll add the for of.
  4180. 3:31:24So we have added for off loop. In this
  4181. 3:31:26one, we'll add the con
  4182. 3:31:29file path of the paths
  4183. 3:31:34dot sort.
  4184. 3:31:37Then we'll add con
  4185. 3:31:41parts equal to file path dot split.
  4186. 3:31:49In this split, simply add forward slash.
  4187. 3:31:52Then we'll add dot filter
  4188. 3:31:56and in this one provide the boolean.
  4189. 3:32:00Then we'll add the variable with let
  4190. 3:32:06current is equal to root.
  4191. 3:32:09Now we'll add the for loop here.
  4192. 3:32:14Just add let
  4193. 3:32:16I
  4194. 3:32:18equal to zero and uh I less than the
  4195. 3:32:25parts do.length length
  4196. 3:32:27then I ++
  4197. 3:32:31here we'll add const name name equal to
  4198. 3:32:33parts index I
  4199. 3:32:37then we'll add con is last equal to i
  4200. 3:32:42and is equal to parts dotlength minus
  4201. 3:32:45one
  4202. 3:32:48then we'll add con full path it will be
  4203. 3:32:52forward slash plus
  4204. 3:32:56this parts
  4205. 3:32:58dot slice
  4206. 3:33:02then zero comma I + 1
  4207. 3:33:06then we'll add dot join
  4208. 3:33:10and provide forward slash
  4209. 3:33:14now we'll add let
  4210. 3:33:17existing equal to current dotfind end
  4211. 3:33:23and create the function with the
  4212. 3:33:27parameter
  4213. 3:33:28n.
  4214. 3:33:30Here we'll add n dot name
  4215. 3:33:34is equal to name.
  4216. 3:33:38After that we'll add if not of existing.
  4217. 3:33:43In this case just add existing.
  4218. 3:33:46It will be
  4219. 3:33:49object where we'll add the name. Then
  4220. 3:33:52we'll add the path
  4221. 3:33:56and in the path just add full path.
  4222. 3:34:01After that we'll add is directory.
  4223. 3:34:06It will be not of is last.
  4224. 3:34:10Then we'll add children.
  4225. 3:34:14Now here we'll add current dot push
  4226. 3:34:18existing.
  4227. 3:34:19After that here we'll add current is
  4228. 3:34:21equal to existing dot children.
  4229. 3:34:25And finally we will add the return and
  4230. 3:34:29we'll return the root.
  4231. 3:34:31So we have created this build tree and
  4232. 3:34:33we are using this build tree here. Here
  4233. 3:34:36we'll get the tree. After that come here
  4234. 3:34:39within this div and simply use curly
  4235. 3:34:41braces and provide the tree dot map.
  4236. 3:34:48In this map add the arrow function and
  4237. 3:34:52return this parenthesis. Here we'll get
  4238. 3:34:54the individual node right and after that
  4239. 3:34:58using this node we have to display the
  4240. 3:35:00tree item. So let's add the text here.
  4241. 3:35:05tree item.
  4242. 3:35:08So instead of adding this text like
  4243. 3:35:09this, we'll create the tree item
  4244. 3:35:13function. So let's scroll up and here
  4245. 3:35:17before this file explorer
  4246. 3:35:19just add
  4247. 3:35:21function
  4248. 3:35:23tree item.
  4249. 3:35:27Now here we'll add some parameter. So
  4250. 3:35:29just destructure these parameters.
  4251. 3:35:32So just add calibrs and provide the
  4252. 3:35:36node.
  4253. 3:35:38Then we will get the active file.
  4254. 3:35:42After that let's get on file select
  4255. 3:35:48and then
  4256. 3:35:50depth. So default value will be zero for
  4257. 3:35:54this depth. After that just add const is
  4258. 3:35:58active equal to the node
  4259. 3:36:03dot path
  4260. 3:36:07equal to
  4261. 3:36:09active file.
  4262. 3:36:11After that we will add if statement node
  4263. 3:36:14dot is directory.
  4264. 3:36:17If it is true then we will add return
  4265. 3:36:22and return a div.
  4266. 3:36:24In this one let's create the another div
  4267. 3:36:29and inside this div we have to provide
  4268. 3:36:32some classes. So we have added these
  4269. 3:36:34telin classes and after that here we
  4270. 3:36:37have to add the folder icon. So let's
  4271. 3:36:39add
  4272. 3:36:41folder icon from Lucid React.
  4273. 3:36:45Then we'll add the size. Size will be
  4274. 3:36:4734. Then we have to add some class name
  4275. 3:36:50for the icon. So we have to add the
  4276. 3:36:55color and opacity.
  4277. 3:36:58Then we'll add the span tag. In this
  4278. 3:37:00span tag, we'll add
  4279. 3:37:03the node dot name.
  4280. 3:37:09After that just come here in this div
  4281. 3:37:12we'll add the style property. In this
  4282. 3:37:15style property add the padding left.
  4283. 3:37:22In this padding left, let's add the back
  4284. 3:37:24text
  4285. 3:37:26dollar sign curly braces and add the
  4286. 3:37:30depth
  4287. 3:37:32multiplied by 12 + 8
  4288. 3:37:38then pixel.
  4289. 3:37:40Now after that let's come here and uh
  4290. 3:37:44here we'll add curly braces.
  4291. 3:37:47Then add node dot
  4292. 3:37:50children dot map.
  4293. 3:37:54In this map add the arrow function and
  4294. 3:37:56provide the parenthesis.
  4295. 3:37:59Here we'll get the child.
  4296. 3:38:02Then we will provide this tree item.
  4297. 3:38:07It's here tree item.
  4298. 3:38:11In this tree item provide the key.
  4299. 3:38:14It will be child
  4300. 3:38:17dot path.
  4301. 3:38:20Then we will add the node.
  4302. 3:38:24So in this node, let's add the child.
  4303. 3:38:28After that, we'll add the active file.
  4304. 3:38:34So it will be active file.
  4305. 3:38:39After that we'll add on file. Select.
  4306. 3:38:43It will be on file select.
  4307. 3:38:46Then we'll add depth. So it will be the
  4308. 3:38:51depth + one.
  4309. 3:38:54Save the changes. Now after that
  4310. 3:38:58we can come here
  4311. 3:39:00and instead of this P
  4312. 3:39:03let's provide the component that is tree
  4313. 3:39:07item.
  4314. 3:39:10In this tree item, we'll add the key. It
  4315. 3:39:13will be the node dot path.
  4316. 3:39:18Then we'll add the node.
  4317. 3:39:22It will be node.
  4318. 3:39:25After that we'll add the active file
  4319. 3:39:29equal to active file. Then on file
  4320. 3:39:33select it will be on file select.
  4321. 3:39:38After that we have to update our
  4322. 3:39:40function that is tree item. You can see
  4323. 3:39:42here we have the tree item where we have
  4324. 3:39:44added if node is directory true. So
  4325. 3:39:49let's add the another statement here. So
  4326. 3:39:51after this if simply add return.
  4327. 3:39:59So if the node is a file not a
  4328. 3:40:02directory. So in this case we'll add a
  4329. 3:40:07button we have added a button tag. Now
  4330. 3:40:11in this button we'll add on click. In
  4331. 3:40:14this on click add the add a function and
  4332. 3:40:17simply call on file select and provide
  4333. 3:40:21the node dot path. Then we'll add the
  4334. 3:40:26class name here in this button. So we'll
  4335. 3:40:28provide the dynamic classes just add the
  4336. 3:40:30curly braces back. So these are the
  4337. 3:40:34fixed classes and then we'll add dollar
  4338. 3:40:36sign curly braces and write is active.
  4339. 3:40:39If it is active in this case
  4340. 3:40:44just add the
  4341. 3:40:48background color, text color and font
  4342. 3:40:50medium. And then we'll add else here
  4343. 3:40:54we'll add other colors. So let's add
  4344. 3:40:58different color here for the text hover
  4345. 3:41:02and
  4346. 3:41:04background hover.
  4347. 3:41:06Right now after that in this one we will
  4348. 3:41:09add the style also. So just add the
  4349. 3:41:13style property then curly braces and
  4350. 3:41:16just add the padding left.
  4351. 3:41:19So here we have added padding left depth
  4352. 3:41:23multiplied by 12 + 8 pixel.
  4353. 3:41:27After that just come here within this
  4354. 3:41:29button. In this button we have to
  4355. 3:41:31display the file icon. So let's add the
  4356. 3:41:34text file icon
  4357. 3:41:39and after this file icon we have to
  4358. 3:41:41display one
  4359. 3:41:45text that is the file name. So just add
  4360. 3:41:47the span tag. In this span tag just add
  4361. 3:41:52node dot name.
  4362. 3:41:55Then provide the class name here. And uh
  4363. 3:41:59in this class name we'll add truncate.
  4364. 3:42:02Save the changes. Instead of displaying
  4365. 3:42:04this file icon text, we have to display
  4366. 3:42:08the actual icon. For that we'll create a
  4367. 3:42:11function. So let's scroll up.
  4368. 3:42:15Before this item tree
  4369. 3:42:18just add a function called
  4370. 3:42:22get file icon.
  4371. 3:42:27Now in this one provide the name
  4372. 3:42:31and uh after that let's add the if
  4373. 3:42:34statement. If the name dot ends with if
  4374. 3:42:39the file name ends with and provide the
  4375. 3:42:43details like dot CSS. So if the file
  4376. 3:42:47name is ending with dot CSS in this case
  4377. 3:42:49we'll add the return and provide one
  4378. 3:42:52file icon. So just add the file
  4379. 3:42:56text icon. Now for this one just add the
  4380. 3:43:01size and
  4381. 3:43:04text color using these size property and
  4382. 3:43:07class name. So we have added file text
  4383. 3:43:10icon. Now after that let's add another
  4384. 3:43:13if statement. So just copy this one.
  4385. 3:43:16Here we'll add ends with dot jsx.
  4386. 3:43:21In this case we'll return the another
  4387. 3:43:23icon. So just add the file code icon.
  4388. 3:43:28import it from the Lucid React.
  4389. 3:43:31And this icon also
  4390. 3:43:34and in this one we'll add one more
  4391. 3:43:36statement. We'll add or
  4392. 3:43:39ends with JS. So just add name ends with
  4393. 3:43:44JS. Let's remove this one.
  4394. 3:43:48Now it is fine. So if it is ending with
  4395. 3:43:52JSX or JS then we'll add the file code
  4396. 3:43:55icon.
  4397. 3:43:57Right now let's copy this one paste it
  4398. 3:44:01here.
  4399. 3:44:02Here we'll add dot JSON.
  4400. 3:44:06So if the file name is ending with dot
  4401. 3:44:09JSON in this case we will add the file
  4402. 3:44:13text icon again. So here we are using
  4403. 3:44:16the same file text icon. size will be 14
  4404. 3:44:19and then we will update this color
  4405. 3:44:25and we'll update the color in this one
  4406. 3:44:28also. Here we will update this color and
  4407. 3:44:31the size is 14 for each. After that
  4408. 3:44:34we'll add the icon for other file type.
  4409. 3:44:37So just add the return statement.
  4410. 3:44:40In this return simply add one icon. So
  4411. 3:44:43let's add
  4412. 3:44:46file text icon size 14 and class name
  4413. 3:44:50where we have added this color. Save the
  4414. 3:44:53changes. After that let's call this
  4415. 3:44:55function here.
  4416. 3:44:57So instead of adding the
  4417. 3:45:00file icon let's provide this function.
  4418. 3:45:05Just add curly braces
  4419. 3:45:08get file icon and provide the node
  4420. 3:45:13dot name. Save the changes. After that
  4421. 3:45:17we have to mount our file explorer
  4422. 3:45:20component in our builder page. So just
  4423. 3:45:22open the builder.jsx
  4424. 3:45:25and this one
  4425. 3:45:29here we have the sidebar tabs then
  4426. 3:45:32sidebar content. So here we have the
  4427. 3:45:35turnary operator. If the left tab is
  4428. 3:45:37chat then we'll display the chat panel.
  4429. 3:45:40Else we'll display the file explorer. To
  4430. 3:45:42display this file explorer here let me
  4431. 3:45:46remove this div and simply add opening
  4432. 3:45:48arrow
  4433. 3:45:51file explorer
  4434. 3:45:53from components.
  4435. 3:45:55Now provide some props here. So just add
  4436. 3:45:57the files. It will be active project dot
  4437. 3:46:03files. After that provide the active
  4438. 3:46:06file.
  4439. 3:46:08In the active file simply provide the
  4440. 3:46:10active file. After that provide the on
  4441. 3:46:14file select. In this on file select
  4442. 3:46:18let's add the function.
  4443. 3:46:24And in this function parameter we'll get
  4444. 3:46:26the path.
  4445. 3:46:29Now in this one just use the setter
  4446. 3:46:31function set active file and provide the
  4447. 3:46:35path.
  4448. 3:46:37Then we'll add setter function set so
  4449. 3:46:40code and make it true.
  4450. 3:46:44Let's save the changes and open our web
  4451. 3:46:47page. So now you can see here we have
  4452. 3:46:49the file structures. So here you can see
  4453. 3:46:52we have the folder also. We have a large
  4454. 3:46:54icon for folder and then we have the
  4455. 3:46:57files. You can see different color for
  4456. 3:47:00different files and uh you can see the
  4457. 3:47:03file name
  4458. 3:47:05extension also like JS dot CSS app do.js
  4459. 3:47:10and this is the folder name. And if I
  4460. 3:47:13click on chat it will display the chat.
  4461. 3:47:15If I click on files it will display the
  4462. 3:47:17files. And when we click on any file it
  4463. 3:47:20will display that file in the right side
  4464. 3:47:23that we have to create. Correct? So this
  4465. 3:47:27file will become active file and it will
  4466. 3:47:29be displayed in the right side. So in
  4467. 3:47:30the right side either we can display the
  4468. 3:47:33file preview or we can display the
  4469. 3:47:37website preview.
  4470. 3:47:39To display our preview panel here in the
  4471. 3:47:42right side we will come back to the VS
  4472. 3:47:43code and uh let's scroll down. Here you
  4473. 3:47:47can see we have the preview/code
  4474. 3:47:50area. So here let's add a div.
  4475. 3:47:54In this div we'll add flex one and
  4476. 3:47:56overflow hidden and then just add the
  4477. 3:48:01curly braces. We'll add active project
  4478. 3:48:04dot a status is equal to pending.
  4479. 3:48:08So we have added active project dot
  4480. 3:48:11status is equal to pending or active
  4481. 3:48:14project dot status is equal to
  4482. 3:48:16generating
  4483. 3:48:18or
  4484. 3:48:20active project dot status is equal to
  4485. 3:48:22failed.
  4486. 3:48:25So in these cases we have to display the
  4487. 3:48:28loader or progress. So just add the
  4488. 3:48:31turnary operator and here we'll add the
  4489. 3:48:35loading component for now. Later we'll
  4490. 3:48:38replace this loading component.
  4491. 3:48:41Let me open this sidebar loading. And
  4492. 3:48:44now if I type this loading we are
  4493. 3:48:48getting the suggestion
  4494. 3:48:50it is already imported I think. Let me
  4495. 3:48:52scroll up. Here we have the loading
  4496. 3:48:54component right. So it is already
  4497. 3:48:56imported and uh we have mounted this
  4498. 3:49:00loading component here. Then we'll add
  4499. 3:49:03else statement. So just add colon and
  4500. 3:49:05another parenthesis and in this one
  4501. 3:49:08we'll display our preview panel. So just
  4502. 3:49:10add the
  4503. 3:49:12tag and let's add the text preview
  4504. 3:49:15panel. So it will be displayed in the
  4505. 3:49:18right side. If I just come back you can
  4506. 3:49:19see here we have the preview panel.
  4507. 3:49:22Correct? Now if I come back here and uh
  4508. 3:49:26let's add exclamation here and come back
  4509. 3:49:31here. So you can see we are getting the
  4510. 3:49:32loading. So instead of loading we'll
  4511. 3:49:34display some other component but for now
  4512. 3:49:38let me keep the loading only and we'll
  4513. 3:49:40continue this preview panel. So we'll
  4514. 3:49:43create a separate component for our
  4515. 3:49:44preview panel. Just open the sidebar in
  4516. 3:49:47this component folder. Create a file
  4517. 3:49:49preview panel dot jsx.
  4518. 3:49:53Now in this one
  4519. 3:49:58we'll add RAFC for creating the
  4520. 3:50:00component structure and after that we
  4521. 3:50:03will destructure some props. So here
  4522. 3:50:06we'll get the project then active file
  4523. 3:50:08and so code. So let's
  4524. 3:50:12come here and provide
  4525. 3:50:15project active file and so code.
  4526. 3:50:21After that
  4527. 3:50:23before this return
  4528. 3:50:26let's add const so error overlay set so
  4529. 3:50:30error overlay equal to
  4530. 3:50:33use a state
  4531. 3:50:35and uh let's initialize it using true.
  4532. 3:50:41After that let me add some comment. So
  4533. 3:50:44we have added the comment here keep
  4534. 3:50:46local state of files that updates as
  4535. 3:50:49user types. So when the user types it
  4536. 3:50:52updates the local state. So here we'll
  4537. 3:50:55add con
  4538. 3:50:58live files set function is set live
  4539. 3:51:00files equal to
  4540. 3:51:04use a state
  4541. 3:51:06and provide the project
  4542. 3:51:08dot files.
  4543. 3:51:11After that we'll add another state. So
  4544. 3:51:13just add con previous project key and
  4545. 3:51:16set a function name is set previous
  4546. 3:51:18project key is equal to use state and uh
  4547. 3:51:22in this one just add the back tick and
  4548. 3:51:25provide dollar sign curly braces and
  4549. 3:51:27insert the project id then
  4550. 3:51:32this let's add
  4551. 3:51:35dollar sign curly braces
  4552. 3:51:39project dot version
  4553. 3:51:42after that we'll add another variable.
  4554. 3:51:45Just add current key
  4555. 3:51:48equal to back ticks and provide this
  4556. 3:51:51one.
  4557. 3:51:53Just copy and paste it here. So we have
  4558. 3:51:56added project id dash project dot
  4559. 3:52:02version.
  4560. 3:52:05After that we'll add if statement
  4561. 3:52:08previous project key not equal to
  4562. 3:52:12current key.
  4563. 3:52:15In this case just use
  4564. 3:52:18set previous project key
  4565. 3:52:22and insert the current key. Then we'll
  4566. 3:52:25add set live files and provide the
  4567. 3:52:30project
  4568. 3:52:32dot files.
  4569. 3:52:34After that let's come here in this
  4570. 3:52:36return. In this return we have a div,
  4571. 3:52:39right? So in this div we will set the
  4572. 3:52:40width and height. So we have added width
  4573. 3:52:43full height full. Next we have to add
  4574. 3:52:46the sandpack provider. So we already
  4575. 3:52:48have the package installed in this
  4576. 3:52:50project. If I open the package dojson
  4577. 3:52:54you can see we have added this package
  4578. 3:52:57code sandbox sandpack react. So we can
  4579. 3:53:01use it in this project. So here let's
  4580. 3:53:03add
  4581. 3:53:06import kales
  4582. 3:53:09from
  4583. 3:53:11at code sandbox/ sandpack react and from
  4584. 3:53:15here we'll get the sandpack provider.
  4585. 3:53:19After that just come here in this div.
  4586. 3:53:22In this div let's add the
  4587. 3:53:25sandpack provider tag. We have added the
  4588. 3:53:28opening and closing tag.
  4589. 3:53:30Right? And uh
  4590. 3:53:34in this one we will add the key first.
  4591. 3:53:38So the key will be our project
  4592. 3:53:42dot id.
  4593. 3:53:45Then we have to add the template. So
  4594. 3:53:48just add
  4595. 3:53:50template. In the template we'll add
  4596. 3:53:52react.
  4597. 3:53:55Then we have to add the files. So just
  4598. 3:53:57add the files. So we have added the
  4599. 3:53:59files property. And after this files
  4600. 3:54:02we'll add the custom setup.
  4601. 3:54:06So we have added custom setups. Then we
  4602. 3:54:09will provide the options. So just add
  4603. 3:54:12space and provide the options.
  4604. 3:54:16After this options we'll provide the
  4605. 3:54:19theme.
  4606. 3:54:20Let me move it in the new line. So here
  4607. 3:54:22we will add the files custom setup
  4608. 3:54:26options and theme. Now let me add these
  4609. 3:54:29details one by one. So for this files
  4610. 3:54:33let's create a
  4611. 3:54:36variable that is send files.
  4612. 3:54:39Before this return just add
  4613. 3:54:44constack
  4614. 3:54:47files equal to
  4615. 3:54:50use memo.
  4616. 3:54:53In this use memo, add the add function.
  4617. 3:54:58And then we'll add the array with
  4618. 3:55:02live files
  4619. 3:55:04and active files. So we have live files
  4620. 3:55:08and active file. After that in this add
  4621. 3:55:12a function
  4622. 3:55:14just add con
  4623. 3:55:18send files
  4624. 3:55:20equal to array. Then we'll add for of
  4625. 3:55:26in this for off we'll add const path and
  4626. 3:55:28content.
  4627. 3:55:30We'll add the array with path and
  4628. 3:55:33content of object dot entries
  4629. 3:55:39then live files.
  4630. 3:55:43After that just add const
  4631. 3:55:46file code equal to
  4632. 3:55:50type of
  4633. 3:55:52content equal to
  4634. 3:55:56string.
  4635. 3:55:58So if it is equal to a string in this
  4636. 3:56:00case we'll add the content.
  4637. 3:56:04Else we'll add content
  4638. 3:56:08dot content
  4639. 3:56:10or we'll add empty string. After that
  4640. 3:56:13we'll add sendpect files
  4641. 3:56:17path
  4642. 3:56:19equal to and provide the code.
  4643. 3:56:23It will be file code. Then provide comma
  4644. 3:56:28and add the active
  4645. 3:56:30in this active provide the path
  4646. 3:56:33is equal to active file.
  4647. 3:56:38So it will be true or false. Now after
  4648. 3:56:41that here let's add the return. In this
  4649. 3:56:45return we will simply add the sandpack
  4650. 3:56:48files.
  4651. 3:56:50Now we can add this sandpack files here
  4652. 3:56:54like this. So we have added the sandpack
  4653. 3:56:56files. After that we have to add the
  4654. 3:56:58custom setup. For this custom setup
  4655. 3:57:01we'll add the dependencies. So
  4656. 3:57:06let's scroll up here. we will add the
  4657. 3:57:08comment.
  4658. 3:57:10Let me add the comment for this one
  4659. 3:57:12also. Just add convert live files to
  4660. 3:57:16sandpack format. And after that here
  4661. 3:57:18we'll add detect dependencies from
  4662. 3:57:22import a statement using live files.
  4663. 3:57:26Let's add it as a comment.
  4664. 3:57:30So here just add
  4665. 3:57:32con dependencies equal to
  4666. 3:57:36use memo
  4667. 3:57:38and in this use memo
  4668. 3:57:41let's add the arrow function and then
  4669. 3:57:43array and in this array we'll add the
  4670. 3:57:46live files and in this function
  4671. 3:57:50simply add the return and provide a
  4672. 3:57:53function that is detect dependencies.
  4673. 3:57:56page.
  4674. 3:58:00So you can see here we have the
  4675. 3:58:04utils folder. In this utils folder
  4676. 3:58:09we have sandpack utils. So in this
  4677. 3:58:11sandpack utils you can see we have a
  4678. 3:58:14function called detect dependencies. So
  4679. 3:58:16we are going to use this one. Let's come
  4680. 3:58:18here and simply provide
  4681. 3:58:22detect dependencies. So it has been
  4682. 3:58:24imported.
  4683. 3:58:26Now in this detect dependencies we'll
  4684. 3:58:28simply add the live files.
  4685. 3:58:32You can see it has been imported from
  4686. 3:58:34utils folder.
  4687. 3:58:36Save the changes. Now after that you can
  4688. 3:58:39see we have to provide the
  4689. 3:58:42value here in this custom setup. So in
  4690. 3:58:45this custom setup
  4691. 3:58:47let's add
  4692. 3:58:51curly braces and
  4693. 3:58:54dependencies.
  4694. 3:58:56That's it. After that here we have the
  4695. 3:58:58options. So in this options we'll add
  4696. 3:59:00the curly braces and add the first
  4697. 3:59:04property that is external resources. So
  4698. 3:59:07in this external resources just add the
  4699. 3:59:10array and here we will add the first
  4700. 3:59:12value that will be Telvin CDN. After
  4701. 3:59:16that comma and provide the CDN for font
  4702. 3:59:20awesome.
  4703. 3:59:22That's it. Then we'll add comma here and
  4704. 3:59:24provide the next property that is
  4705. 3:59:26classes. In this classes, let's add
  4706. 3:59:30sandpack wrapper. It will be sandpack
  4707. 3:59:33wrapper. After that sandpack layout,
  4708. 3:59:37sandpack layout and then sandpack
  4709. 3:59:40preview. Sanpe
  4710. 3:59:42preview.
  4711. 3:59:44Then we'll add comma. And next property
  4712. 3:59:47is log label. That will be zero. Now we
  4713. 3:59:52have the theme here. So in this theme
  4714. 3:59:55we'll add the curly braces and for this
  4715. 3:59:59theme we have to provide the color and
  4716. 4:00:01font. So just add the color and object
  4717. 4:00:06then comma and provide the font
  4718. 4:00:11and object.
  4719. 4:00:13Now here we can add multiple colors and
  4720. 4:00:16the name. So we have added these names
  4721. 4:00:20and colors here.
  4722. 4:00:22Surface 1 2 3 clickable base disabled
  4723. 4:00:27hover ascent
  4724. 4:00:30error error surface. And then we'll add
  4725. 4:00:32the font here. So in this font let me
  4726. 4:00:35provide
  4727. 4:00:37body mono size and line height.
  4728. 4:00:43Now after adding it let's come here
  4729. 4:00:45inside the sandpack provider. So in this
  4730. 4:00:48sandpack provider we have to add the
  4731. 4:00:50sandpack file watcher. So we have to
  4732. 4:00:53create that. Let's scroll up
  4733. 4:00:57and uh here
  4734. 4:01:00let's add the comment watches for files
  4735. 4:01:03edits inside sandpack editor and save
  4736. 4:01:06changes to DB and live state. So here
  4737. 4:01:09we'll add a function and write the
  4738. 4:01:12function name sandpack file watcher.
  4739. 4:01:16Here we'll get the
  4740. 4:01:18parameter. So just add on live files
  4741. 4:01:22change.
  4742. 4:01:24Now in this one just add con
  4743. 4:01:27send equal to
  4744. 4:01:30use send.
  4745. 4:01:34It has been imported here. use send pack
  4746. 4:01:38and uh after that let's add const files
  4747. 4:01:42it will be sendpack.
  4748. 4:01:45Now we'll add con
  4749. 4:01:49active project and uh update project
  4750. 4:01:52files
  4751. 4:01:54and let's get it from the use app
  4752. 4:01:58context.
  4753. 4:02:02We have the update project files here
  4754. 4:02:04from the context. Let's open the context
  4755. 4:02:07file. We'll open
  4756. 4:02:11context folder
  4757. 4:02:14and app context file in this one. Let's
  4758. 4:02:16find it. So we don't have this update
  4759. 4:02:19project file. We have to create it,
  4760. 4:02:22right? So let me create this one.
  4761. 4:02:26Let's scroll down and before this
  4762. 4:02:30return
  4763. 4:02:31here we will add const
  4764. 4:02:35update project files equal to
  4765. 4:02:40use call back.
  4766. 4:02:45In this use call back just add the
  4767. 4:02:48asynchronous add function and then we
  4768. 4:02:51will add comma here and add array.
  4769. 4:02:55In this array we'll add active project.
  4770. 4:03:01Then we will add the user and after that
  4771. 4:03:05we'll add
  4772. 4:03:08a function. Using that we can autosave
  4773. 4:03:11the file. So let's create that function
  4774. 4:03:15also. So
  4775. 4:03:17just before this here just add const
  4776. 4:03:21debounce save equal to
  4777. 4:03:25react dot
  4778. 4:03:27use memo.
  4779. 4:03:29In this one add the arrow function
  4780. 4:03:32where we will add debounce.
  4781. 4:03:36We are not getting the suggestion. Here
  4782. 4:03:38you can see we have the package
  4783. 4:03:40installed.
  4784. 4:03:42Let's open it. In this one, we have the
  4785. 4:03:45load dash debounce. Right? So, we will
  4786. 4:03:48import this package. Let's scroll up
  4787. 4:03:52and provide import debounce from load
  4788. 4:03:56dash debounce. Now, after that just come
  4789. 4:04:00here. Here we can use this one
  4790. 4:04:04debounce and provide the
  4791. 4:04:06async add function.
  4792. 4:04:09Here we'll get the file and id. So just
  4793. 4:04:12add the files and id. Then we'll add
  4794. 4:04:17try catch a statement. In this try block
  4795. 4:04:19we'll add await api.put.
  4796. 4:04:24So it will update the changes in files.
  4797. 4:04:27We'll add the back tick here
  4798. 4:04:30and provide the path that will be / ai/
  4799. 4:04:34projects and insert the id then files.
  4800. 4:04:37Then we'll add comma and provide our
  4801. 4:04:40updated files here.
  4802. 4:04:43After that come here in the catch we'll
  4803. 4:04:45add the error and let's provide console
  4804. 4:04:49dot error and toast dot error.
  4805. 4:04:52Then we'll add comma here and provide
  4806. 4:04:561,000 milliseconds.
  4807. 4:04:59After that here also we'll add the comma
  4808. 4:05:01and provide one array. So we have added
  4809. 4:05:04empty array.
  4810. 4:05:06Save the changes. Now we have to call
  4811. 4:05:09this
  4812. 4:05:10debounce save. For that we'll use the
  4813. 4:05:13use effect. So just add the use effect.
  4814. 4:05:16And for this use effect provide the
  4815. 4:05:18dependency array with debounce save. And
  4816. 4:05:24uh within this let's add the return.
  4817. 4:05:28In this return,
  4818. 4:05:30it will call a function
  4819. 4:05:34that executes this debounce
  4820. 4:05:37save dot cancel.
  4821. 4:05:41After that, just come here in this
  4822. 4:05:44update project files function. So in
  4823. 4:05:47this one, we'll add the if statement.
  4824. 4:05:51If
  4825. 4:05:53let's add not of
  4826. 4:05:56active project or not of user
  4827. 4:06:00then simply add return
  4828. 4:06:04here instead of this params we'll get
  4829. 4:06:06the files
  4830. 4:06:09and after this return let's add debounce
  4831. 4:06:13save and provide the
  4832. 4:06:17files comma active project dot id and
  4833. 4:06:24after that in this dependency we'll add
  4834. 4:06:26the debounce save
  4835. 4:06:29the changes. Now we have to pass it
  4836. 4:06:32through the value object. So let's come
  4837. 4:06:35here and after this log out just add the
  4838. 4:06:38comma and provide
  4839. 4:06:41update project files. Save the changes.
  4840. 4:06:46After exporting this update project
  4841. 4:06:49files, let's just come back here in the
  4842. 4:06:52preview panel. Now in this preview
  4843. 4:06:55panel, we are creating this sandpack
  4844. 4:06:57file watcher. So here you can see we
  4845. 4:06:59have added the update project files from
  4846. 4:07:03the use app context. Now after that
  4847. 4:07:08here we'll add con active project
  4848. 4:07:12reference
  4849. 4:07:13equal to use ref.
  4850. 4:07:17User ref has been imported and in this
  4851. 4:07:19one just add active project.
  4852. 4:07:22After that let's add the use effect. In
  4853. 4:07:26the use effect create the function
  4854. 4:07:29and uh add the dependency array. So the
  4855. 4:07:33dependency add will be
  4856. 4:07:37active project and within this function
  4857. 4:07:41just add active project reference dot
  4858. 4:07:43current equal to active project.
  4859. 4:07:49After that we'll add another use effect.
  4860. 4:07:52So here we have the first use effect.
  4861. 4:07:55Now let's add the another use effect
  4862. 4:07:57here.
  4863. 4:07:58or let me just duplicate this one only
  4864. 4:08:01and clear this function and clear this
  4865. 4:08:04dependency array. So in this dependency
  4866. 4:08:07array we will add
  4867. 4:08:10files
  4868. 4:08:12and uh in this one just add con project
  4869. 4:08:17equal to active project reference
  4870. 4:08:22dot current.
  4871. 4:08:25Then we'll add if not of project then
  4872. 4:08:27simply add return.
  4873. 4:08:29Then we'll add con
  4874. 4:08:32updated files equal to
  4875. 4:08:36object.
  4876. 4:08:38Then we'll add let
  4877. 4:08:41has changes equal to
  4878. 4:08:44false.
  4879. 4:08:48In this case let's add the
  4880. 4:08:51foroff loop.
  4881. 4:08:54So in this for off we'll add path and
  4882. 4:08:56object for the file object
  4883. 4:09:01of the object dot entries
  4884. 4:09:06files
  4885. 4:09:08here just at const
  4886. 4:09:10[snorts]
  4887. 4:09:11file code equal to
  4888. 4:09:15file object dot code.
  4889. 4:09:21Then we'll add updated files
  4890. 4:09:25and add the path
  4891. 4:09:30equal to file code.
  4892. 4:09:36Then we'll add con original content
  4893. 4:09:40equal to type of
  4894. 4:09:43project dot files path is equal to a
  4895. 4:09:46string.
  4896. 4:09:48Let's add the comparison
  4897. 4:09:50equal to a string. If it is true, then
  4898. 4:09:53we'll add project dot files path.
  4899. 4:09:58Else we'll add project dotfiles
  4900. 4:10:01path
  4901. 4:10:03dot content.
  4902. 4:10:08Let's add the dot here.
  4903. 4:10:10Now we'll add if statement. If original
  4904. 4:10:14content not equal to undefined and
  4905. 4:10:17original content not equal to file code.
  4906. 4:10:20In this case,
  4907. 4:10:23let's simply add has changes equal to
  4908. 4:10:26true.
  4909. 4:10:28Here we will add the comment sync live
  4910. 4:10:31files to parent. So just add on live
  4911. 4:10:35files change
  4912. 4:10:37provide the updated files.
  4913. 4:10:41After that just add if
  4914. 4:10:45has changes.
  4915. 4:10:48In this case just add
  4916. 4:10:52update project files and add the updated
  4917. 4:10:57files.
  4918. 4:10:59After that let's come here and here
  4919. 4:11:02simply add return
  4920. 4:11:04null.
  4921. 4:11:05After that, let's scroll down and come
  4922. 4:11:08here in the preview panel function. And
  4923. 4:11:12uh in this one, we have the sandpack
  4924. 4:11:15files and dependencies. Here we'll
  4925. 4:11:18create the
  4926. 4:11:22handle live file change function. So
  4927. 4:11:24just add
  4928. 4:11:26a space. Here
  4929. 4:11:28we will add const
  4930. 4:11:32handle life files change equal to add a
  4931. 4:11:36function.
  4932. 4:11:39In this one we'll add new files.
  4933. 4:11:44Then we'll add
  4934. 4:11:46set
  4935. 4:11:48live files. In this setter function add
  4936. 4:11:51the add a function with the previous
  4937. 4:11:53data.
  4938. 4:11:55So let's add the previous as parameter
  4939. 4:11:58and then provide let changed equal to
  4940. 4:12:01false.
  4941. 4:12:03Then we'll add
  4942. 4:12:05for of
  4943. 4:12:08P and code
  4944. 4:12:13of of object dot entries new files.
  4945. 4:12:18Now in this for we'll again add
  4946. 4:12:22if statement.
  4947. 4:12:24If previous P not equal to
  4948. 4:12:30code
  4949. 4:12:33in this case let's add changed equal to
  4950. 4:12:35true and break.
  4951. 4:12:41Now after that here we'll add return
  4952. 4:12:45and in the return we'll add changed.
  4953. 4:12:49If the changed is true then we'll add
  4954. 4:12:52new files.
  4955. 4:12:54else we'll add the previous
  4956. 4:13:00save the changes. Now after that we can
  4957. 4:13:03come here. [snorts]
  4958. 4:13:06Here you can see we have added this
  4959. 4:13:10sandpack provider. So in this sandpack
  4960. 4:13:12provider let's mount the sandpack file
  4961. 4:13:16watcher. Just add sandpack file watcher
  4962. 4:13:20and close it. Now in this one we'll add
  4963. 4:13:23on
  4964. 4:13:25live files change.
  4965. 4:13:28Just add handle live files change.
  4966. 4:13:33Now after that mount the
  4967. 4:13:37sandpack error monitor.
  4968. 4:13:40So we have to create the sandpack error
  4969. 4:13:43monitor
  4970. 4:13:45component first. So let's add the text
  4971. 4:13:48sandpack error monitor and we'll create
  4972. 4:13:50this component. Just open the sidebar
  4973. 4:13:52and in this components create a file
  4974. 4:13:54sandpack error monitor dot jsx.
  4975. 4:14:02Let's add rafce for creating the
  4976. 4:14:04component structure. And uh after that
  4977. 4:14:09in this one let's dstructure the props.
  4978. 4:14:13So here we'll get on error change. After
  4979. 4:14:17that here [snorts] let's add const
  4980. 4:14:21sandpack equal to
  4981. 4:14:23use sandpack use sandpack has been
  4982. 4:14:25imported and uh let's add con
  4983. 4:14:33error
  4984. 4:14:36equal to sand.
  4985. 4:14:41Now after that here we'll add the use
  4986. 4:14:43effect.
  4987. 4:14:48So we have added the use effect and add
  4988. 4:14:51the array. Now in this array let's
  4989. 4:14:53provide our
  4990. 4:14:55error then comma on error change.
  4991. 4:15:01Let's come here. In this function we'll
  4992. 4:15:03get the if statement if we have the
  4993. 4:15:07error. In this case, we'll add cones
  4994. 4:15:10message equal to error dot message or
  4995. 4:15:12empty string. Then we'll add const is
  4996. 4:15:15network error
  4997. 4:15:17equal to
  4998. 4:15:20the message dot includes
  4999. 4:15:27provide failed to fetch or let's provide
  5000. 4:15:32message dotinccludes
  5001. 4:15:35call dot csb.io.
  5002. 4:15:41Then we'll add or and provide
  5003. 4:15:46message.inccludes
  5004. 4:15:48error connection time out or we'll add
  5005. 4:15:52message dotinccludes
  5006. 4:15:56net error
  5007. 4:16:00then we'll add if statement. If
  5008. 4:16:04is network error
  5009. 4:16:07in this case we'll add on error change
  5010. 4:16:11it will be false then we'll add the
  5011. 4:16:14return
  5012. 4:16:15after that let's come here
  5013. 4:16:18simply add on
  5014. 4:16:21error change make it true
  5015. 4:16:26and in this return simply add null so
  5016. 4:16:31just remove this parenthesis just add
  5017. 4:16:34the null. Right now after that we can
  5018. 4:16:38come back to our preview panel. In this
  5019. 4:16:41preview panel instead of this text let's
  5020. 4:16:44mount our component that is sandpack
  5021. 4:16:49error monitor.
  5022. 4:16:51mount this component and provide on
  5023. 4:16:54error change
  5024. 4:16:56equal to object and provide set
  5025. 4:17:02so error overlay.
  5026. 4:17:04Now we have to add the another component
  5027. 4:17:06that we will import from the sandpack.
  5028. 4:17:08So just add sandpack layout and let's
  5029. 4:17:12import it from the sandpack react.
  5030. 4:17:15Let's add the opening and closing tag.
  5031. 4:17:19Now in this sandpack layout
  5032. 4:17:22within this opening tag provide the
  5033. 4:17:25style. So we have added the style
  5034. 4:17:27property and here we'll add the height,
  5035. 4:17:30border, border radius and background.
  5036. 4:17:35Now after that within this just add
  5037. 4:17:38curly braces and just add so code. If
  5038. 4:17:41this so code is true
  5039. 4:17:44in this case we will mount the sandpack
  5040. 4:17:47code editor. So let's add the
  5041. 4:17:49parenthesis and provide
  5042. 4:17:52sandpack code editor and import it from
  5043. 4:17:55the sandpack package.
  5044. 4:17:58It will be self-closing. In this one
  5045. 4:18:00we'll add so tabs.
  5046. 4:18:02Then we'll add so line numbers.
  5047. 4:18:06Then we'll add so line errors.
  5048. 4:18:12Then we'll add wrap content.
  5049. 4:18:15After that we'll add the style. So in
  5050. 4:18:17the style just add the height. Then
  5051. 4:18:20we'll add the flex
  5052. 4:18:23and provide
  5053. 4:18:26min width. That's it.
  5054. 4:18:30Now after this here we'll add sandpack
  5055. 4:18:34preview. So let's add the component
  5056. 4:18:37sandpack preview and import it from the
  5057. 4:18:40package. Now in this one we'll add so
  5058. 4:18:43navigator. Let's make it false. Then
  5059. 4:18:46we'll add so refresh button.
  5060. 4:18:50Then we'll add show open in code
  5061. 4:18:54sandbox. It will be false. Then we'll
  5062. 4:18:57add the
  5063. 4:18:59so sandpack error overlay.
  5064. 4:19:03It will be so error overlay. After that
  5065. 4:19:05we'll add the a style here. So just add
  5066. 4:19:07the style.
  5067. 4:19:13In this style we have to add the height
  5068. 4:19:17flex and min width. So in this flex we
  5069. 4:19:20have added so code if it is true then
  5070. 4:19:22one else two then min width zero. Save
  5071. 4:19:26the changes and uh after adding it let's
  5072. 4:19:30come back to the builder page. Now in
  5073. 4:19:33this builder page instead of this text
  5074. 4:19:36let's mount our component. So let's
  5075. 4:19:38remove this text from here. And here
  5076. 4:19:40we'll add the
  5077. 4:19:44preview panel.
  5078. 4:19:46We will mount the preview panel here. In
  5079. 4:19:48this one, we have to provide the
  5080. 4:19:49project. So let's add the project.
  5081. 4:19:55So instead of this project, let me
  5082. 4:19:57provide
  5083. 4:20:02active project. So we have added the
  5084. 4:20:04active project here. Then we'll add
  5085. 4:20:07active file. In this active file,
  5086. 4:20:10provide the active file only. Then
  5087. 4:20:12provide the so code. It will be so code.
  5088. 4:20:18That's it. Save the changes and open the
  5089. 4:20:20web page.
  5090. 4:20:23So now you can see right now it is
  5091. 4:20:26displaying the preview. Correct? And
  5092. 4:20:29here you can see we have this button. So
  5093. 4:20:30code. If I click here, it is displaying
  5094. 4:20:33the code. You can see we can change the
  5095. 4:20:36pages from these tabs. But it is
  5096. 4:20:39instantly reloading the web page and
  5097. 4:20:41displaying the same page when we change
  5098. 4:20:42the tabs. To fix it, let me just come
  5099. 4:20:46back to the VS code. Let's open the app
  5100. 4:20:48context. In this app context, we have
  5101. 4:20:50added check sessions. So we are calling
  5102. 4:20:54this check session in this use effect.
  5103. 4:20:56And here we have added the check session
  5104. 4:20:58function. And in the dependency array
  5105. 4:21:00also we have added check session. So
  5106. 4:21:01just remove this. Just add the empty
  5107. 4:21:04array in dependency. Save the changes
  5108. 4:21:07and come back here.
  5109. 4:21:10Now you can see if I click on code, it
  5110. 4:21:12will display the code here and uh we can
  5111. 4:21:15change the pages like this and we can
  5112. 4:21:17change the pages from the left sidebar
  5113. 4:21:19also. If I go to files here you can see
  5114. 4:21:22we have entire files. We have the app
  5115. 4:21:25features footer. Let's click on the
  5116. 4:21:27footer.js. So you can see it is
  5117. 4:21:28displaying the footer code. If I click
  5118. 4:21:30on header js here we have the header
  5119. 4:21:32code. We will change this code and it
  5120. 4:21:36will reflect in preview. So let me
  5121. 4:21:38change the
  5122. 4:21:40text here.
  5123. 4:21:43You can see the button text get started.
  5124. 4:21:45So let's add get started now. So you can
  5125. 4:21:47see the button text has been updated
  5126. 4:21:49here. Let's change it to get started and
  5127. 4:21:54it will autosave the code. Now we will
  5128. 4:21:56come here in the hero.jsx or hero.js. In
  5129. 4:21:59this one, you can see we have the
  5130. 4:22:03message that is build AI workflows which
  5131. 4:22:07is here. So we will change it to create
  5132. 4:22:09AI workflows.
  5133. 4:22:12You can see the text has been updated in
  5134. 4:22:15live preview and it will autosave our
  5135. 4:22:18code.
  5136. 4:22:20Now we can switch back to the preview
  5137. 4:22:21mode only. We can click on this button.
  5138. 4:22:23So it will only display the preview. And
  5139. 4:22:25if I click here, it will display the
  5140. 4:22:27code also. Right now, after that, let me
  5141. 4:22:30update the CSS properties to fix the
  5142. 4:22:34size of this folder icon. Right. So,
  5143. 4:22:37I'll just come back to the VS Code.
  5144. 4:22:43Let's open the
  5145. 4:22:46builder page. In this builder page,
  5146. 4:22:50we have the chat panel and file
  5147. 4:22:54explorer. So, let me open the file
  5148. 4:22:56explorer.jsx. JSX in this file explorer
  5149. 4:23:01we will find our icon. So in this one
  5150. 4:23:04you can see we have the folder open icon
  5151. 4:23:06size is 34. Let me update it. It will be
  5152. 4:23:0914. Save the changes and come back here.
  5153. 4:23:12So you can see perfect size for this
  5154. 4:23:14folder.
  5155. 4:23:16Now after that I'll come back here in
  5156. 4:23:19the builder page. Just open builder.jsx.
  5157. 4:23:22Here you can see
  5158. 4:23:24we have added the loading component. So
  5159. 4:23:26instead of adding the loading component,
  5160. 4:23:28we will add one component that I have
  5161. 4:23:30provided in the asset. So just come back
  5162. 4:23:33to the
  5163. 4:23:35downloaded folder. So just open the
  5164. 4:23:38downloaded assets folder. In this one
  5165. 4:23:40you will find the components and inside
  5166. 4:23:41this components we have the agent
  5167. 4:23:44progress dashboard. So just copy this
  5168. 4:23:46one and add it in the project. Just open
  5169. 4:23:49the project client src assets. Let's
  5170. 4:23:53come back. We will not come to assets.
  5171. 4:23:55We will come to components and paste it
  5172. 4:23:57here. So we have added this agent
  5173. 4:23:59progress dashboard component. After that
  5174. 4:24:02we'll open the VS code.
  5175. 4:24:05And if I open
  5176. 4:24:08components here you can see we have the
  5177. 4:24:13agent progress dashboard.jsx.
  5178. 4:24:16Now let's mount it here instead of this
  5179. 4:24:18loading. So remove this loading and
  5180. 4:24:20provide
  5181. 4:24:22agent progress dashboard.
  5182. 4:24:26Now in this component we have to provide
  5183. 4:24:30uh props. So let's add the
  5184. 4:24:34project. In this project just add the
  5185. 4:24:36active project.
  5186. 4:24:39Save the changes and come back here.
  5187. 4:24:43So until it load or generate the page it
  5188. 4:24:46will display the status. Let me change
  5189. 4:24:50it.
  5190. 4:24:53Here we have the active project status
  5191. 4:24:56equal to pending
  5192. 4:24:59or active project status is generating
  5193. 4:25:03or active project status equal to
  5194. 4:25:05failed. So
  5195. 4:25:07let's add exclamation here not of
  5196. 4:25:11pending. Save the changes and come back
  5197. 4:25:13here. So you can see it will display the
  5198. 4:25:16progress like this. AI agent is
  5199. 4:25:18building. It will also display the files
  5200. 4:25:21name when the AI is building our
  5201. 4:25:23project. Now let me remove it. We'll
  5202. 4:25:25remove this exclamation and it will be
  5203. 4:25:28removed from here and we'll display the
  5204. 4:25:31complete preview or we can display the
  5205. 4:25:34code.
  5206. 4:25:38After that we have to display the
  5207. 4:25:40publish model. So just come back
  5208. 4:25:43and we'll create a new component. So
  5209. 4:25:48let's open the sidebar. In this
  5210. 4:25:50components, we'll create a new file with
  5211. 4:25:52the name publish model dot jsx. Here
  5212. 4:25:56we'll add rafce for creating the
  5213. 4:25:58component structure. And uh in this one
  5214. 4:26:01we'll get some data as props. So just
  5215. 4:26:03dstructure it. We'll add publish url and
  5216. 4:26:06on close.
  5217. 4:26:08After that in this one we'll add handle
  5218. 4:26:11copy link.
  5219. 4:26:14So just add handle copy link function
  5220. 4:26:17and uh it will be one add function.
  5221. 4:26:22Now in this function we'll add if
  5222. 4:26:26not of
  5223. 4:26:28publish URL. It is not available then
  5224. 4:26:31simply add return.
  5225. 4:26:34After that we'll add navigator
  5226. 4:26:38dot
  5227. 4:26:40clipboard
  5228. 4:26:42dot
  5229. 4:26:44write text and provide the
  5230. 4:26:48publish URL.
  5231. 4:26:50Then we'll add the toast notification.
  5232. 4:26:52So just add the toast. Import the toast
  5233. 4:26:54here. Then dot success. And in this one
  5234. 4:26:58add the message public link copied to
  5235. 4:27:01clipboard.
  5236. 4:27:04After that come here in the return. In
  5237. 4:27:07this return first we'll add a div. And
  5238. 4:27:10in this div we will add some classes to
  5239. 4:27:13add the absolute position. And after
  5240. 4:27:16that let's add another div here.
  5241. 4:27:22Now in this one
  5242. 4:27:24we will add the white background and
  5243. 4:27:27we'll add the
  5244. 4:27:29border color. then shadow and we'll add
  5245. 4:27:31the position relative.
  5246. 4:27:34After that here we'll add one button.
  5247. 4:27:38Using that we can close this model. So
  5248. 4:27:41just add a button tag.
  5249. 4:27:45Now in this button we'll add the cross
  5250. 4:27:47icon. So just add X icon from Lucid
  5251. 4:27:51React.
  5252. 4:27:52Now in this icon set the size it will be
  5253. 4:27:5616. And in this button provide the on
  5254. 4:28:00click. Let's add the onclick property.
  5255. 4:28:03In this on click simply add on close.
  5256. 4:28:06Then provide the classes also. So just
  5257. 4:28:08add the class name property and provide
  5258. 4:28:10the absolute. Then we'll add the top
  5259. 4:28:14right. Then we'll add the text color
  5260. 4:28:17hover effect and cursor pointer. Save
  5261. 4:28:20the changes.
  5262. 4:28:22Now after that we'll add the title and
  5263. 4:28:26small description. So after this button
  5264. 4:28:29create a div. In this one we'll add the
  5265. 4:28:32title in H3 and then we'll add the
  5266. 4:28:35description in P tag. So the title is
  5267. 4:28:39your website is live.
  5268. 4:28:42After that we'll add the small
  5269. 4:28:44description.
  5270. 4:28:46So here we have added this description.
  5271. 4:28:49Now add the classes in this div and then
  5272. 4:28:53we'll add the classes in the title which
  5273. 4:28:55is in the S3 tag and after that we'll
  5274. 4:28:58add some classes in the
  5275. 4:29:01description text. So here we have added
  5276. 4:29:03some classes that will reduce the text
  5277. 4:29:06size and change the text color.
  5278. 4:29:10After that we have to add the
  5279. 4:29:15input field and in the input field we'll
  5280. 4:29:18provide the publish URL and we'll add
  5281. 4:29:22the
  5282. 4:29:24button also. So after closing of this
  5283. 4:29:27div here create a div and provide the a
  5284. 4:29:31space y 4
  5285. 4:29:36and within this
  5286. 4:29:38create two divs.
  5287. 4:29:41The first one will contain the input and
  5288. 4:29:45the second one will contain the buttons.
  5289. 4:29:48So in the first one
  5290. 4:29:51let's add the label tag. So we have
  5291. 4:29:53added the label. In this label provide
  5292. 4:29:56some classes. So we have added these
  5293. 4:29:58classes and within this label tag add
  5294. 4:30:00the label text that is published link.
  5295. 4:30:05Then we'll add the input field. So just
  5296. 4:30:07add the input type will be text. Then
  5297. 4:30:11we'll add read only.
  5298. 4:30:14Then we have to add value. So the value
  5299. 4:30:16will be publish URL. And then provide
  5300. 4:30:20some classes here. So we have added
  5301. 4:30:21these classes. So in this input field we
  5302. 4:30:24cannot type anything. We can just read
  5303. 4:30:26the content. Now after that here we have
  5304. 4:30:28a button. So in this button we'll add
  5305. 4:30:31the functionality to copy the link.
  5306. 4:30:34Right? So in the first button we will
  5307. 4:30:38add the functionality to copy the link
  5308. 4:30:39and in the second button we will add the
  5309. 4:30:42functionality to open the live link or
  5310. 4:30:44published link. So we'll add two buttons
  5311. 4:30:47here. So just group it using this div.
  5312. 4:30:49And in this div we have added flex to
  5313. 4:30:51align both buttons. Now create the first
  5314. 4:30:54button. In this first button we'll add
  5315. 4:30:56the button text called copy link.
  5316. 4:30:59After that provide the classes here. So
  5317. 4:31:01just add the class name property. And
  5318. 4:31:03here we have these classes. Now in this
  5319. 4:31:07button we'll add the on click. So in
  5320. 4:31:10this on click simply add our handle copy
  5321. 4:31:13link. That's it. Now we'll create the
  5322. 4:31:16second button. So we have added another
  5323. 4:31:19button tag. Here we'll add the text
  5324. 4:31:21called open site. Then add the class
  5325. 4:31:23name. So let me provide these classes.
  5326. 4:31:27After that here also we have to add the
  5327. 4:31:29on click. So just add the on click
  5328. 4:31:32property. Add one add function and then
  5329. 4:31:35simply add window
  5330. 4:31:39dot open and provide our
  5331. 4:31:43publish URL. Then add comma and provide
  5332. 4:31:48underscore blank. So it will open the
  5333. 4:31:50link in new tab.
  5334. 4:31:52Save the changes. Now we have to mount
  5335. 4:31:55our component that is publish model in
  5336. 4:31:59our builder page. So just open the
  5337. 4:32:01builder page and just scroll down just
  5338. 4:32:03above this last closing div
  5339. 4:32:07here. Let's add curly braces. just add
  5340. 4:32:12publish URL and if it is available then
  5341. 4:32:15we will mount our
  5342. 4:32:18publish URL model or publish model.
  5343. 4:32:23Now in this publish model provide the
  5344. 4:32:25props. So just provide
  5345. 4:32:29publish URL like this. Then we'll add
  5346. 4:32:33the second props that is on close. In
  5347. 4:32:36this on close just add the function and
  5348. 4:32:40here use the setter function set publish
  5349. 4:32:43URL
  5350. 4:32:45and simply provide null. So when we
  5351. 4:32:47don't have the URL it will close it.
  5352. 4:32:50Let's save the changes and come back
  5353. 4:32:52here.
  5354. 4:32:53To preview our model we have to click on
  5355. 4:32:55this button publish. But it is not
  5356. 4:32:58functional yet because we have added the
  5357. 4:32:59empty function. So just come back here
  5358. 4:33:02and we'll complete our function. Just
  5359. 4:33:04scroll up. You can see here we have
  5360. 4:33:05handle publish and handle download. We
  5361. 4:33:08will complete these functions. So in
  5362. 4:33:10this handle publish
  5363. 4:33:13let's add if statement if not of id. In
  5364. 4:33:18this case simply add return.
  5365. 4:33:22After that let's add set publishing.
  5366. 4:33:27In this set publishing we will add true.
  5367. 4:33:31Then we'll add try catcher statement. In
  5368. 4:33:34this try block, we'll make the network
  5369. 4:33:36request using await API. Let's add the
  5370. 4:33:42API here and import it from the API
  5371. 4:33:44file. You can see it has been imported
  5372. 4:33:46from API/ API. Now after that just add
  5373. 4:33:52dot
  5374. 4:33:53post
  5375. 4:33:55in this one add the back tick and insert
  5376. 4:33:59the path. It will be / API/ projects.
  5377. 4:34:03then insert the id using the dollar sign
  5378. 4:34:07curly braces id and then slash publish.
  5379. 4:34:12So this is the endpoint to publish our
  5380. 4:34:14project. Now after that here we'll get
  5381. 4:34:18the
  5382. 4:34:20URL. So just add con URL equal to back.
  5383. 4:34:26Then we'll add dollar signal braces
  5384. 4:34:29window.loation dot origin.
  5385. 4:34:32then slash
  5386. 4:34:36publish and provide the ID using the
  5387. 4:34:40dollar sign and curly braces.
  5388. 4:34:43Next, we'll add the set publish URL and
  5389. 4:34:46in this one provide our URL.
  5390. 4:34:50Then we'll display the toast
  5391. 4:34:51notification. So just add the toast,
  5392. 4:34:53import the toast and add the success. In
  5393. 4:34:56this success just add
  5394. 4:34:59website published successfully.
  5395. 4:35:02Then we have the catch block. In this
  5396. 4:35:05one we'll add the error and provide
  5397. 4:35:08console dot error and provide the toast
  5398. 4:35:11error. So just add toast dot error. Then
  5399. 4:35:14we'll add the finally block also. So in
  5400. 4:35:16this finally simply set the publishing
  5401. 4:35:19false. So just copy this set publishing
  5402. 4:35:22and we will make it false.
  5403. 4:35:25save the changes. So after adding it, it
  5404. 4:35:28will handle our publish button. Now we
  5405. 4:35:32have the download button also. For that
  5406. 4:35:34we have the handle download function. So
  5407. 4:35:36in this one let's add if statement. If
  5408. 4:35:40not of active project. So when the
  5409. 4:35:44active project is not available then
  5410. 4:35:46simply add return. Now suppose the
  5411. 4:35:48active project is available then we have
  5412. 4:35:51to call a function that we have provided
  5413. 4:35:53in the utilities. So just open the utils
  5414. 4:35:56folder. Here we have export project dot
  5415. 4:36:00js file. So in this one you can see
  5416. 4:36:02export project zip function. So just use
  5417. 4:36:05this function here in this builder.
  5418. 4:36:07Let's add
  5419. 4:36:12export project zip and import it from
  5420. 4:36:15the utils folder. You can see it has
  5421. 4:36:18been imported. And uh after that
  5422. 4:36:23here we have to provide a
  5423. 4:36:26project. So just add active project.
  5424. 4:36:32That's it. Now after that save the
  5425. 4:36:35changes and we will come back here. So
  5426. 4:36:37you can see here we have the publish
  5427. 4:36:40button. If I click here it will display
  5428. 4:36:43the notification website published
  5429. 4:36:45successfully. And here we have the model
  5430. 4:36:48within message your website is live. And
  5431. 4:36:50here we have the live URL. And here we
  5432. 4:36:53have the button to copy the link or we
  5433. 4:36:57can open this site in new tab. Just
  5434. 4:36:59click here. So you can see it is opening
  5435. 4:37:00the new tab. Now let's click on this
  5436. 4:37:03button. So you can see the notification
  5437. 4:37:06public link copied to clipboard. When we
  5438. 4:37:09open this site, it is opening the home
  5439. 4:37:11route because we have added the
  5440. 4:37:14routes that will redirect us to homepage
  5441. 4:37:17when the route is not registered. So, we
  5442. 4:37:19have to register our public route also.
  5443. 4:37:22For that,
  5444. 4:37:24let me just come back to the
  5445. 4:37:29app dot jsx. In this app dot jsx you can
  5446. 4:37:32see here we have a
  5447. 4:37:35route that will catch unregistered
  5448. 4:37:38route. So just before that we'll add one
  5449. 4:37:41comment that is public routes.
  5450. 4:37:45In this public routes we'll add the
  5451. 4:37:50route. It will be self-closing. Here
  5452. 4:37:52we'll add the path. So in this path
  5453. 4:37:55we'll add /publish/
  5454. 4:37:58colon id that is the project id and then
  5455. 4:38:00we'll add the element. So in this
  5456. 4:38:03element we'll provide our
  5457. 4:38:10page. So just add publish page. We are
  5458. 4:38:14not getting the suggestions. So just
  5459. 4:38:16open this publish page. And after that
  5460. 4:38:17if I start typing
  5461. 4:38:20it should display this page. Let me
  5462. 4:38:24clear this.
  5463. 4:38:26In this publish page, we have not added
  5464. 4:38:28the component structure. Let me add it.
  5465. 4:38:32And after that, let's start typing it.
  5466. 4:38:39Here we are getting the suggestion
  5467. 4:38:40publish page. It has been mounted here.
  5468. 4:38:44Save the changes and come back here. And
  5469. 4:38:47uh let's close it and click on this open
  5470. 4:38:50site. So now you can see it is opening
  5471. 4:38:52this publish page. We will design this
  5472. 4:38:55page later. So you can see the route
  5473. 4:38:57only that is /publish and / project ID.
  5474. 4:39:03So we have completed our builder page.
  5475. 4:39:07Let me show you one more functionality
  5476. 4:39:09here. Here we can click on this open
  5477. 4:39:11preview. So it will open the preview
  5478. 4:39:12page. You can see the URL preview/
  5479. 4:39:14project ID. And if I click on this
  5480. 4:39:17export, we can download the entire code
  5481. 4:39:20in zip file. You can see the code is
  5482. 4:39:23downloaded here in zip file. So we have
  5483. 4:39:25the export, sign out, publish,
  5484. 4:39:28open, preview and code. We can display
  5485. 4:39:30the code. So now we have completed our
  5486. 4:39:33project builder page.
  5487. 4:39:37After creating this page, let me review
  5488. 4:39:39our code using code rabbit. For that we
  5489. 4:39:42will commit the changes on GitHub. So
  5490. 4:39:44just come back here, click on this
  5491. 4:39:46source control icon and we'll add the
  5492. 4:39:48commit message
  5493. 4:39:56created project builder page.
  5494. 4:39:59So it will commit the changes on GitHub
  5495. 4:40:02and uh after that let me just come back
  5496. 4:40:05to the GitHub account or GitHub repo.
  5497. 4:40:11If I open it, you can see here we have
  5498. 4:40:14this button compare and pull request.
  5499. 4:40:16We'll click on this button
  5500. 4:40:19and click on create pull request. So we
  5501. 4:40:22have created a new pull request. After
  5502. 4:40:25creating the pull request, the code
  5503. 4:40:28rabbit will start analyzing our code.
  5504. 4:40:32Now you can see the code rabbit is
  5505. 4:40:34running and analyzing our code.
  5506. 4:40:42Now you can see the review has been
  5507. 4:40:44completed by code rabbit.
  5508. 4:40:47Here we have this button review change
  5509. 4:40:50stack. We will review the change stack.
  5510. 4:40:53But before that let me see the
  5511. 4:40:55suggestions here also. So here we have
  5512. 4:40:57the suggestion
  5513. 4:41:00in this app context. In this app
  5514. 4:41:03context, we have to
  5515. 4:41:06update the code. Here we have the
  5516. 4:41:08proposed fix also. You can see it is
  5517. 4:41:11suggesting to remove this debounce save
  5518. 4:41:14dot cancel and add dot plus. Instead of
  5519. 4:41:18cancel, we have to use plus. It is
  5520. 4:41:20recommended. And uh let's see the
  5521. 4:41:23suggestion for builder page. In this
  5522. 4:41:25builder page,
  5523. 4:41:27we have to remove this code because we
  5524. 4:41:30are already
  5525. 4:41:32adding it in the context. After that,
  5526. 4:41:37let's see the change stack also. We'll
  5527. 4:41:39click here, review change stack.
  5528. 4:41:47Now in this change stack, you can see
  5529. 4:41:49the changes made in this files. Here we
  5530. 4:41:53have the app context file. So you can
  5531. 4:41:55see the previous files here and the
  5532. 4:41:57latest changes in this right side and uh
  5533. 4:42:00you can see we have the explanation also
  5534. 4:42:03like in this 42 we have made some
  5535. 4:42:06changes in line 42 and for this line 42
  5536. 4:42:09here we have the description. Now if I
  5537. 4:42:12come here
  5538. 4:42:14we have the changes in line 182
  5539. 4:42:20to 227. So here we have the explanation
  5540. 4:42:24for these code. Right? Now after that
  5541. 4:42:29let's come here in the second file. So
  5542. 4:42:34we have the agent progress dashboard.
  5543. 4:42:36Here also we have the updates and we
  5544. 4:42:40have the description in the right side.
  5545. 4:42:42And uh if you want to understand
  5546. 4:42:44anything or want to ask any question you
  5547. 4:42:46can ask from the agent also. So here we
  5548. 4:42:49have the agent and you can enter your
  5549. 4:42:51prompt here and you will get the
  5550. 4:42:53response from the code rabbit agent. Now
  5551. 4:42:56after that let's come here in the next
  5552. 4:42:59file. So here we have the updates
  5553. 4:43:03and this is the next file that is
  5554. 4:43:05builder page.jsx.
  5555. 4:43:10In this builder page you can see we have
  5556. 4:43:13one suggestion. It says we have one
  5557. 4:43:16major issue. Right? Let me expand it.
  5558. 4:43:19And here we have proposed fix. So it is
  5559. 4:43:22suggesting to remove this use effect
  5560. 4:43:24from this builder page dot jsx. Let me
  5561. 4:43:27just come back
  5562. 4:43:29open the
  5563. 4:43:31builder page
  5564. 4:43:34and uh let's find that use effect.
  5565. 4:43:38So here we have this use effect. So we
  5566. 4:43:41have to remove this use effect from
  5567. 4:43:43here. just clear it, save the changes
  5568. 4:43:46and uh after that let's see the next
  5569. 4:43:50isue.
  5570. 4:43:56So
  5571. 4:43:58currently we don't have any other issue
  5572. 4:44:00in this file. Let's see the another file
  5573. 4:44:07here also we don't have any suggestion.
  5574. 4:44:10We will open the next one.
  5575. 4:44:13Now we'll open the first file. And here
  5576. 4:44:16we have the app context. So let's see.
  5577. 4:44:19We have some suggestion in this app
  5578. 4:44:21context also. It is major issue. Let's
  5579. 4:44:25expand it. You can see it is suggesting
  5580. 4:44:28to remove this one. Remove cancel and
  5581. 4:44:31add plus. So just come back here in the
  5582. 4:44:35app context.
  5583. 4:44:38Here we have
  5584. 4:44:40debounced save dot cancel. So we will
  5585. 4:44:42change it to
  5586. 4:44:44dot plus. Let's come back and uh see the
  5587. 4:44:49next suggestion.
  5588. 4:44:51Now we'll click on this comments. So
  5589. 4:44:53here you can see we have the suggestion
  5590. 4:44:56for this app context. In this app
  5591. 4:44:59context we have created the handle chat
  5592. 4:45:01but it is not exported. So here we have
  5593. 4:45:04the proposed fix. We have to provide
  5594. 4:45:07this handle chat inside this value. Just
  5595. 4:45:10come back to the VS code, open app
  5596. 4:45:12context and uh inside this value object
  5597. 4:45:15just add
  5598. 4:45:20handle chat. Save the changes. So we
  5599. 4:45:22have implemented all the suggestions and
  5600. 4:45:25bug fix. And you can click on this
  5601. 4:45:27overview also to see the entire
  5602. 4:45:29overview. You can see here we have the
  5603. 4:45:32code rabbit major issues right and here
  5604. 4:45:36we have the premerge checks. Now after
  5605. 4:45:39that you can see the PI description here
  5606. 4:45:43you can see the code rabbit walk through
  5607. 4:45:47here we have sequence diagrams.
  5608. 4:45:50Now after that let me just come back to
  5609. 4:45:52the
  5610. 4:45:54GitHub repo.
  5611. 4:45:58In this pull request simply click on
  5612. 4:46:00this merge pull request confirm merge.
  5613. 4:46:04So it will merge the changes in main
  5614. 4:46:06branch and uh after that we'll come back
  5615. 4:46:08to the VS code and
  5616. 4:46:12click here
  5617. 4:46:14then select
  5618. 4:46:16pull.
  5619. 4:46:20Now after creating the builder page we
  5620. 4:46:22have to create our next page. So just
  5621. 4:46:25come back to the application
  5622. 4:46:28and you can see if I click on this
  5623. 4:46:30publish
  5624. 4:46:32we'll get the link. Let's open this link
  5625. 4:46:34in new tab that is /publish/
  5626. 4:46:37project id and uh if I click on this
  5627. 4:46:41open preview so we have the / preview/
  5628. 4:46:46project id. So we have to create these
  5629. 4:46:48two pages that is publish page and
  5630. 4:46:51preview page. In both pages we will use
  5631. 4:46:54the same design. Actually we will use
  5632. 4:46:56the same layout that is available here.
  5633. 4:46:58So here we have the small preview. So
  5634. 4:47:00instead of this small preview we will
  5635. 4:47:02create a full screen preview. For that
  5636. 4:47:06let's come back to the VS code
  5637. 4:47:09and we'll create a component here. So
  5638. 4:47:15let's open the sidebar.
  5639. 4:47:19In this one, we have the components
  5640. 4:47:20folder where we'll create a new file
  5641. 4:47:22with the name
  5642. 4:47:28full page preview. JSX.
  5643. 4:47:31Now add R Ace for creating the component
  5644. 4:47:34structure. Now here we need the file
  5645. 4:47:37then only we can display the preview. So
  5646. 4:47:39just get the files as props.
  5647. 4:47:44So now we have the files here and after
  5648. 4:47:46that let me just copy the code here from
  5649. 4:47:50the previous file.
  5650. 4:47:54So let me just open the
  5651. 4:47:59preview panel component.
  5652. 4:48:03In this preview panel component we have
  5653. 4:48:06a div, right? So let's just copy this
  5654. 4:48:08entire div from here from this preview
  5655. 4:48:11panel
  5656. 4:48:13and add it here
  5657. 4:48:15in the full screen preview
  5658. 4:48:18and uh again come back to the preview
  5659. 4:48:21panel
  5660. 4:48:23and from here just copy these code.
  5661. 4:48:28We will copy this function
  5662. 4:48:30sendpack files
  5663. 4:48:42and after that copy this dependencies
  5664. 4:48:44also. Let's copy it and come here in the
  5665. 4:48:47full screen preview
  5666. 4:48:51and paste it here before the return.
  5667. 4:48:55Now again come back to the preview
  5668. 4:48:56panel. In this preview panel, we have
  5669. 4:48:58one state also. Just copy this state
  5670. 4:49:03and paste it here.
  5671. 4:49:06So we have con so error overlay and set
  5672. 4:49:11so error overlay equal to use state. So
  5673. 4:49:15just import this use state from react.
  5674. 4:49:19It will be true. And after that we have
  5675. 4:49:21the sandpack files that is used to
  5676. 4:49:25convert the live files to sandpack
  5677. 4:49:28format.
  5678. 4:49:30So here we have the
  5679. 4:49:32SP files and we have the
  5680. 4:49:37return that is SP files and here we have
  5681. 4:49:40to provide the dependency. So in the
  5682. 4:49:42dependency we'll add the files that we
  5683. 4:49:44are getting as props.
  5684. 4:49:49Let me update it.
  5685. 4:49:52We have added this files here.
  5686. 4:49:56And in this one just update the code
  5687. 4:49:58also. We'll add if statement if not of
  5688. 4:50:03files. So when we don't have this files
  5689. 4:50:06then simply add the return and return
  5690. 4:50:08the empty object.
  5691. 4:50:12After that we'll add the SP files. It
  5692. 4:50:15will be path content of object entries
  5693. 4:50:19and let's add the files here. Just copy
  5694. 4:50:22this files and replace this one.
  5695. 4:50:26Then we'll get the
  5696. 4:50:28file code. So I don't need this one. Let
  5697. 4:50:32me simply remove it.
  5698. 4:50:35We'll add sp files path. It will be
  5699. 4:50:41in this object. We have the code. So the
  5700. 4:50:44code will be our content. Just copy this
  5701. 4:50:46content here and then remove this
  5702. 4:50:49active.
  5703. 4:50:52So we have updated this code here and uh
  5704. 4:50:57after that it is returning the SP files
  5705. 4:51:00and the files as dependency. Then we
  5706. 4:51:03have the dependencies equal to use memo.
  5707. 4:51:06In this one let's add the same if
  5708. 4:51:09statement. If not of files
  5709. 4:51:13in this case simply add return empty
  5710. 4:51:15object else we'll add the return
  5711. 4:51:19detect dependencies and provide our
  5712. 4:51:22files.
  5713. 4:51:27Now we have to import this function. So
  5714. 4:51:31just import it from the utils. You can
  5715. 4:51:34see it is imported from the utils folder
  5716. 4:51:37sandpack utils.
  5717. 4:51:39Now after that let's come here in this
  5718. 4:51:41return. In this return we have a div
  5719. 4:51:44where we have to add the
  5720. 4:51:47screen and we'll add the background and
  5721. 4:51:51uh overflow. So we have updated this
  5722. 4:51:53class name height a screen width a
  5723. 4:51:55screen background white overflow hidden.
  5724. 4:51:59Then we will provide the sandpack
  5725. 4:52:01provider and in this sandpap provider we
  5726. 4:52:04will add the template. It will be react.
  5727. 4:52:06From here we can remove this key.
  5728. 4:52:09So we have the template. Then we have to
  5729. 4:52:12add the files. So the files will be
  5730. 4:52:14sandpack files which is here. And after
  5731. 4:52:18that we'll add the custom setup. So in
  5732. 4:52:22the custom setups we have added
  5733. 4:52:24dependencies. Then options. So in the
  5734. 4:52:26options we have external resources that
  5735. 4:52:29is Telwind CDN and font awesome CDN. And
  5736. 4:52:35uh after that here we'll add
  5737. 4:52:38log label zero. And from here we can
  5738. 4:52:40remove the classes. So we have removed
  5739. 4:52:43these classes.
  5740. 4:52:45After that we have to display our
  5741. 4:52:48preview in full screen. So here we will
  5742. 4:52:51add the
  5743. 4:52:54class name.
  5744. 4:52:56Let's add the class name. Here
  5745. 4:53:04it will be height full and width full.
  5746. 4:53:08And from here we can remove this theme.
  5747. 4:53:14Let's remove this one.
  5748. 4:53:18So we have removed this theme.
  5749. 4:53:21Here we have one extra quote sign. Let
  5750. 4:53:23me correct it. Now it is correct. Save
  5751. 4:53:26the changes. Now within this we have the
  5752. 4:53:28sandpack file watcher. So we can remove
  5753. 4:53:31it. After that we have the sandpack
  5754. 4:53:34error monitor. So let's
  5755. 4:53:39import this one also. So this component
  5756. 4:53:41has been imported and uh in this one we
  5757. 4:53:44have provided this state. Now after that
  5758. 4:53:47we have the sandpack layout. In this
  5759. 4:53:49sandpack layout
  5760. 4:53:52we can remove this style.
  5761. 4:53:55And after removing this style, let's add
  5762. 4:54:00class name
  5763. 4:54:02and provide
  5764. 4:54:06width height. And then we'll add the
  5765. 4:54:09border none.
  5766. 4:54:11Then we'll add background transparent
  5767. 4:54:15like this. And in this one we have to
  5768. 4:54:18add our preview. So just remove this
  5769. 4:54:21and simply add the sandpack preview
  5770. 4:54:24component.
  5771. 4:54:30Let's close this tag here. And here we
  5772. 4:54:33have sandpack preview component. And uh
  5773. 4:54:37let's import this one also. It has been
  5774. 4:54:40imported.
  5775. 4:54:41Then let's import the sandpack layout.
  5776. 4:54:44It is already imported. and sandpack
  5777. 4:54:48error monitor is there. So in this
  5778. 4:54:50preview we have the so navigator false.
  5779. 4:54:55Then we have so refresh button. So let's
  5780. 4:54:59add
  5781. 4:55:00false.
  5782. 4:55:03After that we have so open in code
  5783. 4:55:06sandbox.
  5784. 4:55:08So here also we'll add false.
  5785. 4:55:12Next we have so sandpack error overlay.
  5786. 4:55:17So here we have so error overlay state.
  5787. 4:55:21Then we have some styles. So just remove
  5788. 4:55:23this styles
  5789. 4:55:25and instead of this style we will add
  5790. 4:55:27the class name.
  5791. 4:55:29And let's provide the height full and
  5792. 4:55:32width full.
  5793. 4:55:35Save the changes. So we have created our
  5794. 4:55:38component called full page preview. Now
  5795. 4:55:41let's mount this component in our pages.
  5796. 4:55:44So first we'll come to the publish page.
  5797. 4:55:47Just open the pages and publish page dot
  5798. 4:55:50jsx. In this one
  5799. 4:55:54we need the project id. So just add
  5800. 4:55:57const id equal to
  5801. 4:56:03use padams.
  5802. 4:56:05Now after that we need some state. So
  5803. 4:56:08just add const project and set project
  5804. 4:56:11equal to
  5805. 4:56:13user state and initialize it using null.
  5806. 4:56:17Now after that we'll add con loading and
  5807. 4:56:20set loading equal to
  5808. 4:56:24use a state
  5809. 4:56:26and initialize it using true.
  5810. 4:56:30Then we'll add con error and setter
  5811. 4:56:32function set error
  5812. 4:56:35equal to use a state and by default it
  5813. 4:56:39will be empty string. So we have these
  5814. 4:56:42state and one id from the use params.
  5815. 4:56:45Now after that here we will create the
  5816. 4:56:48use effect
  5817. 4:56:51where we will fetch the public project.
  5818. 4:56:53So just add
  5819. 4:56:56use effect
  5820. 4:56:59and provide the comma dependency add a.
  5821. 4:57:03So it will be our id that is the project
  5822. 4:57:06id. Now let's add if not of id then
  5823. 4:57:11we'll add the return.
  5824. 4:57:14Next we'll add con
  5825. 4:57:17fetch public project
  5826. 4:57:20equal to await then API import this API
  5827. 4:57:26then dot get method and provide the
  5828. 4:57:30endpoint it will be back/ API/
  5829. 4:57:35projects/public
  5830. 4:57:37and then provide the project id like
  5831. 4:57:40this. Now after that we'll get the data.
  5832. 4:57:43So just use set
  5833. 4:57:46project. In this set project provide the
  5834. 4:57:48data that we are getting from the
  5835. 4:57:50network request.
  5836. 4:57:53Let me update it.
  5837. 4:57:56Here we'll create the
  5838. 4:57:58asynchronous add function. And in this
  5839. 4:58:02function paste this code that is await.
  5840. 4:58:07And uh here we'll get the data as a
  5841. 4:58:10response. So just add const
  5842. 4:58:15data equal to await API and we'll set
  5843. 4:58:19the data using the setter function set
  5844. 4:58:21project. Now let's wrap this code inside
  5845. 4:58:25the try catch. So just remove it. We'll
  5846. 4:58:28add the try catch statement and paste
  5847. 4:58:30this code inside the try block. Now come
  5848. 4:58:33here in the catch block we'll add the
  5849. 4:58:35error and then use the console dot
  5850. 4:58:38error. After that we'll add the set
  5851. 4:58:41error. So in the set error we have added
  5852. 4:58:43this
  5853. 4:58:45response or this message. Now we'll add
  5854. 4:58:48the finally block here. And in this
  5855. 4:58:50finally block we will use
  5856. 4:58:54set loading and we will make it false.
  5857. 4:58:58So you can see the loading is true by
  5858. 4:59:00default. So we'll make the loading
  5859. 4:59:02false. Now after that we have to call
  5860. 4:59:05this fetch public project. So just
  5861. 4:59:09before this
  5862. 4:59:11closing curly braces we'll add
  5863. 4:59:15fetch public project and call it.
  5864. 4:59:24After that just come here before this
  5865. 4:59:26return let's add if statement if
  5866. 4:59:29loading. If the loading is true in this
  5867. 4:59:32case simply mount the loading component.
  5868. 4:59:35So just add the return and provide the
  5869. 4:59:40loading component. Just import this
  5870. 4:59:42component and close this tag. Now if the
  5871. 4:59:45loading is false, let's come here
  5872. 4:59:50and create another if statement.
  5873. 4:59:55Here we'll add
  5874. 4:59:58error
  5875. 5:00:00or
  5876. 5:00:02not of project.
  5877. 5:00:04You can see here we have the error
  5878. 5:00:06state.
  5879. 5:00:08So if we have the error or the project
  5880. 5:00:11is not available in this case let's add
  5881. 5:00:14the return and uh provide the
  5882. 5:00:19div.
  5883. 5:00:22Now in this div we'll add the classes.
  5884. 5:00:25So just add these element classes and in
  5885. 5:00:28this one we have to add one icon. So
  5886. 5:00:31let's wrap this icon inside a div. In
  5887. 5:00:33this div provide one icon that is alert
  5888. 5:00:36circle icon.
  5889. 5:00:39Import this icon from lucid react. For
  5890. 5:00:42this icon we will set the size. So size
  5891. 5:00:44will be 24. And we'll provide the
  5892. 5:00:47classes for the div that contains this
  5893. 5:00:50icon. So add the class name and these
  5894. 5:00:53classes. Now after that we have to add
  5895. 5:00:56the title. So after this just add the
  5896. 5:00:59title in H1 tag. So the title is website
  5897. 5:01:02unavailable.
  5898. 5:01:05Then we will add the description in P
  5899. 5:01:09tag. So here we'll add the description
  5900. 5:01:11that will be our error message.
  5901. 5:01:15Then we will add a div.
  5902. 5:01:19And in this div let's add the message
  5903. 5:01:22that is builder AI. Now let's add the
  5904. 5:01:26classes for each. Here just add the
  5905. 5:01:29class name for H1 tag. Then we'll add
  5906. 5:01:33the classes
  5907. 5:01:35for header message.
  5908. 5:01:39So we have added these classes. And now
  5909. 5:01:42we'll add the classes for this text
  5910. 5:01:44called builder AI.
  5911. 5:01:48Save the changes. And after that let's
  5912. 5:01:51come here. We have the return. in this
  5913. 5:01:53final return. We'll return our
  5914. 5:01:59component. So just add
  5915. 5:02:03full page preview component. Now in this
  5916. 5:02:06component we have to provide the files.
  5917. 5:02:08So let's add the files and it will be
  5918. 5:02:10our project dot files. Save the changes.
  5919. 5:02:16Now after that let me just come back to
  5920. 5:02:18the web page
  5921. 5:02:21and uh let's refresh this one that is
  5922. 5:02:24publish/
  5923. 5:02:26project id.
  5924. 5:02:31Let me open it from here. We'll click on
  5925. 5:02:33this publish open site.
  5926. 5:02:37Let's come back to the VS code.
  5927. 5:02:40You can see we are updating the code in
  5928. 5:02:43publish page. Let me inspect it.
  5929. 5:02:53use memo. So, we have to import this use
  5930. 5:02:56memo. Let's scroll up
  5931. 5:02:59and uh open our full page preview
  5932. 5:03:01component.
  5933. 5:03:03Here we have the full page preview and
  5934. 5:03:06uh let's import this one. Import from
  5935. 5:03:11React. Save the changes.
  5936. 5:03:14After that let's clear it and refresh
  5937. 5:03:17it.
  5938. 5:03:20Live files is there. So we have to
  5939. 5:03:21replace this live files from here. Let's
  5940. 5:03:24find it. Here we have live files. So
  5941. 5:03:27just replace this one instead of this
  5942. 5:03:30live files. Simply add files
  5943. 5:03:34as dependencies. Save the changes. Let's
  5944. 5:03:37come back.
  5945. 5:03:38Sandpack provider is not defined. So we
  5946. 5:03:41have to import the sandpack provider.
  5947. 5:03:44Sandpack preview is there.
  5948. 5:03:47We are not getting the suggestion here
  5949. 5:03:49for sandpack provider. So let me import
  5950. 5:03:53it manually in this statement. Let's add
  5951. 5:03:57comma and provide sandpack provider from
  5952. 5:04:00the code sandbox/ sandpack react. Let me
  5953. 5:04:05just come back here refresh it. It says
  5954. 5:04:09sandpack layout is not defined. So just
  5955. 5:04:11import the sendpack layout also. Let's
  5956. 5:04:14add the comma here and provide sandpack
  5957. 5:04:16layout. Save the changes. After adding
  5958. 5:04:18it, come back here.
  5959. 5:04:24Now you can see it is loading our
  5960. 5:04:27website preview. So here we can see the
  5961. 5:04:29website preview in full screen. So this
  5962. 5:04:31is the publish page. After publishing
  5963. 5:04:33the project, any user can see the
  5964. 5:04:36website on this URL that is /publish and
  5965. 5:04:39project ID. Similarly, we'll create the
  5966. 5:04:42preview on our preview page which is
  5967. 5:04:46here preview/ project id. If I refresh
  5968. 5:04:49it, you can see we have the text called
  5969. 5:04:50preview page. So, let me update this
  5970. 5:04:52page also. I'll come back to the VS code
  5971. 5:04:57and uh come to our publish page. Just
  5972. 5:05:00copy the entire code from the publish
  5973. 5:05:02page
  5974. 5:05:05and uh
  5975. 5:05:08open
  5976. 5:05:10our preview page
  5977. 5:05:14and update the code here.
  5978. 5:05:18Let's replace everything and uh update
  5979. 5:05:22the name. Here we have publish page. So
  5980. 5:05:25let's change it to preview page.
  5981. 5:05:31Let's add the preview page here. And we
  5982. 5:05:34will export the preview page here.
  5983. 5:05:38Update this line. Export default preview
  5984. 5:05:41page. And here we'll add con preview
  5985. 5:05:43page. Now in this one we need the ID. It
  5986. 5:05:46is fine. Then we need the data from
  5987. 5:05:50context. So just remove it. Here let's
  5988. 5:05:53add con
  5989. 5:05:56curly braces. We'll add the active
  5990. 5:05:59project. We can preview the active
  5991. 5:06:02project only. So just add active project
  5992. 5:06:04as project.
  5993. 5:06:06Then we'll add comma
  5994. 5:06:09loading active project
  5995. 5:06:13as loading.
  5996. 5:06:16Then we'll add load project function
  5997. 5:06:20and let's get it from the use app
  5998. 5:06:24context. Use app context has been
  5999. 5:06:26imported. Now after that here we have
  6000. 5:06:28the use effect. Now in this use effect
  6001. 5:06:30we have this code. So we will update
  6002. 5:06:32this one. Let's clear this use effect.
  6003. 5:06:39and simply add if statement if id when
  6004. 5:06:42the id is available then we'll add
  6005. 5:06:47load project and provide the id
  6006. 5:06:51after that here we'll add the
  6007. 5:06:56load project as dependency
  6008. 5:06:59then we have if statement if loading
  6009. 5:07:02or not of project.
  6010. 5:07:07In this case, we'll return the loading
  6011. 5:07:09component. Now, remove this if statement
  6012. 5:07:11from here
  6013. 5:07:14and simply provide the return statement
  6014. 5:07:17with full page preview and provide the
  6015. 5:07:20files and files will be project files.
  6016. 5:07:23Let's save the changes. After updating
  6017. 5:07:25this, let's open the web page. And you
  6018. 5:07:28can see this is the URL/review/
  6019. 5:07:30project id. And if I refresh it, it is
  6020. 5:07:34continuously reloading the page. Let me
  6021. 5:07:36just come back.
  6022. 5:07:38Now you can see it is displaying our
  6023. 5:07:40preview here. So after removing the load
  6024. 5:07:44project from the dependency, it is
  6025. 5:07:45working fine. And here we have the
  6026. 5:07:47preview. So we can see the preview of
  6027. 5:07:49our project that we are building. Let's
  6028. 5:07:52come here in the project builder. We'll
  6029. 5:07:55come back to the homepage and open the
  6030. 5:07:57next project. So this is the another
  6031. 5:07:59project, right? And if I click on the
  6032. 5:08:02code, it will display the code here. If
  6033. 5:08:05I click on preview, so it will open the
  6034. 5:08:08path / preview/ project ID. So this is
  6035. 5:08:11the preview. Let's close all these and
  6036. 5:08:15uh come here, open this, then go to
  6037. 5:08:20preview. So you can see the URL preview
  6038. 5:08:23and project ID. And if I go to publish,
  6039. 5:08:25we'll get the URL publish/ project ID.
  6040. 5:08:29So we have completed the front end of
  6041. 5:08:31our AI website builder.
  6042. 5:08:36Now we will review our code using code
  6043. 5:08:38rabbit. So just come here and add the
  6044. 5:08:42commit message.
  6045. 5:08:49front end completed.
  6046. 5:08:56Commit and sync changes.
  6047. 5:08:59After committing the changes, let me
  6048. 5:09:01just come back to the GitHub repo.
  6049. 5:09:05Let's go to development branch
  6050. 5:09:09and uh click on this contribute open
  6051. 5:09:13pull request.
  6052. 5:09:16So click on this button create pull
  6053. 5:09:18request
  6054. 5:09:20and uh once we create the pull request
  6055. 5:09:22the code rabbit will start analyzing our
  6056. 5:09:26code.
  6057. 5:09:29Now you can see the code rabbit is
  6058. 5:09:31running.
  6059. 5:09:32Now you can see the review has been
  6060. 5:09:34completed and here we have the review
  6061. 5:09:36summary. You can also go to review
  6062. 5:09:38change stack and uh after that you can
  6063. 5:09:41see the suggestions here for any
  6064. 5:09:45issue or any improvement. So you can
  6065. 5:09:48implement these fix or suggestions and
  6066. 5:09:51then merge the changes. So just click on
  6067. 5:09:54this button merge pull request confirm
  6068. 5:09:56merge
  6069. 5:10:00and then come to the VS code click here
  6070. 5:10:03and pull. So it will pull the latest
  6071. 5:10:04changes. So now we have completed the
  6072. 5:10:07front end of our AI website builder.
  6073. 5:10:10Next we have to create the back end. So
  6074. 5:10:11just close all files. So right click
  6075. 5:10:13here and select close saved. Now after
  6076. 5:10:16that let's
  6077. 5:10:18fold this one. And here we have to
  6078. 5:10:20create our
  6079. 5:10:23folder for creating the backend server.
  6080. 5:10:26So let's create a folder here and write
  6081. 5:10:28the folder name server.
  6082. 5:10:31In this server folder, we will create
  6083. 5:10:33the backend server where we'll create
  6084. 5:10:35the APIs and then we'll integrate the
  6085. 5:10:38APIs with our client.
  6086. 5:10:41To create our backend server, just right
  6087. 5:10:44click on this server folder and select
  6088. 5:10:46open in integrated terminal.
  6089. 5:10:49So now we have two terminals. This is
  6090. 5:10:51the server terminal and this one is the
  6091. 5:10:53client terminal where the client project
  6092. 5:10:55is running.
  6093. 5:10:57Now come here in the server. In this
  6094. 5:11:00one, let's add npm
  6095. 5:11:04in it dash y. But before adding this,
  6096. 5:11:08let me open this sidebar. In this
  6097. 5:11:10server, we'll create a new file and
  6098. 5:11:12write the file name server.js.
  6099. 5:11:18So this will be the main file. After
  6100. 5:11:20creating this server.js file, come here
  6101. 5:11:22in the terminal and type npm init-y.
  6102. 5:11:28Now after that here you can see we have
  6103. 5:11:29package.json
  6104. 5:11:31in this one we have the name version
  6105. 5:11:33description and main file is server.js
  6106. 5:11:36and here we have the start a script that
  6107. 5:11:38is node server.js
  6108. 5:11:41and here you can see we have the type
  6109. 5:11:43common js and if the type is not
  6110. 5:11:45available you can add it manually. So
  6111. 5:11:47let me update it. Instead of this common
  6112. 5:11:49js we will use
  6113. 5:11:52module.
  6114. 5:11:54Now after that here we have to add the
  6115. 5:11:56dependencies. Using that we'll create
  6116. 5:11:58our backend server. So we'll create the
  6117. 5:12:02server using express. So in this
  6118. 5:12:04terminal let's add npm
  6119. 5:12:08install
  6120. 5:12:09and add the dependencies or packages
  6121. 5:12:13name. So first we'll add the express
  6122. 5:12:14package.
  6123. 5:12:16After that we'll add course
  6124. 5:12:19that will support the crossplatform
  6125. 5:12:22integration. And after that we'll add
  6126. 5:12:24the env. Using that we can add the
  6127. 5:12:27environment variables. Then we'll add
  6128. 5:12:30the cookie parser.
  6129. 5:12:32Using this we can send the cookies in
  6130. 5:12:35the request. After that we'll add the
  6131. 5:12:38brypt package. Using that we can encrypt
  6132. 5:12:41the user's password and store in the
  6133. 5:12:43database. Then we'll add the JSON web
  6134. 5:12:46token. Using that we can generate a
  6135. 5:12:49unique token for authentication. Now
  6136. 5:12:52we'll add the mongus package so that we
  6137. 5:12:54can communicate with the MongoDB
  6138. 5:12:57database. After adding all these
  6139. 5:12:59packages name, let's press enter. So it
  6140. 5:13:01will install all these packages.
  6141. 5:13:05And after installation, you can find all
  6142. 5:13:07these packages in the package.json file
  6143. 5:13:11inside the dependencies. Let's open it.
  6144. 5:13:14You can see here we have the brypt
  6145. 5:13:15cookies parser course. Ennv Express JSON
  6146. 5:13:19web token and mongus. After that we'll
  6147. 5:13:21add one more package. Here we'll add npm
  6148. 5:13:25install. Then we'll add dash d to
  6149. 5:13:28install the package in dev dependencies
  6150. 5:13:31or development dependencies. And here
  6151. 5:13:33we'll add the package name that will be
  6152. 5:13:35nodemon. Using the nodemon we can
  6153. 5:13:39restart our backend server when we will
  6154. 5:13:41make any changes in the code file. It
  6155. 5:13:43will automatically restart the server.
  6156. 5:13:45So just add this npm installed as the
  6157. 5:13:48nodemon.
  6158. 5:13:50So it will get installed
  6159. 5:13:53after that. You can see here we have the
  6160. 5:13:56dev dependencies and in this one we have
  6161. 5:13:58nodemon. Now let's add the nodemon
  6162. 5:14:01script. So just remove this test and
  6163. 5:14:04here we'll add the comma
  6164. 5:14:06and copy this one only. Just copy and
  6165. 5:14:09paste it here. So just add the script
  6166. 5:14:11name. So the script name will be dev.
  6167. 5:14:15And here we'll add the nodemon
  6168. 5:14:18server.js. js. So when we'll type npm
  6169. 5:14:21rundev in the terminal, it will execute
  6170. 5:14:23this nodemon server.js and when we'll
  6171. 5:14:26start the server using this dev script,
  6172. 5:14:29it will automatically restart the
  6173. 5:14:30backend server when we will make any
  6174. 5:14:32changes in the code file. Now after that
  6175. 5:14:36in the left side in this source control
  6176. 5:14:39icon we have the 2,000 plus files. So
  6177. 5:14:44let's come here in this root directory
  6178. 5:14:47that is builder- AI. In this one we will
  6179. 5:14:50add the g ignore file. So let's add a
  6180. 5:14:54new file here and write the file name
  6181. 5:14:57dot get ignore.
  6182. 5:15:01So you can see it is outside of these
  6183. 5:15:03folder that is client and server. And in
  6184. 5:15:06this one just add the folder name that
  6185. 5:15:08is node_modules.
  6186. 5:15:10Then we'll add the another folder. Let's
  6187. 5:15:13add the d and then we'll add env also.
  6188. 5:15:16So it will ignore all these files and
  6189. 5:15:19folder. After that you can see we have
  6190. 5:15:21only four files here. Now just come back
  6191. 5:15:24here
  6192. 5:15:26and let's start creating our basic
  6193. 5:15:28express server. For that let's import
  6194. 5:15:32the express from the express package.
  6195. 5:15:36And uh after that let's add importv
  6196. 5:15:42from
  6197. 5:15:44env/config.
  6198. 5:15:46Then we'll add the import course from
  6199. 5:15:49course package. After that let's create
  6200. 5:15:52one app using express. So we have added
  6201. 5:15:55cost app equal to express.
  6202. 5:15:59Next we will add the
  6203. 5:16:02middleware. So just add
  6204. 5:16:05app dot
  6205. 5:16:08use. In this app dot use just add
  6206. 5:16:11express
  6207. 5:16:12dot
  6208. 5:16:14JSON. So all the request will be passed
  6209. 5:16:17using JSON.
  6210. 5:16:20Here we'll add another line. Just copy
  6211. 5:16:22and paste it here. Let's add app dot use
  6212. 5:16:25and provide the course.
  6213. 5:16:28In this course we have to add the
  6214. 5:16:31object. And in this object we'll add the
  6215. 5:16:34origin. So the origin will be our
  6216. 5:16:38front end and back end URL. And uh we
  6217. 5:16:42can add it in this code. Then we'll add
  6218. 5:16:44the comma and provide the credentials.
  6219. 5:16:47So just add the credentials
  6220. 5:16:50true. Then only we can pass the
  6221. 5:16:55cookies using the
  6222. 5:16:58network request. So instead of adding
  6223. 5:17:01the origins here, we will add it in the
  6224. 5:17:03environment variable. So just open the
  6225. 5:17:05sidebar and in this server create env
  6226. 5:17:08file. Just add env.
  6227. 5:17:12And here let's store our
  6228. 5:17:16URL.
  6229. 5:17:18So let's add the
  6230. 5:17:20name called origins equal to and provide
  6231. 5:17:24the quote. In this one, we'll add http
  6232. 5:17:28localhost
  6233. 5:17:30col 5173. That is our front end URL. If
  6234. 5:17:33I come back to the web page, you can see
  6235. 5:17:36this is the URL. Now, let's add comma
  6236. 5:17:39and provide the URL
  6237. 5:17:42that is localhost
  6238. 5:17:44colon 3000 where we will run our backend
  6239. 5:17:48server. So, we have added this URL here
  6240. 5:17:51in the origins. Now let's add it here in
  6241. 5:17:54the
  6242. 5:17:55course. So in this course we'll add
  6243. 5:17:57process
  6244. 5:18:01envisions
  6245. 5:18:08and then we'll add
  6246. 5:18:11dot a split
  6247. 5:18:14and we will split using the comma.
  6248. 5:18:19Let's come here. You can see we have
  6249. 5:18:20added the comma here to provide the
  6250. 5:18:23multiple origins.
  6251. 5:18:26Now after this course we can add the
  6252. 5:18:29cookie parser also. So first we have to
  6253. 5:18:32import the cookie parser. Let's add
  6254. 5:18:34import cookie parser from cookie parser
  6255. 5:18:37package and just add app dot use
  6256. 5:18:41and just add
  6257. 5:18:43cookie parser here.
  6258. 5:18:46So it will be added in all the request.
  6259. 5:18:49After that we'll create the first route
  6260. 5:18:52or home route. So just add app dot get
  6261. 5:18:56method. In this get method we'll add the
  6262. 5:18:58home path. Then we'll add comma and
  6263. 5:19:01provide a function. In this function
  6264. 5:19:04parameter we'll get the request and
  6265. 5:19:06response.
  6266. 5:19:09Then we will add the response here.
  6267. 5:19:12simply at response dot send and add a
  6268. 5:19:16message. So just add the message server
  6269. 5:19:18is live. So when we will open the home
  6270. 5:19:22route using the get method, it will
  6271. 5:19:24display this message server is live. Now
  6272. 5:19:27after that let's define the port number
  6273. 5:19:29to run our app. So just add con equal to
  6274. 5:19:35let's use process env. If it is
  6275. 5:19:38available in the environment variable,
  6276. 5:19:40it will be used. else we will add 3,00
  6277. 5:19:43if it is not available
  6278. 5:19:45then we will start our server. So just
  6279. 5:19:49add app dot listen.
  6280. 5:19:54Now for this app.list we will provide
  6281. 5:19:57the port number first. So just add the
  6282. 5:19:59port
  6283. 5:20:02comma and provide a function that will
  6284. 5:20:04get executed.
  6285. 5:20:07So in this function simply add
  6286. 5:20:11console.log
  6287. 5:20:14and provide a message that will be
  6288. 5:20:15displayed in the terminal. So just add
  6289. 5:20:18server is running at and provide the
  6290. 5:20:21local host and insert our port number.
  6291. 5:20:24So just add dollar signals port.
  6292. 5:20:29So we have created the basic express
  6293. 5:20:31server. Now let's start our express
  6294. 5:20:35server. So just open the terminal and uh
  6295. 5:20:38in this one just add npm
  6296. 5:20:42run dev.
  6297. 5:20:47Now you can see the message starting
  6298. 5:20:49node server.js and you can see the
  6299. 5:20:51message server is running at localhost
  6300. 5:20:543000.
  6301. 5:20:56Now just hide it and open the web
  6302. 5:20:58browser here. If I type localhost
  6303. 5:21:033000
  6304. 5:21:05here also you can see the message server
  6305. 5:21:07is live that is coming from our home
  6306. 5:21:10route which is here server is live and
  6307. 5:21:13this message server is running at this
  6308. 5:21:15URL it is coming in the terminal after
  6309. 5:21:18creating the basic express server let's
  6310. 5:21:21create one
  6311. 5:21:23global error handler so here let's add
  6312. 5:21:28one message
  6313. 5:21:30centralized error handler and provide
  6314. 5:21:34app dot use.
  6315. 5:21:40Just create a function. In this function
  6316. 5:21:43parameter, we'll get the error
  6317. 5:21:46comma. Then we'll add underscore
  6318. 5:21:49request.
  6319. 5:21:52Then response and then we'll add
  6320. 5:21:55underscore next.
  6321. 5:21:58Let's add error.
  6322. 5:22:02After that, simply add console dot error
  6323. 5:22:07and provide the black tick
  6324. 5:22:10error and it will be dollar sign curly
  6325. 5:22:12braces
  6326. 5:22:14this error dot message.
  6327. 5:22:18Now in the next line, let me provide
  6328. 5:22:22response. So just add response dot a
  6329. 5:22:24status. So a status is 500. Then dot
  6330. 5:22:27JSON in this JSON we'll add the error
  6331. 5:22:31property. It will be error dot message.
  6332. 5:22:34So we have added the global error
  6333. 5:22:36handler function.
  6334. 5:22:38So after creating it now we have to
  6335. 5:22:41connect our backend server with a
  6336. 5:22:44database.
  6337. 5:22:46So here we are going to use the MongoDB
  6338. 5:22:49database. So just open the web browser
  6339. 5:22:51and search for MongoDB atlas.
  6340. 5:22:55Open this website and click on get
  6341. 5:22:58started and create your account. If you
  6342. 5:23:00don't have an account and uh if you
  6343. 5:23:04already have an account, you can go to
  6344. 5:23:06sign in.
  6345. 5:23:08So let me login with my existing
  6346. 5:23:09account. I'll continue with my Google
  6347. 5:23:11account. Let's click here.
  6348. 5:23:14After sign up, it will ask some
  6349. 5:23:16onboarding question and then you need to
  6350. 5:23:18create your project. So let me add the
  6351. 5:23:20project name builder.
  6352. 5:23:26Then next
  6353. 5:23:28then create project and after creating
  6354. 5:23:31the project we have to create a new
  6355. 5:23:34cluster.
  6356. 5:23:35So here you will find this button create
  6357. 5:23:38a cluster and after that you need to
  6358. 5:23:41choose the plan. So let me choose the
  6359. 5:23:43free plan. We'll go for this free plan.
  6360. 5:23:46And from here you can choose the
  6361. 5:23:50service provider. So let me choose
  6362. 5:23:52Google cloud and from this drop-down you
  6363. 5:23:54can choose the nearest region and click
  6364. 5:23:57on create deployment.
  6365. 5:23:59After that you can see it says database
  6366. 5:24:04user created. So it will create one
  6367. 5:24:06database user also and password also.
  6368. 5:24:09You can click on this button to download
  6369. 5:24:12the file where you can save the username
  6370. 5:24:15and password for database.
  6371. 5:24:19So I'll click on this download. It will
  6372. 5:24:21get downloaded. And after that click on
  6373. 5:24:24choose a connection method. Now in this
  6374. 5:24:26connection method we can go for this
  6375. 5:24:29drivers. And in this drop-down you can
  6376. 5:24:32choose mongos because we have already
  6377. 5:24:34added the package. So you can see
  6378. 5:24:36we have the same step npm install
  6379. 5:24:39So we have added the package. We
  6380. 5:24:41can skip this and come to the next step.
  6381. 5:24:44So next we have to add the
  6382. 5:24:48connection a string. So we need to add
  6383. 5:24:50this connection string in our
  6384. 5:24:53file. So this connection a string
  6385. 5:24:55includes our database user and this
  6386. 5:24:57database password. So let me just open
  6387. 5:25:02the VS code
  6388. 5:25:04and then go to env file. In this env
  6389. 5:25:07file let's add the environment variable
  6390. 5:25:10name. So let's add the name
  6391. 5:25:14MongoDB
  6392. 5:25:15URI.
  6393. 5:25:17After adding it, let's come back here
  6394. 5:25:20and copy this string from here and it
  6395. 5:25:24will end here at mongodv.net. Just copy
  6396. 5:25:27this and uh paste it here. So you can
  6397. 5:25:30see we have added this string from
  6398. 5:25:32beginning to this part that is cluster
  6399. 5:25:35zero and some id mongodv.net ate and at
  6400. 5:25:39the end we'll add slash and add any
  6401. 5:25:41project name. So we'll add our project
  6402. 5:25:43name build.ai.
  6403. 5:25:46That's it. Now after adding it save the
  6404. 5:25:49changes and now we'll create the
  6405. 5:25:50configuration for our connection. So
  6406. 5:25:54let's open the sidebar. In this server
  6407. 5:25:56folder create a folder called config.
  6408. 5:26:00In this config folder create a file
  6409. 5:26:02called dv.js.
  6410. 5:26:06Now in this dv.js JS just import the
  6411. 5:26:09mongus package. After that let's create
  6412. 5:26:12one function. So just add export async
  6413. 5:26:14function and add the function name
  6414. 5:26:18connect to database.
  6415. 5:26:22After that let's add mongus
  6416. 5:26:25dot
  6417. 5:26:27connection
  6418. 5:26:29dot on.
  6419. 5:26:32Now in this one just add the
  6420. 5:26:35event name connected.
  6421. 5:26:39So we are getting one
  6422. 5:26:42event or we are registering one event.
  6423. 5:26:44So when this connected event occurred in
  6424. 5:26:47this case it will execute this function
  6425. 5:26:49and here we will display a message. So
  6426. 5:26:51just add console.log
  6427. 5:26:53and provide the message that is
  6428. 5:26:55successfully connected to MongoDB.
  6429. 5:27:00Now after that let's come here and
  6430. 5:27:02simply add await and use the mongus
  6431. 5:27:05package dot connect method. Here you can
  6432. 5:27:08see we have added connection method and
  6433. 5:27:12here we are using connect method. In
  6434. 5:27:14this connect method simply provide the
  6435. 5:27:16connection string from the environment
  6436. 5:27:18variable. So just add process envong
  6437. 5:27:24URI from here. Let's just copy this add
  6438. 5:27:28it here.
  6439. 5:27:30That's it. So we have created this
  6440. 5:27:32function that will help us to connect
  6441. 5:27:34with the MongoDB database. Now just come
  6442. 5:27:36here in the main file that is server.js
  6443. 5:27:38file and here we have to call that
  6444. 5:27:41function. So after this app instance
  6445. 5:27:44we'll add the
  6446. 5:27:46connect to database function and call
  6447. 5:27:49it. You can see this function has been
  6448. 5:27:50imported from config / db. Let's add the
  6449. 5:27:55file name extension db.js. save the
  6450. 5:27:57changes. Now it will connect our project
  6451. 5:28:01with database and uh let's come back
  6452. 5:28:05here in the
  6453. 5:28:07MongoDB dashboard again. Click on done
  6454. 5:28:09and after that we have to update our IP
  6455. 5:28:13address. Just come here in the left
  6456. 5:28:15sidebar. Open database and network
  6457. 5:28:17access. Then go to IP access list and
  6458. 5:28:22click on this edit icon and uh just
  6459. 5:28:25clear it. Here we'll add 0.0.0.0.
  6460. 5:28:31So it will allow us to connect with the
  6461. 5:28:33database from any IP address. So you can
  6462. 5:28:36see it is displaying the status pending
  6463. 5:28:39once it is accepted or active. Then we
  6464. 5:28:43can connect with our database from any
  6465. 5:28:45IP address.
  6466. 5:28:49Now you can see the status is active.
  6467. 5:28:52Let me just come back to the VS code and
  6468. 5:28:56let's open the terminal. In this
  6469. 5:28:58terminal
  6470. 5:29:00the backend server is running and you
  6471. 5:29:02can see the message here that is server
  6472. 5:29:04is running at this URL. And after that
  6473. 5:29:07we have the message successfully
  6474. 5:29:08connected to MongoDB. It means we have
  6475. 5:29:11created our express server and connected
  6476. 5:29:14this express server with MongoDB
  6477. 5:29:16database.
  6478. 5:29:18Next we have to store the data in
  6479. 5:29:21database. For that we have to create the
  6480. 5:29:23models. In this project first we'll
  6481. 5:29:25create the APIs for user authentication.
  6482. 5:29:28It means user can create an account or
  6483. 5:29:31login into existing account and the user
  6484. 5:29:33data will get saved in the database. For
  6485. 5:29:36that we'll create the model and using
  6486. 5:29:39the model we will store the data in
  6487. 5:29:41MongoDB database. So in this server
  6488. 5:29:44folder create a new folder and write the
  6489. 5:29:46folder name models.
  6490. 5:29:49In this models folder create a file that
  6491. 5:29:51will be user.js.
  6492. 5:29:55In this user dot js file let's create
  6493. 5:29:58the
  6494. 5:30:00model. And for creating the model first
  6495. 5:30:03we have to create the schema. So let's
  6496. 5:30:05add import
  6497. 5:30:07and provide curly braces from
  6498. 5:30:13mongus and from this mongus let's get
  6499. 5:30:16the schema.
  6500. 5:30:19After getting the schema here just add
  6501. 5:30:21con user schema equal to
  6502. 5:30:26new schema.
  6503. 5:30:29In this schema we have to define all the
  6504. 5:30:31properties that we will store for this
  6505. 5:30:33user data. So just add the name and in
  6506. 5:30:36this name we'll add the type. Type will
  6507. 5:30:38be a string and then we'll add the
  6508. 5:30:40required. Required will be true to store
  6509. 5:30:42the user data. This name field will be
  6510. 5:30:44required. Then we'll add the email. So
  6511. 5:30:47just add email and then we'll add the
  6512. 5:30:50password. So here we have added the
  6513. 5:30:52email. Type is a string required true
  6514. 5:30:55and in this one we have added unique
  6515. 5:30:56true. So the email should be unique for
  6516. 5:30:59creating a new account. Then we have
  6517. 5:31:01added the lowerase true. So it will
  6518. 5:31:03store the data in lower case and trim
  6519. 5:31:05true. So it will remove the extra space
  6520. 5:31:07from the beginning and end of this email
  6521. 5:31:09id. Then we have added the password type
  6522. 5:31:12will be string and required true for
  6523. 5:31:14adding the user data. Then we'll add the
  6524. 5:31:17comma and provide one object. In this
  6525. 5:31:19one provide the timestamps true. So it
  6526. 5:31:21will automatically add the time and date
  6527. 5:31:24when this data was created or modified.
  6528. 5:31:27Now after that here we'll add a
  6529. 5:31:29function. So just add the comment here
  6530. 5:31:30that is has password before saving. It
  6531. 5:31:34means we'll encrypt the user's password
  6532. 5:31:36before we save the password in database.
  6533. 5:31:38So just add the user schema here
  6534. 5:31:42then dot pre and provide the event save
  6535. 5:31:48then add comma and create the async
  6536. 5:31:51arrow function. Now in this function
  6537. 5:31:54let's add if statement and provide not
  6538. 5:31:58of this dot is modified and provide the
  6539. 5:32:04password.
  6540. 5:32:08Then simply add return.
  6541. 5:32:13After that we'll add const salt. We'll
  6542. 5:32:17generate the salt for encrypting the
  6543. 5:32:19password. So just add cons salt equal to
  6544. 5:32:21await and here we will use the brypt
  6545. 5:32:24package. So just import it. Here we'll
  6546. 5:32:27add import
  6547. 5:32:29brypt from brypt package. And uh after
  6548. 5:32:35that let's add await
  6549. 5:32:38brypt dot hash.
  6550. 5:32:44Let's add await decrypt dot
  6551. 5:32:49gen and provide the digit 10. Then we'll
  6552. 5:32:53add this dot password equal to await.
  6553. 5:32:58Then add brypt
  6554. 5:33:01dot hash that will hash the password. So
  6555. 5:33:04just add this dot password and provide
  6556. 5:33:08the salt here.
  6557. 5:33:10So now we'll get the encrypted password.
  6558. 5:33:13Now after that let's add one method here
  6559. 5:33:16that is for compare password. So just
  6560. 5:33:19add compare password method. Let's add
  6561. 5:33:22user schema dot methods dot compare
  6562. 5:33:27password
  6563. 5:33:29equal to
  6564. 5:33:31asynchronous function and in this
  6565. 5:33:34parameter we'll get the
  6566. 5:33:37password
  6567. 5:33:40and uh after that just add return
  6568. 5:33:44and in the return we will use the brypt
  6569. 5:33:47dot compare here
  6570. 5:33:51and provide the password.
  6571. 5:33:53Then provide
  6572. 5:33:55this dot password.
  6573. 5:33:58Now after that we can create the user
  6574. 5:34:01models. Just add export con user equal
  6575. 5:34:04to
  6576. 5:34:05mongus
  6577. 5:34:09dot model and provide the model name
  6578. 5:34:13user.
  6579. 5:34:14then add the schema that is
  6580. 5:34:18user schema. So we have created the user
  6581. 5:34:20model here and this one we have added
  6582. 5:34:22one compare password method and we have
  6583. 5:34:25added the password encryption also. Now
  6584. 5:34:28after that we'll create the controller
  6585. 5:34:31using that we can create the user
  6586. 5:34:34account or user can login with the
  6587. 5:34:36existing account. So let's come here in
  6588. 5:34:40the sidebar. Here you can see we have
  6589. 5:34:41the
  6590. 5:34:43server. In this server create a new
  6591. 5:34:45folder and write the folder name
  6592. 5:34:47controllers.
  6593. 5:34:50In this controllers folder create the
  6594. 5:34:53file that will be ocontroller. So just
  6595. 5:34:55add a new file
  6596. 5:34:58ocontroller
  6597. 5:35:00dot js. In this o controller we have to
  6598. 5:35:05create the controller function. So just
  6599. 5:35:07add
  6600. 5:35:09export async function and the function
  6601. 5:35:11name is register
  6602. 5:35:15and in this function parameter we will
  6603. 5:35:18get the request and response
  6604. 5:35:23right and uh next we'll create the
  6605. 5:35:27another function that is login. So just
  6606. 5:35:31copy this one, paste it here and write
  6607. 5:35:33the function name that is login.
  6608. 5:35:37After that we'll add one more function.
  6609. 5:35:39So just add a new function here and
  6610. 5:35:42write the function name log out.
  6611. 5:35:45And uh after that let's add one more
  6612. 5:35:48function
  6613. 5:35:50that will return the same user data. So
  6614. 5:35:52just add the function name me
  6615. 5:35:56that will return the own data for the
  6616. 5:35:58user. Now let's start with the first one
  6617. 5:36:02that is registration or user register.
  6618. 5:36:05So in this one we need some data from
  6619. 5:36:07the request right. So just add const
  6620. 5:36:11equal to
  6621. 5:36:15the request
  6622. 5:36:18dot body. So in the request body we will
  6623. 5:36:22send some data for user registration. So
  6624. 5:36:24we need the email name and password for
  6625. 5:36:27user registration. So just add name,
  6626. 5:36:30email and password from request body.
  6627. 5:36:32After getting it, we'll add the if
  6628. 5:36:34statement and verify all data is
  6629. 5:36:36available or not. So just add not of
  6630. 5:36:39name or not of email or not of password.
  6631. 5:36:42If any of this data is missing then
  6632. 5:36:44we'll add the response. So just add
  6633. 5:36:46response dot a status
  6634. 5:36:50and set the status 400. Then we'll add
  6635. 5:36:54dot
  6636. 5:36:55JSON
  6637. 5:36:57and uh in this JSON just provide
  6638. 5:37:02object where we'll add the error. So the
  6639. 5:37:06error message will be name, email and
  6640. 5:37:09password are required. Then we'll add
  6641. 5:37:12the return.
  6642. 5:37:15Now suppose all data is available. Then
  6643. 5:37:17we'll add con trim or trimmed email
  6644. 5:37:23equal to use the email
  6645. 5:37:26dot
  6646. 5:37:28to lower case
  6647. 5:37:33and then dot trim.
  6648. 5:37:40After that we'll add con existing equal
  6649. 5:37:43to await. We will find the existing
  6650. 5:37:46data. So just add the user model here.
  6651. 5:37:48Import the user model. You can see it
  6652. 5:37:50has been imported from model/ user and
  6653. 5:37:53provide the file name extension.js.
  6654. 5:37:56Now after that here we'll add user dot
  6655. 5:38:01find one.
  6656. 5:38:03In this find one we will add the email
  6657. 5:38:08because the email id is unique. So we
  6658. 5:38:10have added email and provide this
  6659. 5:38:13trimmed email and we will find the
  6660. 5:38:15existing user. Now we'll add if
  6661. 5:38:18statement if existing is true. It means
  6662. 5:38:21we have the user existing with this
  6663. 5:38:23email id. In this case we cannot create
  6664. 5:38:26an account. So just copy this statement
  6665. 5:38:28paste it here. We will add response
  6666. 5:38:30status 400 then JSON error and the error
  6667. 5:38:34message is an account with this email
  6668. 5:38:38already exist and then return. Now
  6669. 5:38:41suppose the existing is false. In this
  6670. 5:38:43case we can create the user data. So
  6671. 5:38:45just add con user equal to await and use
  6672. 5:38:49the user model.
  6673. 5:38:51Let's add capital U for the user model
  6674. 5:38:54dot create method.
  6675. 5:38:57It will create a new user and provide
  6676. 5:38:59the name. Then add the email.
  6677. 5:39:07In the email, we will store the
  6678. 5:39:10trimmed email. Then we'll add the
  6679. 5:39:12password.
  6680. 5:39:15Right? So it will create a new user in
  6681. 5:39:18the database. After creating the user,
  6682. 5:39:20we have to set the sessions. It means we
  6683. 5:39:23will set the cookies in the session.
  6684. 5:39:25Using that we will authenticate the user
  6685. 5:39:28for every request. So for that we'll
  6686. 5:39:31create a new function. So here let's add
  6687. 5:39:35comment called helper to set cookies.
  6688. 5:39:41Let's add con set session cookie equal
  6689. 5:39:45to
  6690. 5:39:47add a function and provide the request
  6691. 5:39:53and then provide payload.
  6692. 5:39:57Now in this one we'll add con we'll
  6693. 5:40:00generate a token. For generating the
  6694. 5:40:02token we'll add con token and equal to
  6695. 5:40:05we will use JSON web token package. So
  6696. 5:40:07just import the JSON web token here. So
  6697. 5:40:10just add import JWT from
  6698. 5:40:14JSON web token and just add JWT
  6699. 5:40:18dot sign
  6700. 5:40:22then provide the payload here. Then add
  6701. 5:40:24comma and here we have to add one secret
  6702. 5:40:27key that we will store in the env. So
  6703. 5:40:30just open env file and uh in this one
  6704. 5:40:36let me add one environment variable like
  6705. 5:40:39JWT
  6706. 5:40:41secret and here you can add any secret
  6707. 5:40:43key. So just add any key here
  6708. 5:40:47you can add anything in this secret key
  6709. 5:40:50and after that let's come back here
  6710. 5:40:53in the user controller or o controller.
  6711. 5:40:56So in this o controller
  6712. 5:40:59we are creating this set session cookie
  6713. 5:41:01and provided this JWT sign payload and
  6714. 5:41:05then provide the secret key. So let's
  6715. 5:41:07add
  6716. 5:41:08const JWT secret equal to
  6717. 5:41:12our process
  6718. 5:41:14env
  6719. 5:41:16dot
  6720. 5:41:18JWT secret. Then we'll add our
  6721. 5:41:24fallback secret.
  6722. 5:41:27Now after that
  6723. 5:41:29here
  6724. 5:41:31let me provide this JWT secret and then
  6725. 5:41:35provide comma here we'll provide the
  6726. 5:41:38expiry time for this token. So just add
  6727. 5:41:41expires in 30day.
  6728. 5:41:44After generating the token, let me
  6729. 5:41:46provide
  6730. 5:41:48response dot
  6731. 5:41:52cookie
  6732. 5:41:53in this one. Just add the token,
  6733. 5:41:58comma, and provide the token.
  6734. 5:42:03Then add comma and provide one object.
  6735. 5:42:06In this one, provide HTTP only true.
  6736. 5:42:10Then we'll add secure. So let's add
  6737. 5:42:15secure it will be process env
  6738. 5:42:19equal to production if it is production
  6739. 5:42:21then we'll add secure true then we'll
  6740. 5:42:24add same site it will be lax
  6741. 5:42:27then we will add max age so just add
  6742. 5:42:31this max age it means it will expire in
  6743. 5:42:3430 days then we'll add the path slash
  6744. 5:42:39so we have to provide these
  6745. 5:42:40configuration for the cookie
  6746. 5:42:42Now after that let's come here in the
  6747. 5:42:45controller function and uh after
  6748. 5:42:48generating the user data let's add this
  6749. 5:42:51function set session cookie in this one
  6750. 5:42:55just add the response then add object
  6751. 5:42:59with user id that is the payload right
  6752. 5:43:03so just add the user id it will be the
  6753. 5:43:07user
  6754. 5:43:09dot ID
  6755. 5:43:11Then we'll add dot
  6756. 5:43:15to string.
  6757. 5:43:18Then we'll add the
  6758. 5:43:21comma email.
  6759. 5:43:25In this email just add
  6760. 5:43:28user
  6761. 5:43:30dot email.
  6762. 5:43:34Now after that we can send the response
  6763. 5:43:36to user. So just add response dot a
  6764. 5:43:39status to not one then dot JSON and in
  6765. 5:43:45this response simply add the user
  6766. 5:43:48property. In this user property provide
  6767. 5:43:50the underscore id. It will be
  6768. 5:43:55user dot id.
  6769. 5:44:00Then we'll add the name. So the name
  6770. 5:44:03will be
  6771. 5:44:06user dot name. Then provide email.
  6772. 5:44:12Email will be the user
  6773. 5:44:16dot email.
  6774. 5:44:19So we have created our user registration
  6775. 5:44:21function.
  6776. 5:44:24After registration, we'll complete the
  6777. 5:44:26user login function. So let me just copy
  6778. 5:44:29the entire code from here and paste it
  6779. 5:44:32here in this login function. In this one
  6780. 5:44:35you can see we are getting the name,
  6781. 5:44:37email, password. So for login we only
  6782. 5:44:39need the email and password. Remove this
  6783. 5:44:41name. So we have the email and password.
  6784. 5:44:44Then we'll add if not of email and not
  6785. 5:44:47of password. So we have added either
  6786. 5:44:50email or password is not available. In
  6787. 5:44:53this case, we'll set the status 400 and
  6788. 5:44:55the message is email and password are
  6789. 5:44:58required.
  6790. 5:44:59So this is the error message. Then we'll
  6791. 5:45:02add
  6792. 5:45:04the statement to find the user using
  6793. 5:45:06this email id. So let's add
  6794. 5:45:09con user
  6795. 5:45:12equal to await user.find one and provide
  6796. 5:45:15the email. So the email will be our
  6797. 5:45:19email that we are getting from the
  6798. 5:45:21request. then dot
  6799. 5:45:25to lower case then dot
  6800. 5:45:30trim.
  6801. 5:45:32Now after that we'll add if user not
  6802. 5:45:35available. So just add not of user.
  6803. 5:45:38Suppose we could not find any user with
  6804. 5:45:40this ML ID. Then we will add the
  6805. 5:45:43response with a status 400 or let's add
  6806. 5:45:464.1
  6807. 5:45:48then JSON error and provide the error
  6808. 5:45:51message that is invalid email or
  6809. 5:45:53password. Now after that let's add the
  6810. 5:45:58password check. Suppose the user is
  6811. 5:46:00available with the simil ID. Then we'll
  6812. 5:46:01add const is valid equal to
  6813. 5:46:05await and provide the user
  6814. 5:46:09dot
  6815. 5:46:11compare password
  6816. 5:46:14method. So just add the compare password
  6817. 5:46:17and simply add the password here.
  6818. 5:46:20So it will compare the given password
  6819. 5:46:22with the saved password. And let's add
  6820. 5:46:26if not of is valid
  6821. 5:46:29in this case just add the response with
  6822. 5:46:33a status 4.1 and message is invalid
  6823. 5:46:36email or password and return. Now
  6824. 5:46:38suppose the password is valid in this
  6825. 5:46:40case we will set the session. So here
  6826. 5:46:43we'll use set session cookie
  6827. 5:46:46where we'll add the response then add
  6828. 5:46:48the object with user id
  6829. 5:46:52and in this user id we'll add user dot
  6830. 5:46:55id dot to string and then we'll add the
  6831. 5:46:58email it will be user do email then
  6832. 5:47:00we'll add response do a status so let's
  6833. 5:47:03add the status 2.1 then JSON in the JSON
  6834. 5:47:07we'll add the user property where we'll
  6835. 5:47:09add the underscore id name and email.
  6836. 5:47:13That's it. So, we have completed the
  6837. 5:47:16user login function. Now, after that
  6838. 5:47:19just complete this log out. In this
  6839. 5:47:22logout function, we don't need anything
  6840. 5:47:24from the request. So, here we'll add
  6841. 5:47:26underscore request. Now, after that,
  6842. 5:47:28just add the response dot
  6843. 5:47:33cookie and uh in this one just add the
  6844. 5:47:37cookie name that is token and provide
  6845. 5:47:39the empty string here. So just add comma
  6846. 5:47:42empty string and then we'll add the
  6847. 5:47:45configuration in this object. So in this
  6848. 5:47:48object let's provide the http only true
  6849. 5:47:51secure it will be process environment
  6850. 5:47:55equal to production. Then same site lags
  6851. 5:47:58max zero and path/ now after that simply
  6852. 5:48:01add response dot json. In this JSON
  6853. 5:48:06provide the success property and provide
  6854. 5:48:10true. So we have created the log out
  6855. 5:48:13function also. And after that we have
  6856. 5:48:15the last function that is me that will
  6857. 5:48:17return the user's own data. So here
  6858. 5:48:19let's add the if statement if
  6859. 5:48:24not of request do user. It means we
  6860. 5:48:27don't have the user data in the request.
  6861. 5:48:29And this user property will be added
  6862. 5:48:31using a middleware that we will create
  6863. 5:48:33after creating this controller. So here
  6864. 5:48:36we'll add the response dot a status and
  6865. 5:48:39provide the status 4.1. Then we'll add
  6866. 5:48:43dot JSON. In this JSON provide the error
  6867. 5:48:48message that is not authorized. So if
  6868. 5:48:51the user property is not available in
  6869. 5:48:52the request, we'll display this message
  6870. 5:48:55in the return that is not authorized.
  6871. 5:48:58And then we'll add the return.
  6872. 5:49:03Correct? Now suppose the user is
  6873. 5:49:05available. So let's add con user equal
  6874. 5:49:09to await.
  6875. 5:49:11Then we'll add
  6876. 5:49:13user model dot
  6877. 5:49:17find by ID.
  6878. 5:49:19And let's add the request
  6879. 5:49:24dot
  6880. 5:49:26user dot
  6881. 5:49:30user ID.
  6882. 5:49:33Then we'll add dot select
  6883. 5:49:38and in this select provide minus
  6884. 5:49:41password.
  6885. 5:49:45So it will exclude the password and
  6886. 5:49:48after that we'll add if statement if not
  6887. 5:49:50of user
  6888. 5:49:52then add
  6889. 5:49:54response dot a status 44 and provide the
  6890. 5:49:57message user not found and then return
  6891. 5:50:03and finally here we'll add the response
  6892. 5:50:06dot JSON and in this JSON add the user
  6893. 5:50:10data just add the user now we have to
  6894. 5:50:14add this request test dot user using a
  6895. 5:50:16middleware. So let me just create that
  6896. 5:50:18middleware also that will get executed
  6897. 5:50:20before executing our controller
  6898. 5:50:23function.
  6899. 5:50:25Let me open this sidebar and in this
  6900. 5:50:28server we'll create a new folder called
  6901. 5:50:31middleware.
  6902. 5:50:39In this middleware folder create a new
  6903. 5:50:41file and write the file name o
  6904. 5:50:43middleware.js. JS
  6905. 5:50:48[snorts]
  6906. 5:50:54in this O middleware we will import the
  6907. 5:50:57JWT from JSON web token and then we'll
  6908. 5:51:00create a function. So just add export
  6909. 5:51:02function and the function name is O
  6910. 5:51:04middleware and in this function
  6911. 5:51:07parameter we'll get the request response
  6912. 5:51:09and the next function.
  6913. 5:51:13Now let's add if statement and before
  6914. 5:51:16that let me find the token from the
  6915. 5:51:19request. So just add const
  6916. 5:51:22token equal to
  6917. 5:51:26the request dot cookies
  6918. 5:51:34dot
  6919. 5:51:35token.
  6920. 5:51:38Now we'll check the token availability.
  6921. 5:51:41So just add if not of token. If token is
  6922. 5:51:44not available then simply add the
  6923. 5:51:47response with a status 4.1 and provide
  6924. 5:51:50the
  6925. 5:51:51JSON with the error message that is
  6926. 5:51:54access denied no session token provided
  6927. 5:51:57and suppose the token is available then
  6928. 5:51:59we'll add the try catch statement here
  6929. 5:52:01and in this try block we'll decode the
  6930. 5:52:03token. So just add const decoded equal
  6931. 5:52:06to
  6932. 5:52:08JWT dot verify
  6933. 5:52:12and provide the token and then provide
  6934. 5:52:16the process env
  6935. 5:52:20dot
  6936. 5:52:22JWT secret
  6937. 5:52:26or
  6938. 5:52:28fallback secret.
  6939. 5:52:32Now after that let's add the request
  6940. 5:52:36dot user
  6941. 5:52:40equal to decoded. So we have added the
  6942. 5:52:43request dot user property and in this
  6943. 5:52:45one we'll store the decoded value and
  6944. 5:52:47then we'll execute the controller using
  6945. 5:52:49the next function. Now let's come here
  6946. 5:52:51in the catch block we'll add the error
  6947. 5:52:54and provide response do status 4.1 and
  6948. 5:52:57then provide the JSON with the error
  6949. 5:52:59session expired or invalid. Please sign
  6950. 5:53:01in again. So we have created the
  6951. 5:53:04middleware that will get executed before
  6952. 5:53:06executing our controller. Now after
  6953. 5:53:08creating the controller and middleware,
  6954. 5:53:10we will create the route. So let's open
  6955. 5:53:13the sidebar and in this server create a
  6956. 5:53:15new folder called routes.
  6957. 5:53:18In this routes folder, create a file and
  6958. 5:53:21write the file name routes.js JS
  6959. 5:53:28where you will add all the routes for
  6960. 5:53:29the authentication feature. So in this
  6961. 5:53:31one we have to create the router. So
  6962. 5:53:34let's add import router from the express
  6963. 5:53:38package and uh after that just add con
  6964. 5:53:41router equal to this router.
  6965. 5:53:45Now in this router we'll add different
  6966. 5:53:48endpoint. So just add oouter
  6967. 5:53:52dot post method and provide the endpoint
  6968. 5:53:56path. It will be / register and at this
  6969. 5:54:00end point we will execute the user
  6970. 5:54:02registration function. So just add
  6971. 5:54:06register function from the controllers /
  6972. 5:54:10controller and then js.
  6973. 5:54:13Now duplicate it. In the second one
  6974. 5:54:15we'll add the path. It will be / login
  6975. 5:54:17and provide the function that is login
  6976. 5:54:21and import this function from the
  6977. 5:54:25same file.
  6978. 5:54:29You can see here we have the register
  6979. 5:54:30from the controller.
  6980. 5:54:33Let's update it.
  6981. 5:54:36We will add ocontroller
  6982. 5:54:39dot js and then we'll add
  6983. 5:54:44login from the same file controllers o
  6984. 5:54:47controller and here we have the login
  6985. 5:54:48and register. Now just duplicate it here
  6986. 5:54:51we'll add / logout and here also we'll
  6987. 5:54:57add the controller function
  6988. 5:55:00that is logout. It has been imported.
  6989. 5:55:02Now after that let's duplicate it. Here
  6990. 5:55:06we will change the method. It will be
  6991. 5:55:09get method. Just add oouter.get
  6992. 5:55:13and then provide the path. It will be
  6993. 5:55:15me. And then provide the middleware that
  6994. 5:55:17is
  6995. 5:55:20o middleware. This o middleware has been
  6996. 5:55:23imported from the middleware folder. O
  6997. 5:55:25middleware.js.
  6998. 5:55:26Then provide the comma and function that
  6999. 5:55:29is me and import this function. You can
  7000. 5:55:31see this function has been imported here
  7001. 5:55:33from the controller. Now let's export
  7002. 5:55:36this router from here. So just add
  7003. 5:55:38export default and o router. Now we can
  7004. 5:55:42add this o router in our main file that
  7005. 5:55:44is server.js file. So just open the
  7006. 5:55:47server.js
  7007. 5:55:48and uh here let's add our authentication
  7008. 5:55:51route. So just add app
  7009. 5:55:54dot
  7010. 5:55:57use
  7011. 5:55:59provide the path. It will be / ai / o
  7012. 5:56:06then add comma
  7013. 5:56:08o
  7014. 5:56:10router. You can see o router has been
  7015. 5:56:12imported from routes o routes.js.
  7016. 5:56:16So we have created the APIs for user
  7017. 5:56:18authentication where we have created the
  7018. 5:56:21user registration login logout and user
  7019. 5:56:24data API.
  7020. 5:56:27After that we'll review our code using
  7021. 5:56:28code rabbit. So just click here and
  7022. 5:56:30commit the changes. So let me add
  7023. 5:56:38backend server
  7024. 5:56:41created
  7025. 5:56:45with
  7026. 5:56:46authentication feature
  7027. 5:56:51commit changes and sync changes.
  7028. 5:56:57So it will commit the changes on GitHub
  7029. 5:57:00in the development branch. Now we'll
  7030. 5:57:02come back here in the GitHub repo
  7031. 5:57:06and uh open the repository and click on
  7032. 5:57:10this button compare and pull request.
  7033. 5:57:13Then create pull request.
  7034. 5:57:18After creating the pull request, the
  7035. 5:57:20code rabbit will start analyzing the
  7036. 5:57:22code.
  7037. 5:57:25You can see the code rabbit is running
  7038. 5:57:27and it is analyzing the code.
  7039. 5:57:31Now you can see the review has been
  7040. 5:57:33completed. Here we have the review
  7041. 5:57:34summary. And after that if I scroll down
  7042. 5:57:37you can see here we have some critical
  7043. 5:57:38issue in this ocontroller.js
  7044. 5:57:42and it says
  7045. 5:57:45remove the fallback secret. So we will
  7046. 5:57:49keep it. Now let's come to the second
  7047. 5:57:50one. Here we have ocontroller.js. JS. In
  7048. 5:57:54this one,
  7049. 5:57:56we have to
  7050. 5:58:02update our
  7051. 5:58:05code. Let me open this postfix. You can
  7052. 5:58:08see we have added the request but it
  7053. 5:58:10will be response because in the code we
  7054. 5:58:12are sending the response only response
  7055. 5:58:14docy right. So just come back to the VS
  7056. 5:58:16code and open the O controller and in
  7057. 5:58:20this O controller you can see we have
  7058. 5:58:23session cookie set session cookie and
  7059. 5:58:26here we are using the request but it is
  7060. 5:58:28not used in the function we are using
  7061. 5:58:30the response so just copy and paste it
  7062. 5:58:32here we are using response and payload
  7063. 5:58:34save the changes now just see the next
  7064. 5:58:37suggestion I'll scroll down and see we
  7065. 5:58:41have the in this middleware in this one
  7066. 5:58:45we have some suggestion. So what we have
  7067. 5:58:48to do we have to add the return right.
  7068. 5:58:51So let's just come back here in the O
  7069. 5:58:53middleware and you can see we have if
  7070. 5:58:56not of token then we'll add the return
  7071. 5:58:58and this response. Save the changes. Now
  7072. 5:59:02just come back and uh see the next
  7073. 5:59:04user.js in this user.js
  7074. 5:59:10use a normal function instead of the add
  7075. 5:59:12function. So just come back here and
  7076. 5:59:14open the user.js. In this user dot dot
  7077. 5:59:16dot dot dot dot dot dot dot dot dojs you
  7078. 5:59:17can see we have added the add function
  7079. 5:59:20right. So let me update it here. We'll
  7080. 5:59:23add
  7081. 5:59:28a sync
  7082. 5:59:32function like this. Save the changes. So
  7083. 5:59:35we have added a sync function and in
  7084. 5:59:38this one we have this this dot modified.
  7085. 5:59:41Now let's see the next suggestion from
  7086. 5:59:44the code rabbit. So we have the
  7087. 5:59:46suggestion for this
  7088. 5:59:48server.js. In this server do js it is
  7089. 5:59:52suggesting to provide the await. Let's
  7090. 5:59:55come back and uh open server.js and we
  7091. 5:59:58are calling this connect to db function
  7092. 6:00:00or connect to database function. So
  7093. 6:00:02before that we'll add the await and then
  7094. 6:00:04connect to database
  7095. 6:00:07and after that let's see the
  7096. 6:00:12next one. Here we have the isue for
  7097. 6:00:14origin because we have not updated the
  7098. 6:00:17env file on the
  7099. 6:00:20GitHub. Then we have server.js and do
  7100. 6:00:23not return internal exception messages.
  7101. 6:00:27Just skip it. And now we have updated
  7102. 6:00:29all the code according to the code
  7103. 6:00:33rabbit review. Now we'll click on this
  7104. 6:00:34merge pull request and confirm merge.
  7105. 6:00:38That's it and come back to the
  7106. 6:00:40repository.
  7107. 6:00:42Now let me just come here and click on
  7108. 6:00:44this
  7109. 6:00:47pull. So it will pull the latest
  7110. 6:00:48changes. So after creating the APIs for
  7111. 6:00:52authentication, next we have to create
  7112. 6:00:54the APIs for the project.
  7113. 6:00:58So that we can create the project using
  7114. 6:01:00AI. We can create the website using AI.
  7115. 6:01:06To create the API for project feature,
  7116. 6:01:09we will store the project data in
  7117. 6:01:12database. And to store any data in
  7118. 6:01:14database, we need to create the model.
  7119. 6:01:16So let's create the project model. So
  7120. 6:01:20let's open the sidebar. And here you can
  7121. 6:01:22see we have a
  7122. 6:01:25models folder. In this folder, create a
  7123. 6:01:27file called project.js.
  7124. 6:01:37Here also we have to create the model.
  7125. 6:01:39So I'll copy the entire code from the
  7126. 6:01:40user model. Just copy everything and
  7127. 6:01:43paste it here. And let's update this
  7128. 6:01:45code. So in this one we have the
  7129. 6:01:50brypt. Let's remove it. Here we have
  7130. 6:01:53user schema. And after that we have the
  7131. 6:01:56user schema pre remove this one and
  7132. 6:01:58remove this compare password method
  7133. 6:02:01also. So now it is simple here we have
  7134. 6:02:03the
  7135. 6:02:05schema from mongos and we are creating
  7136. 6:02:08the user schema. So instead of this user
  7137. 6:02:11schema here we are going to create the
  7138. 6:02:14project schema. So let's add project a
  7139. 6:02:17schema equal to new schema. Now in this
  7140. 6:02:20project a schema we have to define all
  7141. 6:02:22the properties. So first we'll add the
  7142. 6:02:25name. So it will be the name of project.
  7143. 6:02:28The type will be string required true.
  7144. 6:02:32Then we will add the default value. So
  7145. 6:02:34let's add comma and provide the default
  7146. 6:02:38it will be untitled project. So if we
  7147. 6:02:41are not providing the name the project
  7148. 6:02:44name will be untitled project. Then we
  7149. 6:02:47have to add the description. So let's
  7150. 6:02:51copy this one. paste it here.
  7151. 6:02:55We will add the property name. So the
  7152. 6:02:58property name will be description. The
  7153. 6:03:00type will be a string and remove this
  7154. 6:03:03required property. And the default value
  7155. 6:03:06will be empty string.
  7156. 6:03:10Now after that we'll add the next
  7157. 6:03:12property. So the next property will be
  7158. 6:03:15files. Let's add files. I'll clear this
  7159. 6:03:18one.
  7160. 6:03:21So here we have files and the type will
  7161. 6:03:23be [snorts]
  7162. 6:03:27our schema
  7163. 6:03:29dot
  7164. 6:03:32types
  7165. 6:03:34dot mixed.
  7166. 6:03:42So this is the
  7167. 6:03:44type for this files property and then
  7168. 6:03:47we'll add the default value here. So
  7169. 6:03:49let's clear it and simply add default.
  7170. 6:03:52In this default we will add the empty
  7171. 6:03:55object.
  7172. 6:03:57Now after that we have to add the
  7173. 6:03:59messages. So let's copy this paste it
  7174. 6:04:02here. We will add the property name. So
  7175. 6:04:05it will be messages. Then we'll add the
  7176. 6:04:08type. So in this type we have to create
  7177. 6:04:12another schema. So let's add the empty
  7178. 6:04:14array here. And here we will provide the
  7179. 6:04:17another schema. and then we'll add the
  7180. 6:04:19default. So in this default we'll add
  7181. 6:04:21the empty
  7182. 6:04:24array. Now let's add the schema for this
  7183. 6:04:28message type. So here let's provide
  7184. 6:04:33con schema or let me just copy this
  7185. 6:04:35entire code. Copy and paste it here.
  7186. 6:04:42We will change the name. It will be
  7187. 6:04:44message schema.
  7188. 6:04:47Now after that just provide this message
  7189. 6:04:49schema here in this type
  7190. 6:04:52correct. Now after that let's complete
  7191. 6:04:55this message schema only. So here we'll
  7192. 6:04:57add the
  7193. 6:04:59object. It's already there. So in this
  7194. 6:05:02object we'll add the first property. So
  7195. 6:05:04the first property will be role for the
  7196. 6:05:07message. In this role first we'll add
  7197. 6:05:09the type and the type will be a string.
  7198. 6:05:11Then we'll add the enum. In this enum
  7199. 6:05:14we'll add the accepted values. So it
  7200. 6:05:17could be user or assistant. Then we'll
  7201. 6:05:20add the required it will be true.
  7202. 6:05:25So this is the type for the role. After
  7203. 6:05:27that we have to add the message
  7204. 6:05:31content. So the content type will be a
  7205. 6:05:34string and required true. After this
  7206. 6:05:37content we'll add the time stamp. So the
  7207. 6:05:40time stamp will be type date and default
  7208. 6:05:44value will be date do.now. Now here we
  7209. 6:05:48don't have to generate the id. So just
  7210. 6:05:50add one object here and in this object
  7211. 6:05:53provide underscore
  7212. 6:05:56id
  7213. 6:05:57and provide false.
  7214. 6:06:00So it will not generate the id for this
  7215. 6:06:03message.
  7216. 6:06:06Now after that let's come here and
  7217. 6:06:07complete our project schema. In this
  7218. 6:06:10project schema we have added the name,
  7219. 6:06:12description, files and then messages.
  7220. 6:06:15After that we have to add the version.
  7221. 6:06:17So it will be project version. So the
  7222. 6:06:20type will be number. Default value will
  7223. 6:06:23be zero. After that we have to add the
  7224. 6:06:26owner. Right? So it will be the project
  7225. 6:06:30owner. So just add owner
  7226. 6:06:33in this owner property.
  7227. 6:06:35Let's provide the type and the type will
  7228. 6:06:38be our
  7229. 6:06:42user data. Right? So just add type
  7230. 6:06:44property. In this one just add
  7231. 6:06:47schema
  7232. 6:06:49dot types dot object ID and then we'll
  7233. 6:06:56add the reference. So let's add ref.
  7234. 6:07:00And in this reference we'll add the user
  7235. 6:07:02model.
  7236. 6:07:05Then we'll add the required.
  7237. 6:07:08So the required property will be
  7238. 6:07:11true.
  7239. 6:07:17Next we will add the another property
  7240. 6:07:19that is published. So just add comma and
  7241. 6:07:22provide published. The type will be
  7242. 6:07:24boolean and default value will be false.
  7243. 6:07:27So by default the published will be
  7244. 6:07:29false and user can make the project
  7245. 6:07:33published. So it will be accessible by
  7246. 6:07:35any user without authentication. Then
  7247. 6:07:38we'll add the project a status. So let's
  7248. 6:07:41add a status. In this a status we'll add
  7249. 6:07:43the type a string and then we'll add the
  7250. 6:07:45enum. In this enum we have to add all
  7251. 6:07:48the
  7252. 6:07:50accepted values in array. So the project
  7253. 6:07:55status could be pending,
  7254. 6:07:59generating,
  7255. 6:08:01revising,
  7256. 6:08:03completed or failed.
  7257. 6:08:06Correct? Now just add comma and here we
  7258. 6:08:09will add the default value for the
  7259. 6:08:11status. So the default value will be
  7260. 6:08:13pending.
  7261. 6:08:15Next we will add the
  7262. 6:08:19files planned. So let's add the property
  7263. 6:08:23name files planned. It will be type
  7264. 6:08:29and in this type we have to add the
  7265. 6:08:32a schema only. So let's add the type and
  7266. 6:08:35provide the array like this and then add
  7267. 6:08:38comma default and the default value will
  7268. 6:08:41be empty array. And uh let's add the
  7269. 6:08:47next property that will be files
  7270. 6:08:50generated.
  7271. 6:08:52In this files generated just add the
  7272. 6:08:55object with the type.
  7273. 6:09:01In this type we will add the array with
  7274. 6:09:05string.
  7275. 6:09:07Then we will add the default.
  7276. 6:09:12And in this default we'll add the empty
  7277. 6:09:14array.
  7278. 6:09:16Next we will add current file.
  7279. 6:09:22So in this current file add the type a
  7280. 6:09:25string and default value will be null.
  7281. 6:09:30Now we will add error. In this error
  7282. 6:09:33property we will add the type a string
  7283. 6:09:35and default is null.
  7284. 6:09:37Correct? Now after that let me complete
  7285. 6:09:40this files plant type is empty array but
  7286. 6:09:44here we have to add the schema of the
  7287. 6:09:46files plant. So let's scroll up here
  7288. 6:09:50we'll add
  7289. 6:09:52con
  7290. 6:09:55plant files schema equal to new schema.
  7291. 6:10:01In this new schema add one object. In
  7292. 6:10:04this object we'll add the path.
  7293. 6:10:07We'll add the path property and in this
  7294. 6:10:09path property provide the type string
  7295. 6:10:12required true.
  7296. 6:10:14So for the files there will be a path
  7297. 6:10:17and after that we will add the
  7298. 6:10:19description. In the description just add
  7299. 6:10:21the type string and required true. So
  7300. 6:10:24there will be a path and description for
  7301. 6:10:26the files. Now we'll add the comma here
  7302. 6:10:29and provide another object where we'll
  7303. 6:10:31add underscore id
  7304. 6:10:33and make it false. So it will not
  7305. 6:10:36generate the ID for this
  7306. 6:10:39plant files schema. Now just add it here
  7307. 6:10:43inside this array under this files plant
  7308. 6:10:48like this. Save the changes and after
  7309. 6:10:50that just come here. You can see here we
  7310. 6:10:52have export con user. So instead of user
  7311. 6:10:55we will add project export con project
  7312. 6:10:58equal to mongus domodel and provide the
  7313. 6:11:01model name. So the model name will be
  7314. 6:11:04project and here we have to add the
  7315. 6:11:06schema that is
  7316. 6:11:08project schema.
  7317. 6:11:11So we have created the
  7318. 6:11:13project model and using this project
  7319. 6:11:16model we can store the data in database.
  7320. 6:11:20Now we can create our controllers.
  7321. 6:11:24So let me open the sidebar. Here we have
  7322. 6:11:28the controllers folder. In this one,
  7323. 6:11:30create a file and write the file name
  7324. 6:11:33project controller.js.
  7325. 6:11:37Now in this controller file, we have to
  7326. 6:11:39create multiple controller function for
  7327. 6:11:42different APIs for different
  7328. 6:11:45functionality. So here
  7329. 6:11:48let's add one comment.
  7330. 6:11:51we will add the comment that will be the
  7331. 6:11:54method type or API type and then API
  7332. 6:11:59endpoint. So the type will be post and
  7333. 6:12:01the path will be / API/ projects
  7334. 6:12:05right and uh let's add the description
  7335. 6:12:09in the comment. So here we'll add the
  7336. 6:12:11description that is
  7337. 6:12:13create a new project from an AI prompt.
  7338. 6:12:18So the first controller function will be
  7339. 6:12:20used for creating a new project using AI
  7340. 6:12:24prompt. So let's create a function and
  7341. 6:12:27export it. We'll add export
  7342. 6:12:31async function and write the function
  7343. 6:12:34name
  7344. 6:12:36create project.
  7345. 6:12:41Now in this function parameter we'll get
  7346. 6:12:43the request and response
  7347. 6:12:47like this. So right now we have created
  7348. 6:12:50one empty function. After that we have
  7349. 6:12:53to create our next function. So the next
  7350. 6:12:56function will work in the background
  7351. 6:12:59when the project is generating. So it
  7352. 6:13:02will update the
  7353. 6:13:04generated project file in the database.
  7354. 6:13:08Right? So let me add the description
  7355. 6:13:10here.
  7356. 6:13:12that is background worker to progressive
  7357. 6:13:16generate files and update database in
  7358. 6:13:19real time.
  7359. 6:13:21So let's create another function here
  7360. 6:13:24like this and add the function name. So
  7361. 6:13:27I'll provide the function name that is
  7362. 6:13:30run background generation. In this one
  7363. 6:13:34we will get the project ID
  7364. 6:13:37and after that we'll add the prompt
  7365. 6:13:41as parameter.
  7366. 6:13:43Now after that we'll create the
  7367. 6:13:45controller function here. For that we'll
  7368. 6:13:48add the
  7369. 6:13:50method. It will be get and the path will
  7370. 6:13:52be / API/ projects. You can see the API
  7371. 6:13:56endpoint is same here and here but the
  7372. 6:13:59type is different. It is post. It is get
  7373. 6:14:03here. Let's add the description also. So
  7374. 6:14:06we will use this function to display the
  7375. 6:14:08list of all project owned by single
  7376. 6:14:11user. So let's add the comment that is
  7377. 6:14:14list all projects owned by the user
  7378. 6:14:17summary only no files contents. Right?
  7379. 6:14:22So
  7380. 6:14:25let's add the function from here. Just
  7381. 6:14:28copy this
  7382. 6:14:30and paste it here.
  7383. 6:14:33Now in this previous function you can
  7384. 6:14:35see we have added export. So let me
  7385. 6:14:37remove this export because this function
  7386. 6:14:38will be used here only. We'll add async
  7387. 6:14:41function. That's it. Now in this one we
  7388. 6:14:44have added export async function and
  7389. 6:14:48let's update the function name. So the
  7390. 6:14:50function name will be
  7391. 6:14:52list projects.
  7392. 6:14:58We have added the function name here
  7393. 6:15:00list projects.
  7394. 6:15:02Now after that we'll create the another
  7395. 6:15:05function. So first we'll add the
  7396. 6:15:07comment. So let me just duplicate the
  7397. 6:15:09entire thing.
  7398. 6:15:11We will update the comment.
  7399. 6:15:15So the first comment is the method type.
  7400. 6:15:18It will be get and the path will be /
  7401. 6:15:20API/ projects and id. And then we'll add
  7402. 6:15:23the description that is get full project
  7403. 6:15:26details. It means we will get the
  7404. 6:15:28complete details of the individual
  7405. 6:15:30project. For that we'll add the function
  7406. 6:15:33name that is
  7407. 6:15:36get project and add the request and
  7408. 6:15:39response in the parameter.
  7409. 6:15:41After that we have to add the next
  7410. 6:15:43function. So copy and paste it here. We
  7411. 6:15:46will update the details. So first we'll
  7412. 6:15:49add the
  7413. 6:15:51method. it will be delete and the path
  7414. 6:15:53will be / API/ projects/ colon id and
  7415. 6:15:58then we'll add the description that is
  7416. 6:16:00delete a project. So we will use this
  7417. 6:16:02function to delete a project. So just
  7418. 6:16:04add the function name called delete
  7419. 6:16:07project and here also we'll get the
  7420. 6:16:08request and response in the parameter.
  7421. 6:16:11Now duplicate this one
  7422. 6:16:14here we will add
  7423. 6:16:18the
  7424. 6:16:20method. it will be put and the endpoint
  7425. 6:16:23API projects id and files. Then we'll
  7426. 6:16:27add the description that is update
  7427. 6:16:28project files. So it will update the
  7428. 6:16:31project file when we will edit the code
  7429. 6:16:33manually. So we have added manual edits.
  7430. 6:16:36So just add the function name that is
  7431. 6:16:40update project files.
  7432. 6:16:43Now let's duplicate it.
  7433. 6:16:48Here we will add the
  7434. 6:16:51comment that will be type post and the
  7435. 6:16:55path will be / API projects id and
  7436. 6:16:58publish. So using this we can publish
  7437. 6:17:02any project. We can mark it as public.
  7438. 6:17:05So it will be visible to anyone.
  7439. 6:17:08Right? So let's add export as sync
  7440. 6:17:13function and provide the function name
  7441. 6:17:15publish project.
  7442. 6:17:17Right now after that we have to add one
  7443. 6:17:20more function here.
  7444. 6:17:23So let's add the details that will be
  7445. 6:17:26the method type. Then we'll add the
  7446. 6:17:29endpoint/ API/ project/ public and id.
  7447. 6:17:34And then we'll add the description that
  7448. 6:17:36is
  7449. 6:17:38get publicly published project details
  7450. 6:17:41without o. It means using this function
  7451. 6:17:45we can display the details of individual
  7452. 6:17:48project and it can be visible to anyone
  7453. 6:17:51who is not authenticated. So here we'll
  7454. 6:17:54add the function name that is get public
  7455. 6:17:58project. So we have added all empty
  7456. 6:18:01functions for this project controller.
  7457. 6:18:03Now we will add the functionality in
  7458. 6:18:05each function one by one. So let's start
  7459. 6:18:08with the first one that is create
  7460. 6:18:10project. For this create project, we
  7461. 6:18:12need a prompt and we'll get the prompt
  7462. 6:18:14from the request body. So let's add
  7463. 6:18:16const
  7464. 6:18:18braces prompt
  7465. 6:18:21equal to
  7466. 6:18:23our request dot body. Now after getting
  7467. 6:18:28the prompt, let's add if statement if
  7468. 6:18:32let's add not of prompt. So if the
  7469. 6:18:35prompt is not available or
  7470. 6:18:39type of
  7471. 6:18:41prompt
  7472. 6:18:43not equal to a string
  7473. 6:18:46in this case
  7474. 6:18:50just add response dot a status it will
  7475. 6:18:52be 400. Then we will add
  7476. 6:18:57dot JSON with the error and the error
  7477. 6:19:01message will be prompt is required
  7478. 6:19:04and then we'll add return
  7479. 6:19:09correct. Now suppose the prompt is
  7480. 6:19:11available and the type of prompt is a
  7481. 6:19:13string. In this case we will check the
  7482. 6:19:16user is available or not. So just add if
  7483. 6:19:22not of
  7484. 6:19:24request dot user this user property will
  7485. 6:19:28be added using the middleware and we are
  7486. 6:19:31checking the user property is available
  7487. 6:19:34or not. If it is not available then
  7488. 6:19:36let's add it here. Add this statement.
  7489. 6:19:39We will provide response do a status 4.1
  7490. 6:19:43then JSON and provide the error and the
  7491. 6:19:46error message is unauthorized
  7492. 6:19:52and then return. Now suppose the user is
  7493. 6:19:55authenticated. In this case we can
  7494. 6:19:58create a project in the database with
  7495. 6:20:01the pending status. So let's add the
  7496. 6:20:04command first that is create project in
  7497. 6:20:07DB immediately with pending status. For
  7498. 6:20:11creating the project we will add con
  7499. 6:20:15project equal to await and then use the
  7500. 6:20:20project model. You can see we are
  7501. 6:20:22getting the suggestion just import it.
  7502. 6:20:23Let's scroll up. You can see the project
  7503. 6:20:26is imported from model/ project and
  7504. 6:20:28write the file name extension.js.
  7505. 6:20:31Let's move it here at the first line.
  7506. 6:20:35So here you can see we have added a
  7507. 6:20:36weight project model then dot create
  7508. 6:20:40method. So it will help us to create a
  7509. 6:20:43new project in the database. Now let's
  7510. 6:20:46add the details in this object. So first
  7511. 6:20:48we'll add the name.
  7512. 6:20:51So in this name let's add
  7513. 6:20:55planning project.
  7514. 6:20:57Then we will add description. So in the
  7515. 6:21:01description let's add the prompt that we
  7516. 6:21:04have received from the request body.
  7517. 6:21:06Then we'll add the files.
  7518. 6:21:09So initially the files will be empty
  7519. 6:21:13object. Then we'll add the messages.
  7520. 6:21:17Now in this messages let's add the
  7521. 6:21:20array. And in this array
  7522. 6:21:23let's add the first object where we will
  7523. 6:21:27add the role. it will be user. And then
  7524. 6:21:31we'll add the content. And in the
  7525. 6:21:33content we will add the prompt.
  7526. 6:21:36Then we'll add the second message. So
  7527. 6:21:39just duplicate it.
  7528. 6:21:43Here we will add the role assistant.
  7529. 6:21:46In this one we'll add the content and
  7530. 6:21:49the content will be planning project
  7531. 6:21:52structure. Now after that add the comma
  7532. 6:21:55here.
  7533. 6:21:56Here we will add the next property that
  7534. 6:21:58is version.
  7535. 6:22:00So the version will be zero.
  7536. 6:22:04Next we will add the owner and in this
  7537. 6:22:07owner we will add the request dot user
  7538. 6:22:11dot user id. Then we will add the a
  7539. 6:22:14status. So a status will be pending.
  7540. 6:22:16Then we'll add files planned it will be
  7541. 6:22:20empty array. Then files generated it
  7542. 6:22:23will be empty array. And then we'll add
  7543. 6:22:27current files. So the current file will
  7544. 6:22:29be null. And then we'll add the error
  7545. 6:22:32null.
  7546. 6:22:34So using this information, we will
  7547. 6:22:36create a new project in the database.
  7548. 6:22:40After adding this data in database, we
  7549. 6:22:43can start generating our project. For
  7550. 6:22:45that, you can see we have added this
  7551. 6:22:47function run background generation. So
  7552. 6:22:49it will start generating the project in
  7553. 6:22:52the background and it will store the
  7554. 6:22:54data in the database. So let's add the
  7555. 6:22:58commit first that is
  7556. 6:23:02a start background generation and call
  7557. 6:23:04this function. So let's call it here.
  7558. 6:23:08Now in this function we have to provide
  7559. 6:23:09two arguments that will be project ID
  7560. 6:23:12and prompt. To provide it here you can
  7561. 6:23:14see we have the project right. So simply
  7562. 6:23:17add this project then dot
  7563. 6:23:22id and after that we have to add the
  7564. 6:23:26prompt also. So let's add the prompt.
  7565. 6:23:29Now after that you can see we have the
  7566. 6:23:31project ID. So let's convert it into a
  7567. 6:23:33string. So just add dot
  7568. 6:23:36to a string.
  7569. 6:23:39That's it. Now at the end here we'll add
  7570. 6:23:42dot
  7571. 6:23:44catch. So it will catch all errors and
  7572. 6:23:47in this one we'll add the
  7573. 6:23:51function.
  7574. 6:23:52Now let's catch the error here in this
  7575. 6:23:55parameter and after that let's provide
  7576. 6:24:00console dot error
  7577. 6:24:04in this console dot error provide back
  7578. 6:24:06tick and insert the
  7579. 6:24:10background AI file generation error for
  7580. 6:24:13project and then insert the details
  7581. 6:24:16using
  7582. 6:24:18dollar sign curly braces and provide
  7583. 6:24:22project
  7584. 6:24:24dot
  7585. 6:24:26id then colon
  7586. 6:24:30and then add comma error save the
  7587. 6:24:35changes. Now it will keep generating the
  7588. 6:24:40project in the background and after that
  7589. 6:24:42we can send the response here. Let's
  7590. 6:24:44just add response dot
  7591. 6:24:47status and in this status we'll add 2.1
  7592. 6:24:51then we will add dot JSON
  7593. 6:24:56in this JSON add the object where we'll
  7594. 6:24:58add underscore id. So it will be our
  7595. 6:25:02project
  7596. 6:25:05dot
  7597. 6:25:06id.
  7598. 6:25:09Then we will add the name. In this name
  7599. 6:25:12we will add the project
  7600. 6:25:16dot name.
  7601. 6:25:19After that we'll add description. It
  7602. 6:25:21will be project dot description. Then
  7603. 6:25:24we'll add files. It will be empty
  7604. 6:25:27object. Then we'll add the messages. It
  7605. 6:25:30will be project dot messages. Then
  7606. 6:25:32provide version. It will be project dot
  7607. 6:25:35version.
  7608. 6:25:37So we are sending these data in the
  7609. 6:25:39response. Then we'll add the status. It
  7610. 6:25:41will be project dot status. Then files
  7611. 6:25:44planned it will be project
  7612. 6:25:46dotfilesplanned.
  7613. 6:25:48Then files generated it will be project
  7614. 6:25:51dot files generated. Then current file
  7615. 6:25:54it will be project dotcurren file. Then
  7616. 6:25:57error it will be project dot error. And
  7617. 6:26:00then created at property it will be
  7618. 6:26:02project do.created at. So we are sending
  7619. 6:26:06these data in the response and it will
  7620. 6:26:09execute our function that is run
  7621. 6:26:11background generation and in this one we
  7622. 6:26:13will use the AI to generate our project.
  7623. 6:26:16So for now let me skip this function we
  7624. 6:26:18will create it later after creating all
  7625. 6:26:21these
  7626. 6:26:23functions right. So here let's come to
  7627. 6:26:27the next one that is list projects. So
  7628. 6:26:30in this list projects we'll add if
  7629. 6:26:33statement.
  7630. 6:26:35In this if we'll add not of request
  7631. 6:26:40dot user. So if the user is not
  7632. 6:26:43available in the request it means the
  7633. 6:26:45user is not authenticated. So just add
  7634. 6:26:49response status 4.1 JSON error will be
  7635. 6:26:52unauthorized and then we'll add the
  7636. 6:26:54return.
  7637. 6:26:57Now suppose the user is authenticated in
  7638. 6:27:00this case just add con projects
  7639. 6:27:05equal to await and then add the project
  7640. 6:27:10model
  7641. 6:27:12dot find method.
  7642. 6:27:15In this find method add the
  7643. 6:27:18object where we'll add the owner
  7644. 6:27:20property. So this owner property will be
  7645. 6:27:23the
  7646. 6:27:25request
  7647. 6:27:26dot user dot user id.
  7648. 6:27:35Then we will add
  7649. 6:27:39name one description one version one
  7650. 6:27:42created at one and updated at one.
  7651. 6:27:47After that we will add dot sort.
  7652. 6:27:53In this sort provide the object
  7653. 6:27:56where we will add
  7654. 6:28:00updated at
  7655. 6:28:03minus one.
  7656. 6:28:06Now we can send the response here. So
  7657. 6:28:09let's add the
  7658. 6:28:11response do.json JSON and uh in this one
  7659. 6:28:14provide the project
  7660. 6:28:17I mean projects. So here we'll get list
  7661. 6:28:20of projects owned by a single user.
  7662. 6:28:26After that let's come to the next
  7663. 6:28:28function that is get project. So here
  7664. 6:28:31we'll get the details of a single
  7665. 6:28:33project. Right? For creating it
  7666. 6:28:38here we will add the same if statement.
  7667. 6:28:41Just copy this, paste it here. We will
  7668. 6:28:44add if not of request do user. Then
  7669. 6:28:48we'll add the response unauthorized and
  7670. 6:28:51return. And after that we have to find
  7671. 6:28:53the project details. So just add con
  7672. 6:28:56project equal to await. And here we will
  7673. 6:28:58use the project model.
  7674. 6:29:02And in this project model we'll add
  7675. 6:29:05find one method.
  7676. 6:29:08Now in this find one add the object
  7677. 6:29:11where we'll add underscore id and in
  7678. 6:29:14this underscore id just add the request
  7679. 6:29:20dot padams
  7680. 6:29:24because in this request padams we are
  7681. 6:29:26getting the id right so we will add the
  7682. 6:29:27request dot padams dot id and after that
  7683. 6:29:32we'll add the comma and provide the
  7684. 6:29:34owner so the owner property will be
  7685. 6:29:36request dot user dot user id. Now after
  7686. 6:29:40that let's add if statement if not of
  7687. 6:29:45project. If we could not find the
  7688. 6:29:47project data
  7689. 6:29:49in this case just add the response dot a
  7690. 6:29:53status for not four then json with the
  7691. 6:29:56error message project not found and
  7692. 6:29:58return. Now suppose the project data is
  7693. 6:30:01available then we'll add con files
  7694. 6:30:06object it will be empty object then
  7695. 6:30:09we'll add
  7696. 6:30:11for off loop in this for off we'll add
  7697. 6:30:15con path and entry
  7698. 6:30:19then of object dot entries
  7699. 6:30:23then add the project
  7700. 6:30:27dot files
  7701. 6:30:32Then we'll add
  7702. 6:30:34files object. Then add the
  7703. 6:30:40path
  7704. 6:30:42equal to
  7705. 6:30:44entry dot content.
  7706. 6:30:47Now after that we can send the response.
  7707. 6:30:49So let's add response dojson.
  7708. 6:30:54And uh in this JSON let's provide the
  7709. 6:30:57details. So I'll just come here and copy
  7710. 6:31:00this one.
  7711. 6:31:02Copy it and paste it here.
  7712. 6:31:06So you can see in this response dojson
  7713. 6:31:08we are adding underscore id that is
  7714. 6:31:10project dot id then name then
  7715. 6:31:14description and files. In the files
  7716. 6:31:17simply add this
  7717. 6:31:20files object.
  7718. 6:31:22Correct? Then we'll add the messages.
  7719. 6:31:26Then version
  7720. 6:31:28then we'll add the a status. Then files
  7721. 6:31:32planned files generated
  7722. 6:31:35and
  7723. 6:31:37current file and error and then created
  7724. 6:31:41at it will be project do.created at. So
  7725. 6:31:45after this error we have the created at
  7726. 6:31:47property. It is project do.created
  7727. 6:31:49created at and with that we'll add the
  7728. 6:31:51updated at also. So just add the next
  7729. 6:31:54one updated at and it will be project
  7730. 6:31:58dot updated at save the changes. So we
  7731. 6:32:02have completed our function to get the
  7732. 6:32:04details of individual project right now
  7733. 6:32:07after that let's scroll down and see our
  7734. 6:32:10next function. So the next function is
  7735. 6:32:13delete project. In this delete project
  7736. 6:32:15again we will check the user is
  7737. 6:32:17authenticated or not. So just copy this
  7738. 6:32:19paste it here in this delete function.
  7739. 6:32:23If request dot user is not available
  7740. 6:32:26then we'll add unauthorized and return.
  7741. 6:32:29Now user is authenticated. In this case
  7742. 6:32:32we'll add con result
  7743. 6:32:34equal to await and use the project model
  7744. 6:32:41dot find one and delete.
  7745. 6:32:44In this find one and delete we will add
  7746. 6:32:47the object where we will add underscore
  7747. 6:32:50id. It will be request.padams do id.
  7748. 6:32:54Then we'll add owner it will be request
  7749. 6:32:57dot user dot user id. Now after that
  7750. 6:33:02we'll add the if statement if
  7751. 6:33:05not of result. So in this case let's add
  7752. 6:33:10response dot a status.
  7753. 6:33:13it will be 4.4 and provide the error
  7754. 6:33:16that is project not found
  7755. 6:33:19and after that if the result is
  7756. 6:33:22available in this case let's add
  7757. 6:33:25response dot JSON
  7758. 6:33:30and simply add the message that will be
  7759. 6:33:33success message it will be true
  7760. 6:33:36that's it so the project will get
  7761. 6:33:39deleted
  7762. 6:33:41now after that let's come here in the
  7763. 6:33:43next function that is update project
  7764. 6:33:45files. So when we will make changes in
  7765. 6:33:48the code file, it should update the
  7766. 6:33:49project files in the database. So here
  7767. 6:33:53let's add con files
  7768. 6:33:56and get this files from the request dot
  7769. 6:33:59body. After that we'll add if statement
  7770. 6:34:02if not of
  7771. 6:34:05files
  7772. 6:34:07or
  7773. 6:34:11type of files not equal to object.
  7774. 6:34:17In this case just add response status
  7775. 6:34:21400 and error will be files object is
  7776. 6:34:24required. Then we'll add the return.
  7777. 6:34:29Now after that come here and provide the
  7778. 6:34:31if statement if not of request do user.
  7779. 6:34:35In this case we'll add the same message
  7780. 6:34:37that is request
  7781. 6:34:40dot a status 4.1 JSON error will be
  7782. 6:34:44unauthorized and returned. Now user is
  7783. 6:34:46authenticated. Then come here and
  7784. 6:34:49provide the con project equal to await
  7785. 6:34:51and use the project model.
  7786. 6:34:56Then dot
  7787. 6:34:59find one. In this find one add the
  7788. 6:35:04underscore id it will be request.params
  7789. 6:35:08do id then add comma owner and provide
  7790. 6:35:13request dot user dot user ID. So here
  7791. 6:35:17we'll find the project. Right. Now let's
  7792. 6:35:20add if statement if not of project. So
  7793. 6:35:23if the project is not available in this
  7794. 6:35:26case just add the message that is
  7795. 6:35:28request dot status 4.4 and the message
  7796. 6:35:31is project not found and return and
  7797. 6:35:33suppose the project is available in this
  7798. 6:35:36case let me add the comment that is
  7799. 6:35:40reveal project files map with content
  7800. 6:35:43and hes. So let's add const new files
  7801. 6:35:48will be
  7802. 6:35:50empty object then we'll add
  7803. 6:35:54for of
  7804. 6:35:56const path and content
  7805. 6:36:01of object dot entries and provide the
  7806. 6:36:04files. Now in this for we'll add the if
  7807. 6:36:08statement if type of content is equal to
  7808. 6:36:11a string.
  7809. 6:36:14In this case, let's add new files and
  7810. 6:36:18path
  7811. 6:36:20equal to
  7812. 6:36:22object and provide the content
  7813. 6:36:26then comma and provide the has property.
  7814. 6:36:30In this one, we'll add
  7815. 6:36:33has content
  7816. 6:36:36and content.
  7817. 6:36:39And we have to h our content using
  7818. 6:36:42crypto. So let me just scroll up
  7819. 6:36:45and here we will create a function just
  7820. 6:36:49add has content function
  7821. 6:36:53and provide the return in this one we'll
  7822. 6:36:56get the content as parameter and provide
  7823. 6:36:59the crypto and let's import it. We'll
  7824. 6:37:01add import
  7825. 6:37:05crypto from crypto and then we'll add
  7826. 6:37:10crypto dot Create hash
  7827. 6:37:16and provide
  7828. 6:37:19MD5.
  7829. 6:37:22Then dot
  7830. 6:37:24update and provide content.
  7831. 6:37:29Then dot
  7832. 6:37:33digest.
  7833. 6:37:35Then [snorts]
  7834. 6:37:36let's add hex.
  7835. 6:37:41Then dot
  7836. 6:37:44slice and provide
  7837. 6:37:480 comma 12
  7838. 6:37:51and we are using this as content here
  7839. 6:37:58in this for of.
  7840. 6:38:00Now after that
  7841. 6:38:04let's come here
  7842. 6:38:09and provide the project dotfiles equal
  7843. 6:38:11to new files.
  7844. 6:38:14Then we'll add await project dots save
  7845. 6:38:22and uh after that let's add con files
  7846. 6:38:26object. It will be empty object. And
  7847. 6:38:28then we'll add the same thing. Just copy
  7848. 6:38:30this.
  7849. 6:38:32Paste it here. In this one, we'll add
  7850. 6:38:35con path entry
  7851. 6:38:41of object dot entries and provide
  7852. 6:38:44project dot files.
  7853. 6:38:49Then we'll add
  7854. 6:38:51files object
  7855. 6:38:53and path it will be entry dot content.
  7856. 6:38:58And uh after that we can simply add the
  7857. 6:39:02response. So just add response dot JSON
  7858. 6:39:07and provide one object. In this object
  7859. 6:39:09we have to provide the project details.
  7860. 6:39:11So I'll copy from here.
  7861. 6:39:15Let's copy it and come back here.
  7862. 6:39:19In this one we are providing underscore
  7863. 6:39:21id. It is project dot id then name
  7864. 6:39:25project.name then description then
  7865. 6:39:28files. So the files will be files object
  7866. 6:39:31then messages then version and uh after
  7867. 6:39:35that we can remove these details. Simply
  7868. 6:39:38add created at and updated at.
  7869. 6:39:44Save the changes. So we have created
  7870. 6:39:48this function that is update project
  7871. 6:39:52files when we edit the code manually.
  7872. 6:39:55Right? Now after that
  7873. 6:39:58you can see we have the next function
  7874. 6:40:00that is publish project. Right? So in
  7875. 6:40:03this one again add the same statement
  7876. 6:40:06for user authentication check. We will
  7877. 6:40:08add if
  7878. 6:40:10request do user is not available then
  7879. 6:40:13we'll add
  7880. 6:40:16response do status 4.1 and the message
  7881. 6:40:19is unauthorized and return. Now suppose
  7882. 6:40:21the user is authenticated then we'll add
  7883. 6:40:23con project equal to await and use the
  7884. 6:40:27project model. So just add project dot
  7885. 6:40:33find one and update. Now in this one add
  7886. 6:40:37our first object. In this one just add
  7887. 6:40:41underscore id. It will be request dot
  7888. 6:40:44padams do id. Then we will add
  7889. 6:40:50owner it will be request dot user dot
  7890. 6:40:53user id. We have to update the status
  7891. 6:40:57right. We have to update the published
  7892. 6:40:59property. Right? So you can see we are
  7893. 6:41:02providing the
  7894. 6:41:04method find one and update and it will
  7895. 6:41:07help us to find the record. Then we'll
  7896. 6:41:10add comma and provide the next object
  7897. 6:41:12where we'll add published property and
  7898. 6:41:15make it true. So it will be publicly
  7899. 6:41:17available. And after that let's add the
  7900. 6:41:20next object where we'll add return
  7901. 6:41:22document and provide after.
  7902. 6:41:26So it will return the updated document.
  7903. 6:41:30Right now after that
  7904. 6:41:32here we will add the if statement if not
  7905. 6:41:35of project
  7906. 6:41:38it means we didn't get the project after
  7907. 6:41:42update right so in this case we'll add
  7908. 6:41:44response do a status 44 and then we'll
  7909. 6:41:47add the error message that is
  7910. 6:41:53project not found let me add it inside
  7911. 6:41:55the curly braces and if the project is
  7912. 6:41:59available after update then we'll add
  7913. 6:42:02response dojson with this success true
  7914. 6:42:05and we'll add the published property it
  7915. 6:42:08will be project dotpublished
  7916. 6:42:11that's it save the changes so we have
  7917. 6:42:13created this function using that we can
  7918. 6:42:16publish a project right now after that
  7919. 6:42:19we have to create this function
  7920. 6:42:22that is get the details of the publicly
  7921. 6:42:26published project so here we'll get the
  7922. 6:42:29entire details of the project and it
  7923. 6:42:31will be visible to all user without
  7924. 6:42:34authentication.
  7925. 6:42:35Right? So in this one we'll add con
  7926. 6:42:38project equal to await project dot find
  7927. 6:42:42by id and we'll get the id from request
  7928. 6:42:44patterns and id right here we are not
  7929. 6:42:48checking the authentication then we'll
  7930. 6:42:50add the if statement if not of project
  7931. 6:42:53suppose we could not find the project
  7932. 6:42:55using this ID provided in the padams
  7933. 6:42:58then we'll add response status 44 and
  7934. 6:43:01the error message is project not found
  7935. 6:43:03and return then we'll Add
  7936. 6:43:06another if statement. Copy and paste it
  7937. 6:43:08here. We'll add not of project
  7938. 6:43:10do.publish. Suppose the project is
  7939. 6:43:12available but published property is
  7940. 6:43:15false. Right? Then we'll add response
  7941. 6:43:18status 4.3.
  7942. 6:43:20And in the error message we'll add
  7943. 6:43:23project is not published yet.
  7944. 6:43:28It means the project is available but it
  7945. 6:43:30is not public. Right? Now suppose it is
  7946. 6:43:33public in this case we'll add con files
  7947. 6:43:36object will be empty object and then we
  7948. 6:43:40have to add the for off. So just copy
  7949. 6:43:43the for off loop from here.
  7950. 6:43:49Let's copy this one. Paste it here.
  7951. 6:43:53Let's add con
  7952. 6:43:56path entry of object dot entries.
  7953. 6:44:00Then project dotfiles if
  7954. 6:44:04let me remove this if simply add this
  7955. 6:44:08files object path equal to entry dot
  7956. 6:44:12content
  7957. 6:44:17and uh after that we can send the
  7958. 6:44:19response
  7959. 6:44:21right for sending the response let's
  7960. 6:44:23just copy the statement from here copy
  7961. 6:44:26this response dojson and paste it here
  7962. 6:44:30Now in this one we'll add underscore id.
  7963. 6:44:32It will be project id. Then name
  7964. 6:44:36description and files. Then we'll add
  7965. 6:44:39the version.
  7966. 6:44:42That's it.
  7967. 6:44:44ID name description files and version.
  7968. 6:44:48Save the changes. So we have created
  7969. 6:44:50this function. Using that we can return
  7970. 6:44:52the details of published project. so
  7971. 6:44:55that any user without authentication can
  7972. 6:44:57view the published project. After
  7973. 6:45:01creating these controllers, we will
  7974. 6:45:03create the API routes. For that, we have
  7975. 6:45:05to create the route file. So, in this
  7976. 6:45:08routes folder, create a new file and
  7977. 6:45:10write the file name project routes.js.
  7978. 6:45:18In this project routes, we have to
  7979. 6:45:22create the router using express. So just
  7980. 6:45:24add import router from express and after
  7981. 6:45:28that let's add con project router equal
  7982. 6:45:32to router. Now in this project router we
  7983. 6:45:37will add different endpoint. So let's
  7984. 6:45:39add project router dot get
  7985. 6:45:44and in [snorts] this one we'll add the
  7986. 6:45:47endpoint. You can see we have added the
  7987. 6:45:49type get and provide the endpoint. So
  7988. 6:45:51just add the endpoint for this last one.
  7989. 6:45:55You can see here we have the last
  7990. 6:45:57controller that is get public project.
  7991. 6:46:02So the endpoint will be this
  7992. 6:46:07public/
  7993. 6:46:09id right and the type is get. So let's
  7994. 6:46:12add it here. Just add public/
  7995. 6:46:16id and then we'll add the comma and
  7996. 6:46:19provide the function. So just add get
  7997. 6:46:24public project and it is imported from
  7998. 6:46:27the controllers project controller file.
  7999. 6:46:30So just add the file name extension js.
  8000. 6:46:33So first we have added this one because
  8001. 6:46:35this will be public route right. So let
  8002. 6:46:38me add the comment that is public route.
  8003. 6:46:41Here we don't need any authentication
  8004. 6:46:43and after that we have to add the other
  8005. 6:46:45routes where we have to add some
  8006. 6:46:49authentication right let me show you
  8007. 6:46:52that we'll add project router and uh
  8008. 6:46:57then we'll add the method dot post. So
  8009. 6:47:01we'll add the method post and then we'll
  8010. 6:47:04add the end point. So let's add the
  8011. 6:47:06endpoint it will be slash and then we'll
  8012. 6:47:10add the controller that is create
  8013. 6:47:13project. So just add the create project.
  8014. 6:47:15It has been imported here. You can see
  8015. 6:47:18this is the endpoint and the method is
  8016. 6:47:20post. Then we will use the create
  8017. 6:47:22project. And in this one we have to add
  8018. 6:47:24the middleware so that only
  8019. 6:47:26authenticated user can access this
  8020. 6:47:28route. So instead of adding the
  8021. 6:47:30middleware here we can add the
  8022. 6:47:33middleware just before this
  8023. 6:47:37route creation. So here just add this
  8024. 6:47:40project router
  8025. 6:47:42dot use
  8026. 6:47:46and in this use method we'll add the O
  8027. 6:47:50middleware.
  8028. 6:47:51So you can see O middleware is imported
  8029. 6:47:54from middleware o middleware.js. Now
  8030. 6:47:57after this o middleware use we'll create
  8031. 6:48:00other routes and these routes will be
  8032. 6:48:02protected. Let me add the comment here
  8033. 6:48:07that is protect all following routes. So
  8034. 6:48:10now whenever we'll create the new route
  8035. 6:48:14below this one all the routes will be
  8036. 6:48:16protected. It means first it will
  8037. 6:48:18execute this o middleware then only it
  8038. 6:48:21will execute the controller. Right? So
  8039. 6:48:24here we have added the first one. Let's
  8040. 6:48:26add the next one. So just copy this
  8041. 6:48:32is project router and then add dot.
  8042. 6:48:36We'll add project router.getate and the
  8043. 6:48:38path will be slash. Then we'll add list
  8044. 6:48:41projects.
  8045. 6:48:43So list projects has been imported. When
  8046. 6:48:46we'll hit this route using get method,
  8047. 6:48:48we'll get the list of projects by
  8048. 6:48:50individual owner. Now just copy this,
  8049. 6:48:54paste it here. We will add project
  8050. 6:48:56router.get and then colon id that is the
  8051. 6:49:00project id. Then it will give the
  8052. 6:49:03details of individual project. So just
  8053. 6:49:05add the get project controller. It has
  8054. 6:49:08been imported here. Now duplicate it and
  8055. 6:49:13uh here we'll add the method delete.
  8056. 6:49:17And for this delete, we'll add the
  8057. 6:49:19endpoint / id and provide the function
  8058. 6:49:23that is delete project. Now just
  8059. 6:49:27duplicate it. Here we'll add the type
  8060. 6:49:31put and then we'll add the path. It will
  8061. 6:49:35be colon id /
  8062. 6:49:39files.
  8063. 6:49:41And then we'll add the function that is
  8064. 6:49:45update project files. Let me just come
  8065. 6:49:48back here in the controller. You can see
  8066. 6:49:50we have this function called uh update
  8067. 6:49:55projects files and the method type is
  8068. 6:49:57put. Correct? Now come here in the
  8069. 6:49:59routes and duplicate this one. So in the
  8070. 6:50:03next one we will add the type post and
  8071. 6:50:07in this post we'll add the path. it will
  8072. 6:50:10be colon id and publish. So we will use
  8073. 6:50:14this route to publish a project. So
  8074. 6:50:17let's add the function
  8075. 6:50:20publish project.
  8076. 6:50:22So we have added all the routes here and
  8077. 6:50:25after that let's export this router from
  8078. 6:50:28here
  8079. 6:50:29that is project router. So just add
  8080. 6:50:33export default project router. That's
  8081. 6:50:37it. Next, we have to add this router in
  8082. 6:50:39our main file that is server.js file.
  8083. 6:50:42So, let's open server.js.
  8084. 6:50:46And uh here let's add app dot use.
  8085. 6:50:54And in this app dot use just add the
  8086. 6:50:58path. So, the path will be / ai/
  8087. 6:51:04projects. Let's add this slash also. /
  8088. 6:51:07API/ projects and then we'll provide our
  8089. 6:51:10router. So let's add
  8090. 6:51:13project
  8091. 6:51:15router. So you can see the project
  8092. 6:51:18router has been imported from routes
  8093. 6:51:19folder project routes.js file. So we
  8094. 6:51:22have created the endpoint for our
  8095. 6:51:24projects where we can create a project.
  8096. 6:51:28We can display the list of projects. We
  8097. 6:51:30can get the individual project data. We
  8098. 6:51:33can delete the project. We can update
  8099. 6:51:34the files. We can publish the project
  8100. 6:51:37and we can get the data of published
  8101. 6:51:39project. Now we have to complete the
  8102. 6:51:42functionality of this run background
  8103. 6:51:45generation. It means we will generate
  8104. 6:51:47the project or generate the website
  8105. 6:51:50using AI. So we have to implement our AI
  8106. 6:51:53feature. To add the AI functionality
  8107. 6:51:57first we need the keys for AI APIs. So
  8108. 6:52:01let me just open the web browser and
  8109. 6:52:03search for open router. We will use the
  8110. 6:52:05open router keys. After that, let's sign
  8111. 6:52:09up here. And after sign up, you will
  8112. 6:52:11come to
  8113. 6:52:14workspaces. And in the left side, you
  8114. 6:52:16will find the API keys. And you will
  8115. 6:52:19find this button new key. So just click
  8116. 6:52:22here and create a new key. Let me add
  8117. 6:52:24the name for this key that is builder AI
  8118. 6:52:28and click on create.
  8119. 6:52:31So here we have a new key. Let me add
  8120. 6:52:33this key in our environment variable. So
  8121. 6:52:36let me open ENV file here.
  8122. 6:52:41In this env file, we'll add one
  8123. 6:52:44environment variable name. So just add
  8124. 6:52:46open router API key
  8125. 6:52:51and paste this key from open router.
  8126. 6:52:54Copy and paste it here.
  8127. 6:52:59After that we have to provide the model.
  8128. 6:53:01So let's add the another
  8129. 6:53:04environment variable that is open router
  8130. 6:53:06model
  8131. 6:53:08and to get the model let's come here and
  8132. 6:53:12let's go to homepage
  8133. 6:53:15and after that click on this models from
  8134. 6:53:18this navigation bar and here we will
  8135. 6:53:21search for free.
  8136. 6:53:23So it will display the free models and
  8137. 6:53:27here we have the list of free models. So
  8138. 6:53:29we are going to use this co here. Let's
  8139. 6:53:31click on this one.
  8140. 6:53:34So this is cohair north mini code free
  8141. 6:53:38and uh let's add the model name in our
  8142. 6:53:43environment variable. I'll copy this
  8143. 6:53:46one. Come to env file and paste this one
  8144. 6:53:50that is coher/n
  8145. 6:53:52north mini
  8146. 6:53:54code free. So this model has some
  8147. 6:53:58limitation. You can use 50 API request
  8148. 6:54:01per day or up to 500 token per day. And
  8149. 6:54:06if you go for any paid API then you will
  8150. 6:54:10get the more limit and even that will
  8151. 6:54:13generate a better response that will
  8152. 6:54:16generate a better code for your website.
  8153. 6:54:19So we are using the free model here and
  8154. 6:54:21after that we have to add the packages
  8155. 6:54:25to add the AI functionality. So let's
  8156. 6:54:28open the terminal.
  8157. 6:54:34We will open the terminal. You can see
  8158. 6:54:37this is the
  8159. 6:54:40server terminal where backend server is
  8160. 6:54:42running. So just add Ctrl C to stop the
  8161. 6:54:44project. And after that here let's add
  8162. 6:54:49npm
  8163. 6:54:54install
  8164. 6:54:56and write the package name AI. We will
  8165. 6:54:59use this package for open router API
  8166. 6:55:01call. Then we will add a space at
  8167. 6:55:06AI
  8168. 6:55:08dash SDK
  8169. 6:55:12/ open AI.
  8170. 6:55:16So we will use this package for creating
  8171. 6:55:20AI schema and after that add a space and
  8172. 6:55:23provide p-map.
  8173. 6:55:25We will use this p map for mapping the
  8174. 6:55:29files in database. Then we'll add the
  8175. 6:55:33next
  8176. 6:55:35package that is zod.
  8177. 6:55:39So we will use this zord package to
  8178. 6:55:43extract the structured data from the AI
  8179. 6:55:46response. So you can see we have added
  8180. 6:55:48these packages npm install AI then AI
  8181. 6:55:52SDK then /open AI then pmap and zord.
  8182. 6:55:57Press enter. So it will install these
  8183. 6:56:00packages and after installation we can
  8184. 6:56:03verify it from the package.json file.
  8185. 6:56:07Let me open package.json.
  8186. 6:56:11Here you can see we have these packages
  8187. 6:56:13pmap zord
  8188. 6:56:16AI and AI SDK open AI.
  8189. 6:56:22After adding it let's start our project
  8190. 6:56:25again. So in this terminal we'll add npm
  8191. 6:56:28rundev. So it will start our backend
  8192. 6:56:31server again. You can see the message in
  8193. 6:56:33the terminal
  8194. 6:56:35successfully connected to MongoDB and
  8195. 6:56:38server is running. Now let's hide this
  8196. 6:56:40terminal and in this one we'll add some
  8197. 6:56:42assets. So let's come here in the
  8198. 6:56:46downloaded file that is the downloaded
  8199. 6:56:48asset. In this one you will find the
  8200. 6:56:50server. In this server we have services
  8201. 6:56:53folder. In this services we have four
  8202. 6:56:55files that is code validator then
  8203. 6:56:58content normalizer diff and prompts. So
  8204. 6:57:03just copy this services folder from here
  8205. 6:57:06and open our project folder. Then go to
  8206. 6:57:09server and in this server simply paste
  8207. 6:57:12this services.
  8208. 6:57:15So we have added the services here in
  8209. 6:57:18the server project. Now close it and
  8210. 6:57:21come back to the VS code. So if I open
  8211. 6:57:24this sidebar here you can see
  8212. 6:57:28we have the
  8213. 6:57:31services folder and in this services
  8214. 6:57:34folder we have four different file. Now
  8215. 6:57:36we'll create a new file in this services
  8216. 6:57:38that will be AI.js. So just create a new
  8217. 6:57:41file that is AI.js
  8218. 6:57:44JS and in this AI dot js let's add
  8219. 6:57:48import
  8220. 6:57:50and provide
  8221. 6:57:52curly braces from at AI SDK/open
  8222. 6:57:59AI
  8223. 6:58:00and from here we will get
  8224. 6:58:04create open AI
  8225. 6:58:06correct now let's add the comment here
  8226. 6:58:08that is open router model client setup
  8227. 6:58:13for this client line setup.
  8228. 6:58:16Let's provide
  8229. 6:58:18the con model equal to and use the model
  8230. 6:58:22from the environment variable using
  8231. 6:58:24process.env
  8232. 6:58:26dot open router model which is here open
  8233. 6:58:29router model. After that let's add or
  8234. 6:58:34and provide open router/free.
  8235. 6:58:39Then we will add
  8236. 6:58:42max concurrency
  8237. 6:58:45equal to
  8238. 6:58:47parse int. In this parse int we will add
  8239. 6:58:50process dot env
  8240. 6:58:54and uh let's provide
  8241. 6:58:57a max concurrency
  8242. 6:59:00and if it is not available then we will
  8243. 6:59:03add or
  8244. 6:59:06six
  8245. 6:59:07then comma 10.
  8246. 6:59:11After adding it, let's provide con
  8247. 6:59:15open router equal to
  8248. 6:59:20create open AI.
  8249. 6:59:23In this create open AI, just add the
  8250. 6:59:26base URL. So the base URL will be https
  8251. 6:59:31open router.
  8252. 6:59:33AI/
  8253. 6:59:35API/v1
  8254. 6:59:37that is version one. Then we will add
  8255. 6:59:39the API key. So let's provide the
  8256. 6:59:43process envi
  8257. 6:59:46key from the environment variable.
  8258. 6:59:50Now after that we have to create the
  8259. 6:59:53model here. So just add con model equal
  8260. 6:59:56to
  8261. 6:59:58open router
  8262. 7:00:01and in this open router provide our
  8263. 7:00:03model.
  8264. 7:00:06That's it. Now we will create our
  8265. 7:00:08function. Using that we can generate the
  8266. 7:00:11project. So let's add command first.
  8267. 7:00:15We'll add the command.
  8268. 7:00:18Generate project files.
  8269. 7:00:22Then we have added plan first. Then
  8270. 7:00:25build the files in order with fallback
  8271. 7:00:29retries. It means first it will generate
  8272. 7:00:32the plan then it will build the files
  8273. 7:00:36one by one right. So
  8274. 7:00:40let's add the function and export the
  8275. 7:00:43function. So just add export as sync
  8276. 7:00:45function and write the function name
  8277. 7:00:48generate project.
  8278. 7:00:50So it will generate a project and in
  8279. 7:00:52this project it will plan the files and
  8280. 7:00:56then generate the files one by one. So
  8281. 7:00:58let's create that function also that
  8282. 7:01:00will handle the single file generate. So
  8283. 7:01:03let's add the comment here that is
  8284. 7:01:07generate a single files code. So just
  8285. 7:01:11add a sync function
  8286. 7:01:14and write the function name generate
  8287. 7:01:16single file.
  8288. 7:01:18Now for generating the single file code
  8289. 7:01:21here we provide the file then all files.
  8290. 7:01:26After that we will provide the prompt
  8291. 7:01:29then provide
  8292. 7:01:31already generated files
  8293. 7:01:36right and let's come here in this
  8294. 7:01:38function that is generate project in
  8295. 7:01:40this generate project we have to provide
  8296. 7:01:42the prompt and then we'll add the
  8297. 7:01:45callbacks
  8298. 7:01:47in this file we have to create one more
  8299. 7:01:49function that is revise project function
  8300. 7:01:52right so let's add export
  8301. 7:01:56async function function and write the
  8302. 7:01:58function name that is revise project. In
  8303. 7:02:02this revise project we will get the
  8304. 7:02:04prompt.
  8305. 7:02:07After that we'll get the manifest then
  8306. 7:02:11relevant files
  8307. 7:02:13and then recent messages.
  8308. 7:02:17So we have created three functions here
  8309. 7:02:20and to complete these functions we need
  8310. 7:02:24some schemas right. So let's create the
  8311. 7:02:27schema in different file. In this
  8312. 7:02:29services we will create a new file and
  8313. 7:02:31write the file name AI schemas.js.
  8314. 7:02:35In this AI schemas we will use zod. So
  8315. 7:02:38just add import zed from zod. We will
  8316. 7:02:41use this zord for creating the schema.
  8317. 7:02:44And uh let's add
  8318. 7:02:47export const generation result schema
  8319. 7:02:52equal to
  8320. 7:02:54Z dot object. Here we'll add the files
  8321. 7:02:59and in this files just add Z dot record
  8322. 7:03:04and then Z dot string then comma again
  8323. 7:03:09add Z dot string. Next we'll add the
  8324. 7:03:12description
  8325. 7:03:15and in this description we'll add Z dot
  8326. 7:03:18string dot default
  8327. 7:03:20and in this default provide generated
  8328. 7:03:24project.
  8329. 7:03:25So we have added generation result
  8330. 7:03:27schema.
  8331. 7:03:29So this generation results will contain
  8332. 7:03:32files. Now after that we'll create the
  8333. 7:03:36next schema. So just duplicate this one.
  8334. 7:03:39In this one we'll add the name that is
  8335. 7:03:43file operations a schema or file op
  8336. 7:03:46schema equal to
  8337. 7:03:48Z
  8338. 7:03:50dot object and here we'll add the
  8339. 7:03:53details. So let's add
  8340. 7:03:56operation optinum.
  8341. 7:04:02In this one add array that contains
  8342. 7:04:07create, update and delete.
  8343. 7:04:10So these are the file operations and
  8344. 7:04:13after that we'll add the path.
  8345. 7:04:16So we have added the path here and in
  8346. 7:04:18this path let's add Z dot a string. Then
  8347. 7:04:23we'll add content. So in this content
  8348. 7:04:26provide Z dot a string dot
  8349. 7:04:30null label dot optional
  8350. 7:04:34then we will add search and replace.
  8351. 7:04:40So we have added search and replace. For
  8352. 7:04:42this one also we have added the same
  8353. 7:04:44details.
  8354. 7:04:46Now after that we'll create our next
  8355. 7:04:49schema. So I'll just copy this paste it
  8356. 7:04:52here. Here
  8357. 7:04:55we'll add the name that is revision
  8358. 7:04:58result schema. In this revision result
  8359. 7:05:01schema, I'll copy the details from here.
  8360. 7:05:04Paste it here.
  8361. 7:05:07Here we will add the operations.
  8362. 7:05:12It will be Z dot array. And provide the
  8363. 7:05:16file operations schema which is here.
  8364. 7:05:20Then let's add the description. It will
  8365. 7:05:23be Z dot string dotdefault. And here
  8366. 7:05:26we'll add applied revisions.
  8367. 7:05:29Now we'll create our next schema. So
  8368. 7:05:32let's copy this and paste it here. Here
  8369. 7:05:36we'll add the schema name
  8370. 7:05:40file plan schemas or schema. So we have
  8371. 7:05:43added file plan schema z.object and
  8372. 7:05:46provide the files.
  8373. 7:05:48So let's add the files property. It will
  8374. 7:05:51be Z dot array
  8375. 7:05:53and uh after that we'll add the project
  8376. 7:05:56name.
  8377. 7:05:58In the project name we'll add Z dot
  8378. 7:06:01string dot default and then we'll add
  8379. 7:06:04the value that will be generated
  8380. 7:06:07project. After that just duplicate it.
  8381. 7:06:13It will be project description.
  8382. 7:06:16It will be Z dot string dot default and
  8383. 7:06:20the data will be a react project.
  8384. 7:06:24Correct? Now let's update this one that
  8385. 7:06:27is files. It will be Z dot array. In
  8386. 7:06:30this array let's add Z dot
  8387. 7:06:34object. Now in this one we'll add the
  8388. 7:06:38path. It will be Z dot string.
  8389. 7:06:41Then we will add the description. It
  8390. 7:06:43will be Z dot string.
  8391. 7:06:46Then exports. In this exports, we'll add
  8392. 7:06:49Z dot string dot optional dot default
  8393. 7:06:53empty string. Then we'll add imports. In
  8394. 7:06:56this imports, just provide Z dot array.
  8395. 7:07:00It will be Z do.ring dot optional dot
  8396. 7:07:04default empty array. So we have created
  8397. 7:07:07the file plan schema. And after that we
  8398. 7:07:10have to create our last schema that is
  8399. 7:07:12file code schema. So I'll just copy the
  8400. 7:07:16simple one. Just copy this and paste it
  8401. 7:07:18here. Add the schema name file code
  8402. 7:07:21schema.
  8403. 7:07:23Then add code.
  8404. 7:07:26It will be Z dot string.
  8405. 7:07:30That's it.
  8406. 7:07:32So we have created all these schemas.
  8407. 7:07:34Let me show you one by one. Let's fold
  8408. 7:07:36it. So here we have generation result
  8409. 7:07:40schema, file operation schema, division
  8410. 7:07:43result schema, file plan schema and file
  8411. 7:07:46code schema.
  8412. 7:07:48After that we can come back to our AI
  8413. 7:07:51file that is AI.js.
  8414. 7:07:53Now we'll come to this AI.js file and in
  8415. 7:07:56this one we'll start creating this
  8416. 7:07:59generate project function. So in this
  8417. 7:08:01generate project function let's add the
  8418. 7:08:04comment that is phase one that is plan.
  8419. 7:08:08So in the phase one we'll plan the
  8420. 7:08:10project. So let's add the message in
  8421. 7:08:13console also we will add console.log log
  8422. 7:08:16and provide a message in back tick that
  8423. 7:08:19is AI phase 1 planning file structure
  8424. 7:08:24for and provide the prompt
  8425. 7:08:29and in this prompt add the slice.
  8426. 7:08:33So it will display only 80 character
  8427. 7:08:36when we add 0 and 80 and uh at the end
  8428. 7:08:41we'll add this dot. So this message will
  8429. 7:08:45be added in the console. Now after that
  8430. 7:08:48let's add const
  8431. 7:08:51object as plan equal to await and here
  8432. 7:08:56we will use the generate object
  8433. 7:09:01and we will get this generate object
  8434. 7:09:03from AI. Let's scroll up. You can see
  8435. 7:09:05generate object has been imported from
  8436. 7:09:07the AI package.
  8437. 7:09:09Now in this generate object add one
  8438. 7:09:13object where we will add the model
  8439. 7:09:18then add schema.
  8440. 7:09:22In this schema just add file
  8441. 7:09:26plan schema from the schema file. You
  8442. 7:09:29can see it is imported from the AI
  8443. 7:09:31schemas file. So let's add the file name
  8444. 7:09:34extension also that is js. Now let's
  8445. 7:09:38come here add the comma after this a
  8446. 7:09:41schema let's add system in this system
  8447. 7:09:45property provide the file plan
  8448. 7:09:49system
  8449. 7:09:51and let's import it from the file that
  8450. 7:09:55we have provided in the services that is
  8451. 7:09:58this prompt let's open it and after that
  8452. 7:10:02if I start typing this
  8453. 7:10:06we are getting the suggestions so you
  8454. 7:10:07can It is imported from the prompts.js.
  8455. 7:10:11After that, let's add prompt. So, we
  8456. 7:10:16will add back
  8457. 7:10:18plan a react website for and provide our
  8458. 7:10:22given prompt. So, just add prompt. Then
  8459. 7:10:26we will add the next properties that is
  8460. 7:10:29max retries. It will be two. Now, we'll
  8461. 7:10:32add if statement if not of plan.
  8462. 7:10:38and find. In this find method, add the
  8463. 7:10:43add a function. We'll get the first file
  8464. 7:10:48or individual file and then we'll add
  8465. 7:10:51file dot path
  8466. 7:10:55equal to / app.js.
  8467. 7:10:59So in this case, we'll add plan.files
  8468. 7:11:02files dot
  8469. 7:11:04unshift
  8470. 7:11:06and simply add the path. It will be app
  8471. 7:11:10js using the slash. Then we'll add the
  8472. 7:11:13description. So the description is main
  8473. 7:11:16application entry point. Then we'll add
  8474. 7:11:19exports
  8475. 7:11:21default app. then imports and in the
  8476. 7:11:24imports let's provide
  8477. 7:11:27dot /styles
  8478. 7:11:30dot CSS.
  8479. 7:11:32Now we will duplicate this if statement.
  8480. 7:11:34Just copy and paste it here.
  8481. 7:11:37So in this second if statement we'll add
  8482. 7:11:40not of plan dot files dotfind. It will
  8483. 7:11:44be path equal to
  8484. 7:11:49/st style dot css. So we have added a
  8485. 7:11:53styles dot css. Then plan dotfiles dot
  8486. 7:11:58push
  8487. 7:12:01and provide path
  8488. 7:12:04that is styles dot css. Then we'll add
  8489. 7:12:08the description.
  8490. 7:12:10So we have added the description that is
  8491. 7:12:13global CSS Google font import key frame
  8492. 7:12:16animations utility classes then we'll
  8493. 7:12:20add exports it will be none and import
  8494. 7:12:24it will be empty array.
  8495. 7:12:29Now after that here we'll add if
  8496. 7:12:33in this if we'll add the callbacks
  8497. 7:12:38dot on plan
  8498. 7:12:42then just add await and here use the
  8499. 7:12:47callback dot on plan and provide the
  8500. 7:12:51plan. After that we'll add console log
  8501. 7:12:54here. So just add console do.log log
  8502. 7:12:58and in this console log
  8503. 7:13:04just add the back text and provide AI
  8504. 7:13:07phase 2
  8505. 7:13:09generating
  8506. 7:13:11then
  8507. 7:13:13add the plan dot files.length length
  8508. 7:13:18that will be total number of files and
  8509. 7:13:21then we'll add files in parallel
  8510. 7:13:25concurrency
  8511. 7:13:27and then we'll add max concurrency.
  8512. 7:13:32After that just add this parenthesis and
  8513. 7:13:36colon and provide dollar sign curly
  8514. 7:13:39braces here. Just add the plan
  8515. 7:13:44dot files dot map. Get the individual
  8516. 7:13:49file and uh after that it will return
  8517. 7:13:54file dot
  8518. 7:13:56path. Then add dot join and in this join
  8519. 7:14:01we will add comma and a space. That's
  8520. 7:14:05it. So we have added this console log
  8521. 7:14:08and uh after this we will add con files.
  8522. 7:14:12It will be empty object.
  8523. 7:14:16Then provide
  8524. 7:14:18let pending files equal to plan dot
  8525. 7:14:23files
  8526. 7:14:25dot map. In this map we will add the
  8527. 7:14:28individual file and after that add the
  8528. 7:14:31parenthesis curly braces a spread
  8529. 7:14:34operator and this file. Now we'll add
  8530. 7:14:38max retry rounds it will be two. Then
  8531. 7:14:42we'll add
  8532. 7:14:44for loop. We'll add let round it will be
  8533. 7:14:49zero.
  8534. 7:14:52then round
  8535. 7:14:55less than equal to
  8536. 7:14:58max retry rounds. Just copy and paste it
  8537. 7:15:01here. Then round ++
  8538. 7:15:05that is round increment and then we'll
  8539. 7:15:07add
  8540. 7:15:10if
  8541. 7:15:12pending files.length is equal to zero
  8542. 7:15:16then simply add break. After that we'll
  8543. 7:15:20add if statement. If round is greater
  8544. 7:15:24than zero in this case we'll add
  8545. 7:15:27console.log
  8546. 7:15:28and in this console log we have added AI
  8547. 7:15:32retry round and provide the round number
  8548. 7:15:35max retry round for pending files.length
  8549. 7:15:40then failed files and insert the pending
  8550. 7:15:42files dom then it will return file.path
  8551. 7:15:46path dot join using this comma and
  8552. 7:15:51space.
  8553. 7:15:52Now after that just come here let's add
  8554. 7:15:57con results equal to await
  8555. 7:16:01and here we will use the P map let's
  8556. 7:16:04import it we are not getting the
  8557. 7:16:06suggestion so we will import it manually
  8558. 7:16:09let's scroll up
  8559. 7:16:11here just add import pmap from p-map we
  8560. 7:16:18have already added this package now
  8561. 7:16:20after that scroll
  8562. 7:16:22Now in this result we'll add await pmap
  8563. 7:16:27and then let's provide
  8564. 7:16:31pending files comma
  8565. 7:16:34asynchronous
  8566. 7:16:36add a function. Here we'll get the file
  8567. 7:16:39as parameter and uh after that here
  8568. 7:16:42we'll add the try catch a statement.
  8569. 7:16:46Now in this try we'll add if callback
  8570. 7:16:49dot on file start then just add await
  8571. 7:16:56callbacks dot on file start
  8572. 7:17:00then add file
  8573. 7:17:03dotpath.
  8574. 7:17:04Now come here after this if statement
  8575. 7:17:07just add con single result equal to
  8576. 7:17:11await and now we will use the previous
  8577. 7:17:14function that we have already declared
  8578. 7:17:17that is generate single file. In this
  8579. 7:17:20generate single file we will provide the
  8580. 7:17:22file
  8581. 7:17:24then provide the plan dot files then
  8582. 7:17:28provide prompt and files. Now just add
  8583. 7:17:33if.
  8584. 7:17:35In this if we'll add callbacks dot
  8585. 7:17:38onfile complete.
  8586. 7:17:41In this case we'll add await callbacks
  8587. 7:17:45dot onfile complete.
  8588. 7:17:48Then add the file.path
  8589. 7:17:51and single file or single result doc
  8590. 7:17:54code. So here we have a single result
  8591. 7:17:57then dot code and after that simply add
  8592. 7:18:00the return
  8593. 7:18:02in this return we'll add the object with
  8594. 7:18:05success true and provide the file and
  8595. 7:18:08then we'll add the result property
  8596. 7:18:11result property will be single result
  8597. 7:18:14and come here in the catch block in this
  8598. 7:18:16catch we'll add the return and provide
  8599. 7:18:19the object with success false and
  8600. 7:18:22provide the file and error it will be
  8601. 7:18:25this error. Now after that here we'll
  8602. 7:18:28add comma and provide concurrency.
  8603. 7:18:34It will be max concurrency.
  8604. 7:18:38Now [snorts] after that here let's add
  8605. 7:18:40con
  8606. 7:18:42failed files. It is empty array. Then
  8607. 7:18:46we'll add for of
  8608. 7:18:51just add con entry of results.
  8609. 7:18:55Then provide if entry dot success.
  8610. 7:19:02In this case, we'll add con path and
  8611. 7:19:05code equal to the
  8612. 7:19:09entry dot
  8613. 7:19:12result. then files path dot starts with
  8614. 7:19:17slash if it is true then path else
  8615. 7:19:22forward slash plus path equal to code.
  8616. 7:19:28Now we'll add the else statement. So
  8617. 7:19:30just add the else. In this else just add
  8618. 7:19:34the console dot warn that is the
  8619. 7:19:36warning. So we have added this warning
  8620. 7:19:39and after that we'll add the failed
  8621. 7:19:42files
  8622. 7:19:44dot push
  8623. 7:19:46and just add the
  8624. 7:19:49entry dot file. Now after that here
  8625. 7:19:53we'll add the pending files equal to
  8626. 7:19:57failed files. Now after that just add
  8627. 7:20:00the if statement here. if pending
  8628. 7:20:04files.length is greater than zero. So in
  8629. 7:20:07this case let me provide const
  8630. 7:20:12failed paths equal to pending files
  8631. 7:20:17dot map
  8632. 7:20:20and provide the arrow function with a
  8633. 7:20:24single file. Then it will return the
  8634. 7:20:26file dot path. After that we'll add dot
  8635. 7:20:30join. Then add comma and a space. Then
  8636. 7:20:35we'll add one message in console that is
  8637. 7:20:37console dot error like this. And after
  8638. 7:20:41this console just add if statement if
  8639. 7:20:44pending files
  8640. 7:20:46dot sum and provide the arrow function
  8641. 7:20:49with individual file file.path is equal
  8642. 7:20:52to app dot js.
  8643. 7:20:55In this case here we'll add con
  8644. 7:20:57extension ext equal to
  8645. 7:21:01file dotpath
  8646. 7:21:03dotsplit
  8647. 7:21:05and we'll split using dot. Then just add
  8648. 7:21:10dot pop
  8649. 7:21:15then dot two lower case.
  8650. 7:21:21Now after that let's add if
  8651. 7:21:24extension equal to CSS.
  8652. 7:21:27In this case just add files
  8653. 7:21:32file.path equal to backix and insert
  8654. 7:21:38/ start. Then insert the file
  8655. 7:21:42description and generation failed.
  8656. 7:21:46Please retry.
  8657. 7:21:48After that we'll add the else statement.
  8658. 7:21:54In this else statement
  8659. 7:21:56just add the
  8660. 7:21:59files file.path is equal to and provide
  8661. 7:22:04the
  8662. 7:22:07string. So we have added this string and
  8663. 7:22:10here we'll add the text called import
  8664. 7:22:13react from react
  8665. 7:22:16like this. Then we'll add plus. In the
  8666. 7:22:20next line, we'll add back tick and
  8667. 7:22:22provide
  8668. 7:22:25this comment. This file could not be
  8669. 7:22:29generated. Please retry. Then plus in
  8670. 7:22:33the next line just add
  8671. 7:22:36back text
  8672. 7:22:39and provide purpose.
  8673. 7:22:42It will be file dot description. Then
  8674. 7:22:44plus
  8675. 7:22:46then we will add
  8676. 7:22:50export default function and
  8677. 7:22:54it is placeholder.
  8678. 7:22:57Then we have added this plus.
  8679. 7:23:00After that we'll add return. Let me add
  8680. 7:23:03the entire code here. So we have added
  8681. 7:23:06export default function placeholder
  8682. 7:23:08return. It will return a div with these
  8683. 7:23:12classes. Here we have the message
  8684. 7:23:15component failed to generate please try
  8685. 7:23:18again.
  8686. 7:23:20Now after that just come here and we'll
  8687. 7:23:22add the if statement
  8688. 7:23:25and provide not of
  8689. 7:23:29files app dot js. So in this case just
  8690. 7:23:33add throw new error and the error
  8691. 7:23:36message is AI did not generate appjs
  8692. 7:23:40entry point and after that just add the
  8693. 7:23:43return here. In this return let's
  8694. 7:23:47provide files and description.
  8695. 7:23:51In this description we'll add the plan
  8696. 7:23:54dot project description.
  8697. 7:23:57Save the changes.
  8698. 7:23:59Now in this function you can see we are
  8699. 7:24:01using the generating or generate single
  8700. 7:24:04file. Let's scroll up. You can see we
  8701. 7:24:06are using this generate single file. So
  8702. 7:24:08just complete that function also. So
  8703. 7:24:10scroll up and we will fold this function
  8704. 7:24:14and let's complete this generate single
  8705. 7:24:16file. So in this function just add const
  8706. 7:24:22system equal to
  8707. 7:24:26build build file code system and import
  8708. 7:24:30it from prompts.
  8709. 7:24:32Then we'll add
  8710. 7:24:35all files
  8711. 7:24:37comma and provide already generated
  8712. 7:24:41files. Then we will add con user message
  8713. 7:24:45equal to back tick and provide project
  8714. 7:24:50colon and provide the prompt
  8715. 7:24:54and uh after this prompt provide write
  8716. 7:24:58the complete code for and then we'll add
  8717. 7:25:04the file.path path
  8718. 7:25:07then
  8719. 7:25:09add the purpose and it will be file
  8720. 7:25:12do.escription
  8721. 7:25:14then we'll add console.log it will be
  8722. 7:25:19AI creating file and the file.path path.
  8723. 7:25:23After that just add con object
  8724. 7:25:28equal to await and here we will use
  8725. 7:25:31generate object. Just add the generate
  8726. 7:25:34object
  8727. 7:25:36and it is already imported from AI
  8728. 7:25:40package right and in this one provide
  8729. 7:25:42the model
  8730. 7:25:44and after the model we'll add the
  8731. 7:25:46schema.
  8732. 7:25:48So in this schema just add file
  8733. 7:25:52code schema
  8734. 7:25:55then we'll add system
  8735. 7:25:58then we will add prompt that is the user
  8736. 7:26:01message
  8737. 7:26:03and then we'll add the max retries it
  8738. 7:26:06will be two. After that here we'll add
  8739. 7:26:08let
  8740. 7:26:10code equal to
  8741. 7:26:13normalize content and get this normalize
  8742. 7:26:16content imported. Let me open this
  8743. 7:26:19normalize content or content
  8744. 7:26:22normalizer.js file. Here it is. After
  8745. 7:26:25that if I start typing
  8746. 7:26:28you can see we are getting this sgestion
  8747. 7:26:30to import it. And uh if I scroll up you
  8748. 7:26:34can see it is imported from the content
  8749. 7:26:36normalizer.js.
  8750. 7:26:39Let's come back here. So we have added
  8751. 7:26:42let code equal to normalize content and
  8752. 7:26:45simply provide the
  8753. 7:26:48object dot code.
  8754. 7:26:52Here we have the object and in this one
  8755. 7:26:54we have the code. Now after that we'll
  8756. 7:26:56add if
  8757. 7:26:59code.trim
  8758. 7:27:01dotlength is equal to zero.
  8759. 7:27:04In this case, just add throw new error
  8760. 7:27:07and provide the message generated code
  8761. 7:27:10is empty after normalization.
  8762. 7:27:14Now let's add the comment here that is
  8763. 7:27:17apply postgeneration validation and
  8764. 7:27:20autofix.
  8765. 7:27:22Right? So here we will use the validator
  8766. 7:27:26code. If I open the services here we
  8767. 7:27:30have the code validator.js.
  8768. 7:27:33open this one and then let's add it
  8769. 7:27:35here. So here just add con validation
  8770. 7:27:39equal to validate and fix code. Just
  8771. 7:27:43import it from the file and uh in this
  8772. 7:27:46one provide the code then we'll add the
  8773. 7:27:50file dot path. Then provide object with
  8774. 7:27:56all planned files. It will be
  8775. 7:27:59all files. Then we'll add code equal to
  8776. 7:28:03validation
  8777. 7:28:05dot code.
  8778. 7:28:08Now we'll add if validation dot warnings
  8779. 7:28:14do.length is greater than zero.
  8780. 7:28:17In this case we'll add console log and
  8781. 7:28:20provide
  8782. 7:28:22validator code adjustments for and
  8783. 7:28:26file.path. And then we'll add the
  8784. 7:28:29warning and
  8785. 7:28:32join using dash. Now after that let's
  8786. 7:28:35add another console log here. So just
  8787. 7:28:38add console.log.
  8788. 7:28:40And here we have
  8789. 7:28:42AI created file and file.path and
  8790. 7:28:46code.length characters. Then we'll add
  8791. 7:28:49the return statement here. So just add
  8792. 7:28:51the return and simply provide the object
  8793. 7:28:55with path. It will be file.path and then
  8794. 7:28:58we will add the code also. Save the
  8795. 7:29:01changes. So we have created the
  8796. 7:29:04functionality to generate our project
  8797. 7:29:06using AI. Now you can see we have the
  8798. 7:29:10third function that is revise project.
  8799. 7:29:12So let's complete this function also. So
  8800. 7:29:14in this one just add const
  8801. 7:29:18context parts equal to empty array. Then
  8802. 7:29:23we'll add context parts dot push and
  8803. 7:29:27provide the string here.
  8804. 7:29:31So we have added current project files
  8805. 7:29:35manifest.
  8806. 7:29:38Then we'll add context parts dot push.
  8807. 7:29:42And here we'll add this string. After
  8808. 7:29:45that we'll add for of in this for of
  8809. 7:29:48we'll add con file of
  8810. 7:29:52manifest. It will be context parts dot
  8811. 7:29:56push
  8812. 7:29:58and provide back text with dollar sign
  8813. 7:30:01curly braces file.path path space
  8814. 7:30:05and let's add parenthesis that contains
  8815. 7:30:10file has comma file dot size b.
  8816. 7:30:16Now after that we'll add context parts
  8817. 7:30:19dot push and provide this a string. Now
  8818. 7:30:23we'll add the if statement here. In this
  8819. 7:30:25if just add object dot keys and provide
  8820. 7:30:30relevant files
  8821. 7:30:33that we are getting as parameter and
  8822. 7:30:37then we'll add dot length
  8823. 7:30:41is greater than zero.
  8824. 7:30:44So if we have the relevant files in this
  8825. 7:30:47case we'll add context parts dotpush and
  8826. 7:30:50provide the file contains for reference.
  8827. 7:30:55Then we'll add the for. So let's just
  8828. 7:30:58copy this and add it here. We'll add for
  8829. 7:31:01of and con path and content
  8830. 7:31:07of object dot entries and provide
  8831. 7:31:11relevant files. Then we'll add context
  8832. 7:31:14parts dot push and provide the
  8833. 7:31:17back text. In this back we add this n
  8834. 7:31:21and path. Then we'll add the
  8835. 7:31:24content. Now after that here we'll add
  8836. 7:31:27another if statement.
  8837. 7:31:30In this if statement we'll add recent
  8838. 7:31:32messages dotlength is greater than zero.
  8839. 7:31:36We are getting the recent messages here
  8840. 7:31:38as parameter. So in this case
  8841. 7:31:43just add these statements copy and paste
  8842. 7:31:47it here that is context parts dotpush
  8843. 7:31:50and provide
  8844. 7:31:55this string and after that we'll add for
  8845. 7:31:59con msg that is message of recent
  8846. 7:32:03messages dot slice
  8847. 7:32:08and provide
  8848. 7:32:09minus 3. Then we'll add context parts
  8849. 7:32:12dot push and provide back text with
  8850. 7:32:16dollar sign curly braces and uh insert
  8851. 7:32:19the message dot roll and message dot
  8852. 7:32:24content.
  8853. 7:32:26Now after that let me close this curly
  8854. 7:32:29braces here.
  8855. 7:32:34Now it is correct. Here we'll add
  8856. 7:32:37context parts dotpush provide back text
  8857. 7:32:40and provide the message
  8858. 7:32:43revision requested and add the prompt.
  8859. 7:32:47Then we'll add console.log and provide
  8860. 7:32:50the message from AI revising project.
  8861. 7:32:55Then we'll add const
  8862. 7:32:58object as
  8863. 7:33:01row pared equal to
  8864. 7:33:05await and here again use
  8865. 7:33:09generate object. Now in this generate
  8866. 7:33:13object we will add the model. Then we'll
  8867. 7:33:17add the
  8868. 7:33:19schema.
  8869. 7:33:21In this schema just add revision result
  8870. 7:33:25schema and import it from the schema.js
  8871. 7:33:29or AI schema.js. Then we'll add the
  8872. 7:33:32system.
  8873. 7:33:34In this system we'll add
  8874. 7:33:39revise system from the prompts dot js.
  8875. 7:33:43Then we'll add the prompt.
  8876. 7:33:46In the prompt, we'll add
  8877. 7:33:49context parts dot
  8878. 7:33:52join
  8879. 7:33:54and provide
  8880. 7:33:56back slash n.
  8881. 7:33:59Then we'll add
  8882. 7:34:02max retries
  8883. 7:34:04it will be two. Now let's add the if
  8884. 7:34:08statement here. In this if we'll add row
  8885. 7:34:12passed and
  8886. 7:34:14array dot is array row passed dot
  8887. 7:34:20operations.
  8888. 7:34:21In this case we'll add raw path dot
  8889. 7:34:24operations equal to raw dot operations
  8890. 7:34:28dot map. And uh let's add the add
  8891. 7:34:32function and provide the
  8892. 7:34:36individual operation. And here we'll add
  8893. 7:34:39if statement
  8894. 7:34:41if not of op or
  8895. 7:34:46type of op not equal to object. Then
  8896. 7:34:53return and provide the op.
  8897. 7:34:57After that we'll add let
  8898. 7:35:00operation a string equal to a string
  8899. 7:35:06and then we'll add op dot op or empty
  8900. 7:35:11string then dot
  8901. 7:35:15trim
  8902. 7:35:17then dot to lower case. Now we'll add if
  8903. 7:35:21statement here. If
  8904. 7:35:25array contains create add new includes
  8905. 7:35:28operation a string then simply add opt
  8906. 7:35:34equal to
  8907. 7:35:36create then we'll add else if and
  8908. 7:35:40provide this array that update edit
  8909. 7:35:45modify patch
  8910. 7:35:48dot includes
  8911. 7:35:50operation string
  8912. 7:35:52Then provide op dot op equal to update.
  8913. 7:36:00Let's move this parenthesis here.
  8914. 7:36:04Now it is correct. After that let's add
  8915. 7:36:08another else if. Just copy and paste it
  8916. 7:36:10here. In this one we have added else if
  8917. 7:36:15delete remove d or rm dot includes
  8918. 7:36:21operation string then opt
  8919. 7:36:24equal to delete. After that
  8920. 7:36:28just add the if statement.
  8921. 7:36:30If op.path and type of op.path path is
  8922. 7:36:35equal to a string and
  8923. 7:36:40not of op dot path start with forward
  8924. 7:36:44slash in this case just add the
  8925. 7:36:48operation dotpath it will be forward
  8926. 7:36:50slash plus optath
  8927. 7:36:53now let's come here here we will add if
  8928. 7:36:57optent
  8929. 7:37:00then we'll add optent equal to normalize
  8930. 7:37:04content and provide op.content.
  8931. 7:37:10Now let's duplicate it. Here we'll add
  8932. 7:37:12opt.
  8933. 7:37:15Then add
  8934. 7:37:18optarch
  8935. 7:37:19equal to normalize content opt.
  8936. 7:37:25Let's duplicate it. We'll add op.replace
  8937. 7:37:31and provide op.replace replace
  8938. 7:37:34equal to normalize content op dot
  8939. 7:37:37replace.
  8940. 7:37:39Now just add the another if statement
  8941. 7:37:43if opt
  8942. 7:37:45equal to create and operation dot
  8943. 7:37:49content. Now in this if statement we'll
  8944. 7:37:51add con validation equal to
  8945. 7:37:55validate revision content and import it
  8946. 7:37:58from the code validator.
  8947. 7:38:01And after that we'll add operation dot
  8948. 7:38:04content in the first argument and then
  8949. 7:38:07provide operation dotpath
  8950. 7:38:11and then we'll add comma create. Then
  8951. 7:38:15we'll add operation dot content equal to
  8952. 7:38:18validation dot content. Again we'll add
  8953. 7:38:22the if. Let's add validation dot
  8954. 7:38:26wararning.length is greater than zero.
  8955. 7:38:30In this case just add console log. So we
  8956. 7:38:33have added this console log and uh after
  8957. 7:38:37that we'll add else if
  8958. 7:38:45and this else if we'll add operation dot
  8959. 7:38:47operation
  8960. 7:38:49equal to update.
  8961. 7:38:54Let me remove it from here and we will
  8962. 7:38:57add it here. For this if we'll add the
  8963. 7:38:59else if
  8964. 7:39:03here we have equal to create and here we
  8965. 7:39:06have equal to update and operation dot
  8966. 7:39:10replace. So in this case just add con
  8967. 7:39:14validation. So just copy this one paste
  8968. 7:39:17it here.
  8969. 7:39:19validation equal to validation revision
  8970. 7:39:22content operation dotreplace
  8971. 7:39:27dot operation dot
  8972. 7:39:31path and here we'll add update.
  8973. 7:39:35Now after that just add operation
  8974. 7:39:38dotreplace equal to
  8975. 7:39:40validation dotcontent.
  8976. 7:39:43Then we'll add if
  8977. 7:39:47validation dot warning.length is greater
  8978. 7:39:50than zero
  8979. 7:39:52in this case simply add one console log.
  8980. 7:39:56So we have added this console log here.
  8981. 7:40:00That's it. And after that here simply
  8982. 7:40:03add the return and return this
  8983. 7:40:05operation.
  8984. 7:40:07And at the end here we'll add
  8985. 7:40:11return and provide
  8986. 7:40:14raw pasted. Save the changes. So we have
  8987. 7:40:18completed the function that is
  8988. 7:40:24device project.
  8989. 7:40:26Now let's use this generate project
  8990. 7:40:29function in our project controller. So
  8991. 7:40:31let's open the controllers. Then we have
  8992. 7:40:34the project controller. Now in this
  8993. 7:40:37project controller
  8994. 7:40:39we have the run background generation.
  8995. 7:40:42So in this run background generation
  8996. 7:40:44just add the try catch. Now in this try
  8997. 7:40:47block first we'll add the console log.
  8998. 7:40:50So we have added this console log that
  8999. 7:40:53is background AI a starting generation
  9000. 7:40:57for project and the project ID. Then we
  9001. 7:41:00will add the con
  9002. 7:41:03result equal to await and use that
  9003. 7:41:06function that is generate project and
  9004. 7:41:09get this project from the
  9005. 7:41:12services folder and AI.js file. Let's
  9006. 7:41:15scroll up. You can see it is imported
  9007. 7:41:17from the services/ AI.js. Now after that
  9008. 7:41:21here we'll add
  9009. 7:41:24the argument that will be prompt. Then
  9010. 7:41:27we'll add the
  9011. 7:41:29object. In this object we'll add on
  9012. 7:41:32plan.
  9013. 7:41:35It will be asynchronous add function
  9014. 7:41:38with the plan in the parameter.
  9015. 7:41:41Now here we'll add the console log
  9016. 7:41:43again. So we have added this console log
  9017. 7:41:45and provide the con
  9018. 7:41:48file list equal to plan
  9019. 7:41:52dot
  9020. 7:41:54files
  9021. 7:41:56dot map. In this map add the arrow
  9022. 7:41:59function get the individual file. Here
  9023. 7:42:03we will add the
  9024. 7:42:06back tick.
  9025. 7:42:08In this back tix we'll add dash back
  9026. 7:42:12slash
  9027. 7:42:13file.path
  9028. 7:42:15then colon file dot description
  9029. 7:42:18and after that we'll add dot join
  9030. 7:42:22and in this join add back slash n. Now
  9031. 7:42:26we'll add await project model dot find
  9032. 7:42:31by id and update
  9033. 7:42:36and provide the project id to find the
  9034. 7:42:41project and then we'll add the object
  9035. 7:42:43that will update the data. So just add
  9036. 7:42:45the name property. In this name property
  9037. 7:42:47add plan dot project name or generated
  9038. 7:42:51project. Then we'll add the status. It
  9039. 7:42:54will be generating. Then we'll add files
  9040. 7:42:58planned. It will be plan dotfiles. Then
  9041. 7:43:01we'll add dollar push
  9042. 7:43:05object. And uh in this object just add
  9043. 7:43:11the messages.
  9044. 7:43:14So just add the messages. It will be ro
  9045. 7:43:17assistant. Then add the content. So in
  9046. 7:43:21the content let's provide planned
  9047. 7:43:23website structure and then file list.
  9048. 7:43:27Then we'll add the time stamp. It will
  9049. 7:43:29be new date. Now after that let's come
  9050. 7:43:33here. Here we'll add on file start. It
  9051. 7:43:38will be asynchronous add function with
  9052. 7:43:42the path in the parameter. Here also
  9053. 7:43:44we'll add the console log.
  9054. 7:43:47Let's add it here. And after this
  9055. 7:43:49console log, we'll add await and simply
  9056. 7:43:52use the
  9057. 7:43:54project model
  9058. 7:43:56dot find by ID and update.
  9059. 7:44:01In this one, we'll add the project ID,
  9060. 7:44:04comma, and provide one object where just
  9061. 7:44:09add the current file. It will be path.
  9062. 7:44:13Now after that let's add the comma here
  9063. 7:44:17and provide
  9064. 7:44:18on file complete. It is also
  9065. 7:44:22asynchronous add function. Here we'll
  9066. 7:44:24get the path and code. Here we have on
  9067. 7:44:27plan. After this on plan we have on file
  9068. 7:44:30start and then on file complete. Now in
  9069. 7:44:33this on file complete again we'll add
  9070. 7:44:36one message in console. So just add
  9071. 7:44:38console.log log and then we'll add con
  9072. 7:44:42project equal to await and use the
  9073. 7:44:45project model dot find by id and provide
  9074. 7:44:51the project id. Now after that let's add
  9075. 7:44:54if
  9076. 7:44:56project if the project is available in
  9077. 7:44:59this case just add project dotfiles
  9078. 7:45:03equal to the project dotfiles or empty
  9079. 7:45:08object then we'll add project dot files
  9080. 7:45:11path equal to
  9081. 7:45:14object that contains content it will be
  9082. 7:45:18code then hash has content
  9083. 7:45:23Then we'll add the project dot files
  9084. 7:45:27generated
  9085. 7:45:28equal to
  9086. 7:45:30array with a spread operator and provide
  9087. 7:45:35project dot files generated or empty
  9088. 7:45:40array
  9089. 7:45:41then comma path. After that we'll add
  9090. 7:45:44project dot messages dotpush. So just
  9091. 7:45:48add the role assistant content and
  9092. 7:45:50timestamp. So in the content we have
  9093. 7:45:53added created file and the path.
  9094. 7:45:57Now after that here we'll add the
  9095. 7:45:59project dot current file it will be null
  9096. 7:46:03and then project dot mark modified and
  9097. 7:46:07provide files. Then we'll add await and
  9098. 7:46:12project
  9099. 7:46:14dot save. So it will save the changes in
  9100. 7:46:18the database. Now after that here we'll
  9101. 7:46:22add console.log
  9102. 7:46:25that is background AI successfully
  9103. 7:46:27generated project and the project id.
  9104. 7:46:30Now let's add con project equal to await
  9105. 7:46:34and provide the project model dotfind by
  9106. 7:46:36id and provide the project ID. Then
  9107. 7:46:40we'll add the if statement if project is
  9108. 7:46:42available. Then provide project dot a
  9109. 7:46:46status it will be completed. Then add
  9110. 7:46:49the project dot version. It will be one.
  9111. 7:46:53Then we'll add the if
  9112. 7:46:56result dot description.
  9113. 7:47:00In this case just add the project name
  9114. 7:47:03and equal to result dot description.
  9115. 7:47:08Then we'll add project
  9116. 7:47:10dot messages dotpush. Here we'll add ro
  9117. 7:47:14assistant and content and time stamp. So
  9118. 7:47:18in the content we have added website
  9119. 7:47:20generation complete. You can view and
  9120. 7:47:22edit the files.
  9121. 7:47:25After that let's add a weight and
  9122. 7:47:28provide the project dot save to save the
  9123. 7:47:33data in database.
  9124. 7:47:35Now let's come here in the catch block.
  9125. 7:47:37In this catch block we'll add the error
  9126. 7:47:40and then we'll add the console.
  9127. 7:47:44Now we'll add await
  9128. 7:47:47and provide the
  9129. 7:47:49project dot find by id and update. Here
  9130. 7:47:55we'll provide the project id
  9131. 7:47:58then comma and provide one object. Here
  9132. 7:48:01in this object we'll add the status
  9133. 7:48:03failed and the error will be error dot
  9134. 7:48:06message. And then we'll add the dollar
  9135. 7:48:09push and provide one object. And here
  9136. 7:48:13just add the messages.
  9137. 7:48:16In this messages, let's add the role
  9138. 7:48:19assistant. And then we'll add the
  9139. 7:48:20content and time stamp. And the content
  9140. 7:48:23is generation failed and the error dot
  9141. 7:48:25message.
  9142. 7:48:27That's it. So we have completed our
  9143. 7:48:30function that is run background
  9144. 7:48:32generation. Now we can generate the
  9145. 7:48:35content in the background when we enter
  9146. 7:48:37the prompt. Now after that we have to
  9147. 7:48:41add the functionality for the chat. It
  9148. 7:48:44means we can enter the prompt in the
  9149. 7:48:46chat to revise the website or again edit
  9150. 7:48:49the website. For that we'll create a
  9151. 7:48:52separate file. Now let's create the
  9152. 7:48:56chat controller for creating the chat
  9153. 7:48:58APIs. Using that we will update our
  9154. 7:49:01generated project. So just open the
  9155. 7:49:04controllers folder. In this one create a
  9156. 7:49:06new file and write the file name
  9157. 7:49:08chatcontroller.js.
  9158. 7:49:13In this one
  9159. 7:49:15we have to create a controller function.
  9160. 7:49:19So first let me add the
  9161. 7:49:23method type. it will be post and the
  9162. 7:49:25path will be / API/ project/ colon id
  9163. 7:49:28and chat. Then we'll add one another
  9164. 7:49:32command that is send a revision prompt
  9165. 7:49:36and return updated project. So let's
  9166. 7:49:40create and export the function here. So
  9167. 7:49:43just add export a sync function called
  9168. 7:49:46chat.
  9169. 7:49:48Here we'll get the request
  9170. 7:49:52and response.
  9171. 7:49:56Then we'll add const and we'll get the
  9172. 7:49:59prompt from the request body. So just
  9173. 7:50:01add the request dot body
  9174. 7:50:04and here we will get the prompt. Now
  9175. 7:50:07we'll check the prompt is available or
  9176. 7:50:10not. So just add if
  9177. 7:50:12not of prompt or type of prompt
  9178. 7:50:18is not equal to
  9179. 7:50:21string.
  9180. 7:50:23In this case simply add response dot a
  9181. 7:50:26status 400 and we'll add the error
  9182. 7:50:28message that is prompt is required and
  9183. 7:50:31returned. Now we will check the user is
  9184. 7:50:34authenticated or not. So let's copy this
  9185. 7:50:37paste it here. I'll provide if not of
  9186. 7:50:43request dot user property in this case
  9187. 7:50:47we'll add a status 4.1 then JSON with
  9188. 7:50:52the error message that is unauthorized
  9189. 7:50:55and add return now suppose the prompt is
  9190. 7:50:58available then the user is authenticated
  9191. 7:51:03after that we have to find the project
  9192. 7:51:06so just add con project equal to await
  9193. 7:51:08it and then add the
  9194. 7:51:11project model. Just click here to import
  9195. 7:51:13it. You can see project model is
  9196. 7:51:16imported from the models folder. Project
  9197. 7:51:19file just add the file name
  9198. 7:51:21extension.js.
  9199. 7:51:23Now here just add dot find one.
  9200. 7:51:27In this one let's add the underscore id.
  9201. 7:51:32It will be request.params
  9202. 7:51:35do ID. Then we'll add the owner
  9203. 7:51:38property.
  9204. 7:51:40In the owner property, just add the
  9205. 7:51:42request
  9206. 7:51:44dot user dot user ID. So it will find
  9207. 7:51:50the project. Now just add if statement
  9208. 7:51:52if not of project. Suppose we could not
  9209. 7:51:55find any project. In this case, just add
  9210. 7:51:58response. status 4.4 and the error
  9211. 7:52:01message is project not found and return.
  9212. 7:52:05Now let's add one comment here. Suppose
  9213. 7:52:08the project is available then we'll add
  9214. 7:52:10comment set a status to revising and
  9215. 7:52:13save user prompt immediately. So just
  9216. 7:52:16add the project dot status
  9217. 7:52:21equal to
  9218. 7:52:24revising. Then we will add project dot
  9219. 7:52:27messages dot push. And here we'll add
  9220. 7:52:30the object with ro user. And then we'll
  9221. 7:52:34add the content. And the content will be
  9222. 7:52:36our prompt. Then we'll add the time
  9223. 7:52:38stamp. It will be new date.
  9224. 7:52:42After that save the changes in database.
  9225. 7:52:45So just add await
  9226. 7:52:48project dots save. Next we'll add the
  9227. 7:52:52try catch a statement here. So let's add
  9228. 7:52:54the try catch. In this try block just
  9229. 7:52:58add one comment that is
  9230. 7:53:01build compact manifest that contains
  9231. 7:53:05path hash size instead of sending all
  9232. 7:53:08code. So we have to create a function
  9233. 7:53:10for building the manifest. So just
  9234. 7:53:12scroll up and here we will create that
  9235. 7:53:15function. So just add export function
  9236. 7:53:20and function name is build manifest
  9237. 7:53:24and here we provide all files. So just
  9238. 7:53:27add the
  9239. 7:53:29files.
  9240. 7:53:31Now in this one let's add con manifest
  9241. 7:53:36equal to empty array. Then for of in
  9242. 7:53:39this for off we'll add the array with
  9243. 7:53:44path and entry. Then we'll add object
  9244. 7:53:48dot entries and files. Then just use the
  9245. 7:53:53manifest dot
  9246. 7:53:56push
  9247. 7:53:59and provide the object with path. Then
  9248. 7:54:02we will add hash. It will be entry.ash.
  9249. 7:54:07After that provide size.
  9250. 7:54:13It will be entry
  9251. 7:54:17dot content.length
  9252. 7:54:21and then return this manifest. So just
  9253. 7:54:23add return manifest
  9254. 7:54:27and let's use this function here
  9255. 7:54:33in this try block. So in this try block
  9256. 7:54:36let's provide
  9257. 7:54:38con
  9258. 7:54:43manifest equal to build manifest and
  9259. 7:54:47provide the project
  9260. 7:54:50dot files.
  9261. 7:54:54After that let's add another comment
  9262. 7:54:57that is include all files
  9263. 7:55:01contents so that AI can do accurate
  9264. 7:55:05search and replace. So just add con
  9265. 7:55:09relevant files it will be object.
  9266. 7:55:13Then we'll add for of
  9267. 7:55:17and let's add path and entry
  9268. 7:55:22of of object dot entries
  9269. 7:55:25and provide the project dot files. In
  9270. 7:55:29this one provide relevant files path
  9271. 7:55:32equal to entry dot content.
  9272. 7:55:37Now after that again add the comment
  9273. 7:55:40that is recent messages for content that
  9274. 7:55:43is last for maximum. So here we'll add
  9275. 7:55:46const recent messages equal to
  9276. 7:55:51project dot
  9277. 7:55:54messages
  9278. 7:55:55dot slice and provide minus4.
  9279. 7:56:00Then we will add dot map. Add the arrow
  9280. 7:56:04function here in this map and get the
  9281. 7:56:06individual message.
  9282. 7:56:10And after that just add the parenthesis
  9283. 7:56:13and object that contains the role. Ro
  9284. 7:56:17will be message roll or m dot roll. Then
  9285. 7:56:21we'll add content. It will be m dot
  9286. 7:56:24content.
  9287. 7:56:27Now after that we have to add one
  9288. 7:56:29console log. So I have simply added this
  9289. 7:56:32console log here and then we'll add one
  9290. 7:56:36comment that is call AI with manifest
  9291. 7:56:38plus relevant files.
  9292. 7:56:42So just add const result equal to await
  9293. 7:56:48and here we will add a function that we
  9294. 7:56:50have added in the AI.js file that is
  9295. 7:56:52revise project. Import it. You can see
  9296. 7:56:56here the device project is imported from
  9297. 7:56:59the services/ AI then js.
  9298. 7:57:04Now let's come here and uh in this one
  9299. 7:57:08we will provide our prompt then provide
  9300. 7:57:11manifest.
  9301. 7:57:13After that provide the relevant files
  9302. 7:57:15and uh recent messages
  9303. 7:57:20and here we'll get the result. Let's add
  9304. 7:57:22the console log here.
  9305. 7:57:25So we will add console.log
  9306. 7:57:28that is AI got result operations.length
  9307. 7:57:34and operations result dot description
  9308. 7:57:37and after that just add one comment
  9309. 7:57:39apply operations to file map.
  9310. 7:57:44So just add const files
  9311. 7:57:48updated files applied error equal to
  9312. 7:57:51apply
  9313. 7:57:53operations. Let's
  9314. 7:57:56import it. So just open the sidebar.
  9315. 7:58:00Here we have services and div.
  9316. 7:58:03So let's open it. And now we'll get the
  9317. 7:58:05suggestion. So now if I type
  9318. 7:58:09apply operations, we are getting the
  9319. 7:58:11suggestion to import it. So let's import
  9320. 7:58:13it and scroll up. You can see it is
  9321. 7:58:15imported from the services/diff.js.
  9322. 7:58:19Now let's complete this. So in this one
  9323. 7:58:24provide some arguments that will be
  9324. 7:58:26project dotfiles,
  9325. 7:58:30result dot operations. Next we'll add
  9326. 7:58:33the if statement if errors do.length
  9327. 7:58:37greater than zero. In this case, just
  9328. 7:58:39add the console. That is the warning.
  9329. 7:58:43And uh if there's no error in this case,
  9330. 7:58:48we'll add update project in database.
  9331. 7:58:51For that, just add the project dot
  9332. 7:58:54files. It will be updated files. Then
  9333. 7:58:57add project dot mark modified. Let's add
  9334. 7:59:03files. Then add project dot version. It
  9335. 7:59:07will be plus equal to 1. Then project
  9336. 7:59:11dot a status it will be completed. Then
  9337. 7:59:15project dot
  9338. 7:59:17messages dot push
  9339. 7:59:20and add one object. Where we'll add the
  9340. 7:59:23role. It will be assistant.
  9341. 7:59:27Then we will add the content. In the
  9342. 7:59:30content we will add result.escription
  9343. 7:59:34plus
  9344. 7:59:35error.length length is greater than
  9345. 7:59:37zero. Then we'll add some operations
  9346. 7:59:39field. Else we'll add the empty string
  9347. 7:59:44and after that we'll add a weight and
  9348. 7:59:47provide the project
  9349. 7:59:50dot save. Now let's come here in the
  9350. 7:59:54catch block. But before that here in
  9351. 7:59:55this try block only we will add one
  9352. 7:59:58comment that is return updated project.
  9353. 8:00:02For that just add const
  9354. 8:00:05files object will be empty object and
  9355. 8:00:07provide the for of. So in this for off
  9356. 8:00:10we have added the const path entry of
  9357. 8:00:14object dot entries project dotfiles and
  9358. 8:00:18files object path it will be entry dot
  9359. 8:00:21content and then we'll add response
  9360. 8:00:23here. So just add response dot
  9361. 8:00:26JSON and add the object. So in this
  9362. 8:00:29object we'll add underscore id. It will
  9363. 8:00:31be project dot id. Then name it will be
  9364. 8:00:35project dotname. Description will be
  9365. 8:00:37project dot description.
  9366. 8:00:41Then let's add the files. It will be
  9367. 8:00:45files object. After that we have to add
  9368. 8:00:48the messages. It will be project dot
  9369. 8:00:51messages. Then add the version a status
  9370. 8:00:55applied and uh errors. Then we'll add
  9371. 8:00:59the AI description. And here just add
  9372. 8:01:01result dot description. Now come here in
  9373. 8:01:04the catch block here we'll get the error
  9374. 8:01:08and then add the console dot error.
  9375. 8:01:11After that we'll add project dot a
  9376. 8:01:13status and we'll mark the status
  9377. 8:01:16completed. Then let's add await project
  9378. 8:01:19dots save. Then add response dot a
  9379. 8:01:22status it will be 500 and provide the
  9380. 8:01:25error message that is error dot message
  9381. 8:01:28or failed to process revision request.
  9382. 8:01:31That's it. So we have completed this
  9383. 8:01:34chat controller and after that we have
  9384. 8:01:36to create the route for this chat
  9385. 8:01:38feature. For that let's open the sidebar
  9386. 8:01:41and in the routes we have the project
  9387. 8:01:43routes. So just open it and here
  9388. 8:01:47before this export project router let's
  9389. 8:01:50add the command that is chat and for
  9390. 8:01:54this chat we'll use the project router
  9391. 8:01:57and uh dot post method in this one add
  9392. 8:02:02the endpoint that will be /
  9393. 8:02:06id then / chat and then we'll add the
  9394. 8:02:11function that is chat. Let's import it.
  9395. 8:02:13So you can see the chat function is
  9396. 8:02:15imported from the controllers
  9397. 8:02:17chatcontroller.js.
  9398. 8:02:18Save the changes. So now we have
  9399. 8:02:21completed all our APIs.
  9400. 8:02:26So we have completed the backend server.
  9401. 8:02:29Let me commit these changes on GitHub
  9402. 8:02:31and we will review our code using code
  9403. 8:02:33rabbit. So just click here and add one
  9404. 8:02:37commit message.
  9405. 8:02:42Backend server completed. Commit changes
  9406. 8:02:45and sync.
  9407. 8:02:48After that, let me open the web browser
  9408. 8:02:51and we will open the GitHub repo. Here
  9409. 8:02:54we have this button compare and pull
  9410. 8:02:56request.
  9411. 8:03:00Then click here create pull request. And
  9412. 8:03:03once we create the pull request, the
  9413. 8:03:05code rabbit will start analyzing our
  9414. 8:03:08code.
  9415. 8:03:10Now you can see the code rabbit is
  9416. 8:03:12running and it is analyzing our code.
  9417. 8:03:16Now you can see the code rabbit has
  9418. 8:03:18reviewed our code and here we have the
  9419. 8:03:20review summary and after that you can
  9420. 8:03:21see the code rabbit is suggesting some
  9421. 8:03:25changes for different code files. So you
  9422. 8:03:28can see so we have to update the project
  9423. 8:03:31controller js file. In this one we have
  9424. 8:03:33one critical issue and here it is
  9425. 8:03:35suggesting to remove this statement. It
  9426. 8:03:39means we have to remove this if
  9427. 8:03:41statement and directly provide this
  9428. 8:03:43files object path entry content. So let
  9429. 8:03:46me update it in our code file. And you
  9430. 8:03:49can see the file name project
  9431. 8:03:51controller.js and line number 245 to
  9432. 8:03:55250. So just come back here
  9433. 8:03:59and open
  9434. 8:04:01controller project controller and then
  9435. 8:04:04come to the
  9436. 8:04:06245.
  9437. 8:04:08So here you can see we have the if
  9438. 8:04:11statement. So we have to remove this if
  9439. 8:04:13statement and directly provide this
  9440. 8:04:16files object path entry content. Save
  9441. 8:04:19the changes and let's see the next
  9442. 8:04:21suggestion. So scroll down and see the
  9443. 8:04:24suggestion
  9444. 8:04:26for the next file. So here we have the
  9445. 8:04:29suggestion in package.json. So we can
  9446. 8:04:31skip this one. It is minor. And after
  9447. 8:04:34that you can see here we have the major
  9448. 8:04:36issue in project router or project
  9449. 8:04:40routes.js. So in this one we have missed
  9450. 8:04:43this forward slash. So just come back to
  9451. 8:04:46the VS code then open the routes project
  9452. 8:04:50routes.js JS and you can see here we
  9453. 8:04:52have the project router.get and here we
  9454. 8:04:55have to add the slash just update this
  9455. 8:04:57one and save the changes. Now we'll come
  9456. 8:05:00back here and see the next suggestion or
  9457. 8:05:03work fix. So here we have the AI.js
  9458. 8:05:06file. In this one we have the critical
  9459. 8:05:08issue. So it is suggesting this fix. So
  9460. 8:05:12we have to correct this spelling for
  9461. 8:05:14validation.
  9462. 8:05:16Let's come to AI.js js file and open the
  9463. 8:05:20line number
  9464. 8:05:22235.
  9465. 8:05:24So just open services AI.js and 235.
  9466. 8:05:30Let's update it. It will be validation
  9467. 8:05:33dotwnings.length.
  9468. 8:05:36It is correct. And uh after updating it,
  9469. 8:05:39let's scroll down. You can see we have
  9470. 8:05:42some
  9471. 8:05:44major issue in the AI schema. So in this
  9472. 8:05:47one we have the unused file import.
  9473. 8:05:52So just come back to the VS code and
  9474. 8:05:55open the AI schema and in this one you
  9475. 8:05:58can see we have this file. So let's
  9476. 8:06:00remove it.
  9477. 8:06:02Save the changes and after that let's
  9478. 8:06:05see the next iso. So here we have the
  9479. 8:06:08content normalizer.js and uh here it is
  9480. 8:06:11suggesting some fix. So we have to
  9481. 8:06:13remove these three lines and add this
  9482. 8:06:15one. So I'll just copy it
  9483. 8:06:21and open our
  9484. 8:06:24content normalizer js file and come to
  9485. 8:06:26line 27.
  9486. 8:06:28Here you can see we have these commands
  9487. 8:06:30and code. Right? Let's verify it again.
  9488. 8:06:34So we have to replace all these three
  9489. 8:06:35lines and add the new code. So we have
  9490. 8:06:38updated it. Let me just come back here.
  9491. 8:06:42We are getting some warning in this
  9492. 8:06:43content. Let me revert the code.
  9493. 8:06:46So we have to remove this code and add
  9494. 8:06:50the code from here. So let me just
  9495. 8:06:52update this last statement. We will
  9496. 8:06:55leave the comment as it is. So in this
  9497. 8:06:57one you can see here we have this
  9498. 8:06:58expression. Just copy it
  9499. 8:07:02and update it here inside this replace.
  9500. 8:07:08Now save the changes.
  9501. 8:07:10Let's remove this extra parenthesis.
  9502. 8:07:13save the changes. So we have updated
  9503. 8:07:15this code also. Now scroll down and see
  9504. 8:07:17the next critical issue in this div.js.
  9505. 8:07:22So here we have to
  9506. 8:07:25update the code. We have to add the
  9507. 8:07:28import statement import crypto. So just
  9508. 8:07:31copy this one and open the
  9509. 8:07:35div.js. And here at line one we will add
  9510. 8:07:40import crypto from
  9511. 8:07:43crypto package. Save the changes. And
  9512. 8:07:46after that you can see we have some
  9513. 8:07:48suggestion
  9514. 8:07:52in this diff only. Here it is suggesting
  9515. 8:07:56to replace this
  9516. 8:07:59code in this line.
  9517. 8:08:02So just copy this one.
  9518. 8:08:06and come to
  9519. 8:08:10diff. Scroll down and here we have this
  9520. 8:08:14code. Let me verify it. It is in 75
  9521. 8:08:2078.
  9522. 8:08:21Right? So here we have the line number
  9523. 8:08:2378.
  9524. 8:08:27Let me replace this one.
  9525. 8:08:32Save the changes. Now after that you can
  9526. 8:08:36see we don't have any other suggestions.
  9527. 8:08:38So we have updated our code based on the
  9528. 8:08:41code rabbit suggestion for bug fix.
  9529. 8:08:44After that let me merge these changes in
  9530. 8:08:46the main branch. So just add merge pull
  9531. 8:08:48request.
  9532. 8:08:50Confirm merge
  9533. 8:08:54and uh let me just come back here
  9534. 8:08:58then click here and click pull. So it
  9535. 8:09:02will pull the latest changes. So we have
  9536. 8:09:04completed the front end and backend
  9537. 8:09:08server. Now we will integrate these
  9538. 8:09:09backend APIs with our front end. So let
  9539. 8:09:13me close all these files. So right click
  9540. 8:09:15here and select close saved and we will
  9541. 8:09:18fold this one also. So here you can see
  9542. 8:09:20we have the client and server.
  9543. 8:09:23To connect our backend APIs with client
  9544. 8:09:25just open the sidebar and then come to
  9545. 8:09:28client repository. In this one you can
  9546. 8:09:30see we have the API folder and here we
  9547. 8:09:32have API.js and in this one we have
  9548. 8:09:34added the dummy data that is dummy user.
  9549. 8:09:37Just remove this dummy user. After that
  9550. 8:09:39you can see we have the initial
  9551. 8:09:41projects. Let's remove this initial
  9552. 8:09:44projects. Then we have this API
  9553. 8:09:47dodefaults dot adapter. So we will
  9554. 8:09:50remove this one also. So now the API
  9555. 8:09:54file is cleared. Here we only have the
  9556. 8:09:57axios and we have created the instance
  9557. 8:09:59of axios called API and provided the
  9558. 8:10:02base URL and this is the vat base URL.
  9559. 8:10:06So we have to update the base URL in our
  9560. 8:10:08environment variable. So just openv file
  9561. 8:10:11from the client. So currently we don't
  9562. 8:10:16have the env file in this client. So let
  9563. 8:10:20me create that.
  9564. 8:10:22In this client, we'll add new file with
  9565. 8:10:25the name env. And here we will add in
  9566. 8:10:30the environment variable with the name
  9567. 8:10:32vase URL.
  9568. 8:10:36And in this one we will add our backend
  9569. 8:10:39server URL. So you can see the backend
  9570. 8:10:41server is running at localhost 3000. So
  9571. 8:10:45just add it here. Remove this forward
  9572. 8:10:47slash from the end. So it is http
  9573. 8:10:49localhost 3000. save the changes and
  9574. 8:10:52after that let me open our web page.
  9575. 8:10:57So now you can see if I open the web
  9576. 8:11:00page it is asking to sign in or sign up
  9577. 8:11:04because we are not authenticated. So
  9578. 8:11:07whenever we try to open our homepage it
  9579. 8:11:10will redirect us to the login page and
  9580. 8:11:13if we don't have any account we can go
  9581. 8:11:15to create an account. So here we have to
  9582. 8:11:18create an account. So let me add the
  9583. 8:11:20name
  9584. 8:11:26greatest tag. Then we'll add one email
  9585. 8:11:29id. So let's add the
  9586. 8:11:31greatest [email protected]. And here we'll
  9587. 8:11:34add the password
  9588. 8:11:38then sign up.
  9589. 8:11:40After sign up we can see our homepage.
  9590. 8:11:43And on this homepage you can see we
  9591. 8:11:45don't have any previous project. So we
  9592. 8:11:47can create a new project. Here for that
  9593. 8:11:49here we have to add a prompt. So here we
  9594. 8:11:52will add a prompt. Using that we can
  9595. 8:11:54create a new website.
  9596. 8:11:59Let's add the prompt. Create a portfolio
  9597. 8:12:02website for a web developer. And after
  9598. 8:12:05that we'll click on this send icon.
  9599. 8:12:08So after adding the prompt it will open
  9600. 8:12:11the project builder page. At the top you
  9601. 8:12:14can see we have this path builder/
  9602. 8:12:17project id and in the left side you can
  9603. 8:12:19see we have the chat. So in this chat we
  9604. 8:12:22have our prompt and after that you can
  9605. 8:12:24see the AI response that is planning
  9606. 8:12:27project structure
  9607. 8:12:29and in the main content area you can see
  9608. 8:12:33planning architecture and betting
  9609. 8:12:35production ready react code base and we
  9610. 8:12:39have the loading animation. So we have
  9611. 8:12:41to wait for few minutes to generate our
  9612. 8:12:45website.
  9613. 8:12:47After few minutes you can see here we
  9614. 8:12:49have the another response in the left
  9615. 8:12:52sidebar which is the chat area and here
  9616. 8:12:55we have the message AI agent is building
  9617. 8:12:58and here you can see the progress.
  9618. 8:13:00Here we have the list of files that is
  9619. 8:13:03total number of files is nine and it is
  9620. 8:13:05creating the first one that is app.js
  9621. 8:13:08and the first one has been created now.
  9622. 8:13:10And here we have the list of files that
  9623. 8:13:13is the
  9624. 8:13:15file and folder structure. And in the
  9625. 8:13:18left side if I click on this files here
  9626. 8:13:20you can see we only have the app do.js
  9627. 8:13:23because only app do.js is created for
  9628. 8:13:26now and it is creating the other files
  9629. 8:13:28one by one. So we have to wait for few
  9630. 8:13:30minutes.
  9631. 8:13:35Now you can see our project has been
  9632. 8:13:37generated. Here we have the beautiful
  9633. 8:13:38portfolio created using AI. Let me
  9634. 8:13:41scroll it. You can see it is a single
  9635. 8:13:44page website where we have the features
  9636. 8:13:48then testimonial. Here we have the
  9637. 8:13:51contact section and we have the footer
  9638. 8:13:53also right and after that let's go to
  9639. 8:13:58code. So it will display the code also.
  9640. 8:14:00We can manually edit this code and it
  9641. 8:14:02will be autosaved in our database. If I
  9642. 8:14:05go to left side in the files here you
  9643. 8:14:07can see the entire file structure and
  9644. 8:14:09folders. So here we have the app and
  9645. 8:14:11then components. In the components we
  9646. 8:14:13have these files like contact features
  9647. 8:14:16footer header hero and
  9648. 8:14:20projects and testimonials. Let me open
  9649. 8:14:23the hero.js. In this hero.js you can see
  9650. 8:14:27we have the text. So let me update this
  9651. 8:14:32text. Here we have the name. Hi, I am
  9652. 8:14:34Alex. So, let me change it. Hi, I am
  9653. 8:14:41Avin. And uh after that you can see it
  9654. 8:14:44is updating the content on our website
  9655. 8:14:48and we can see the live preview also.
  9656. 8:14:51Let's click on this open preview. So, it
  9657. 8:14:54will open a new tab and you can see the
  9658. 8:14:56full screen preview. So, right now it is
  9659. 8:14:59a private project only. You can see this
  9660. 8:15:01right and if I make it public let's
  9661. 8:15:03click on this publish and now it is a
  9662. 8:15:07public project and anyone can see this
  9663. 8:15:09project using this link. Let me open
  9664. 8:15:12this link in new tab. So this is the
  9665. 8:15:14live link and it is publish project. So
  9666. 8:15:17anyone can see this project without
  9667. 8:15:19authentication.
  9668. 8:15:20Now after that let's see the next button
  9669. 8:15:23that is export. So we can click here to
  9670. 8:15:26export this entire code. So you can see
  9671. 8:15:28we will get a zip file that contains all
  9672. 8:15:31the code files. So we have created our
  9673. 8:15:34portfolio website using the AI prompt
  9674. 8:15:37and let's come here in the chat and if
  9675. 8:15:39you want to modify anything using the AI
  9676. 8:15:42then you can enter the prompt in this
  9677. 8:15:45text area. Enter the prompt like I want
  9678. 8:15:47to update the contact I want to update
  9679. 8:15:50the footer right and it will update the
  9680. 8:15:53particular section only. So we have
  9681. 8:15:55completed our project that is AI website
  9682. 8:15:58builder. I hope this video will be
  9683. 8:16:00helpful for you. If you have any
  9684. 8:16:02question you can ask me in the comment
  9685. 8:16:04section. Please like and share this
  9686. 8:16:06video and also subscribe my channel
  9687. 8:16:08great tag to watch more videos like this
  9688. 8:16:10one. Thank you so much for watching this
  9689. 8:16:12video.

About this transcript

This page contains the full transcript of Build a Full Stack AI Website Builder with MERN Stack | Complete AI SaaS Project Step by Step by GreatStack, generated from the public captions YouTube serves with the video. The transcript has 60,068 words across 9,689 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.