{"version":3,"file":"suggestion-STEjPiDy.js","sources":["../../../app/javascript/components/types/Suggestion.jsx","../../../app/javascript/entrypoints/suggestion.jsx"],"sourcesContent":["import { useState } from \"react\";\n\nimport classNames from \"classnames\";\nimport cn from \"./Feedback.module.css\";\n\nfunction Suggestion() {\n const [hasSubmitted, setSubmitted] = useState(false);\n const [isLoading, setLoading] = useState(false);\n const [comment, setComment] = useState(null);\n const [url, setURL] = useState(null);\n const kind = window.CSSMasterClass.suggestionKind;\n\n const INFO = {\n screencast: {\n placeholder: \"Write about what you'd like me to teach you\",\n more: \"You can also link to a website for more information\",\n },\n project: {\n placeholder: \"Write about what kind of project you'd like me to build\",\n more: \"You can also link to a website you'd like me to reproduce\",\n },\n };\n\n const handleCommentChange = (event) => {\n setComment(event.target.value);\n };\n\n const handleURLChange = (event) => {\n setURL(event.target.value);\n };\n\n const handleSubmit = async () => {\n if (hasSubmitted) {\n return;\n }\n\n setLoading(true);\n const csrfToken = document.querySelector(\"meta[name='csrf-token']\");\n\n if (!csrfToken) {\n throw new Error(\"No token available.\");\n }\n\n const options = {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-CSRF-Token\": csrfToken.content,\n },\n credentials: \"include\", // Include cookies in the request,\n body: JSON.stringify({\n kind,\n comment,\n url,\n }),\n };\n\n try {\n const response = await fetch(`/api/suggestion`, options);\n\n if (!response.ok) {\n throw new Error(\"Network response was not ok\");\n }\n\n setSubmitted(true);\n } catch (error) {\n console.error(\"Error fetching data: \" + error.message);\n } finally {\n setLoading(false);\n }\n };\n\n const componentCN = classNames({\n [cn.component]: true,\n [cn.suggestion]: true,\n [cn[\"submitted\"]]: hasSubmitted,\n });\n\n return (\n
\n What {kind} would you like to suggest?\n
\n\n \n\n {INFO[kind].more}\n\n \n\n