Skip to content

Commit

Permalink
Displying response data into frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
moovendhan-v committed Mar 17, 2024
1 parent 32024ca commit ede68e7
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 9 deletions.
19 changes: 17 additions & 2 deletions backend/controller/components.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,23 @@ const getComponentsBySearch = (req,res)=>{
//Bring a particular components
const getParticularComponent = async (req,res)=>{
const {comp} = req.query;
componentDetails = await UserComponents.findOne({ folder_name: comp });
res.send(componentDetails);
try {
const data = await UserComponents.findOne({ folder_name: comp });
if(!data){
return res.send(jsonStatusError({ errorStatus : true, statusCode : "", message : 'Components not available', response : null, count : 0 }));
}
const user = await GitHubUser.findOne({ user_id: data.user_id.$oid });
if(!user){
return res.send(jsonStatusError({ errorStatus : true, statusCode : "", message : 'Fails in fetching components details Please contact admin Please visit contactus page for more details', response : null, count : 0 }));
}
const response = await readFilesInformations(data.categories, data.folder_name,{data, user}, (err, result) => {
err ? res.send(err):res.send(result);
});
} catch (error) {
res.send(error)
}


}

module.exports = {
Expand Down
19 changes: 19 additions & 0 deletions backend/copy.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# //github secrets
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

#jtw secrets
JWT_ACCESS_TOKEN =
REFRESH_TOKEN =

#Mongodb
MONGODB_CONNECTION_STRING=mongodb://172.28.0.2:27017/github_user

# //discord
DISCORD_ALERT =
DISCORD_MESSAGE =
DISCORD_APPROVAL =

#development
ACCESS_TOKEN =""
2 changes: 1 addition & 1 deletion backend/operations/errorhandlingOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function jsonStatusError({ errorStatus = true, statusCode = "", message = '', re
// #TODO https://discordjs.guide/popular-topics/embeds.html#using-the-embed-constructor update discord messge style with this docs
// Send the embed message via the provided function

sendDiscordWebhookMessage(message, "alert");
// sendDiscordWebhookMessage(message, "alert");

return data;
}
Expand Down
4 changes: 4 additions & 0 deletions ui/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Componenets from './screens/Components';
import Editor from './screens/Editor';
import Profile from './screens/Profile';
import ContributeNewComp from './screens/ContributeNew';
import ViewComponent from './screens/ViewComponent';


function App() {
Expand Down Expand Up @@ -42,6 +43,9 @@ function App() {
{/* component routeing end */}
<Route path="/edit" element={<Editor />} />
<Route path="/profile" element={<Profile />} />
{/* Dynamic routing for viewing a ciomponent details */}
<Route path="/view" element={<ViewComponent />} />

</Routes>
</Router>
</div>
Expand Down
8 changes: 4 additions & 4 deletions ui/src/components/CodeEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ const OutputScreen = ({ html, css, js }) => {
);
};

const WebEditor = () => {
const WebEditor = (props) => {

const [html, setHtml] = useState(`<div> we-lcome to agricreations</div>`);
const [css, setCss] = useState('div { color: blue; }');
const [js, setJs] = useState('console.log("Hello, CodePen Clone!");');
const [html, setHtml] = useState(props.html);
const [css, setCss] = useState(props.css);
const [js, setJs] = useState(props.js);

const handleHtmlChange = (newValue) => {
setHtml(newValue);
Expand Down
8 changes: 6 additions & 2 deletions ui/src/screens/ContributeNew.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ const ContributeNewComp = ()=>{
return(
<>
<Nav />
<CodeEditor />
<Footer />
<CodeEditor
html = {"testing"}
css = {"css"}
js = {"js"}
/>
<Footer />
</>
)
}
Expand Down
51 changes: 51 additions & 0 deletions ui/src/screens/ViewComponent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

import { useEffect, useState } from 'react';
import CodeEditor from '../components/CodeEditor';
import Nav from '../components/Nav';
import Footer from '../components/Footer';


const ViewComponent = ()=>{

const [componentDetails, setComponentDetails] = useState({});

async function fetchComponentDetails(){
try {
const response = await fetch('http://localhost:4000/components/view?comp=moovendhan_amazing_tooltip4');
if(!response.ok){
throw new Error("Error Fetching data");
}
const data = await response.json();
console.log(data);
setComponentDetails(data.post_details);
return data;
} catch (error) {
console.error(`Error Fetching Data ${error}`)
}
}

// alert(JSON.stringify(componentDetails.html));

useEffect(()=>{
fetchComponentDetails();
},[])

return(
<>
<Nav />

{/* //Validating and send props to components if data fetched */}
{Object.keys(componentDetails).length > 0 && (
<CodeEditor
html={componentDetails.html}
css={componentDetails.css}
js={componentDetails.js}
/>
)}
<Footer />

</>
)
}

export default ViewComponent;

0 comments on commit ede68e7

Please sign in to comment.