From b8c9cde2d0c4046182c858053a23211c1932cae3 Mon Sep 17 00:00:00 2001 From: cedricd Date: Wed, 27 Apr 2022 18:34:20 +0200 Subject: [PATCH] changed git page from class component to function component because function components suck in react if its only for such a small page --- backend/app/webtop-work-space/spaces.json | 2 +- frontend/src/pages/git.js | 160 ++++++++-------------- 2 files changed, 56 insertions(+), 106 deletions(-) diff --git a/backend/app/webtop-work-space/spaces.json b/backend/app/webtop-work-space/spaces.json index 4098746..bf6ef17 100644 --- a/backend/app/webtop-work-space/spaces.json +++ b/backend/app/webtop-work-space/spaces.json @@ -1 +1 @@ -{"64e266dfae2b4f34abf0de11ec077e99": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\test_rocrate_vliz", "ro_profile": "233ec883a63a4cf8965fb7fab08fe7c5", "uuid": "64e266dfae2b4f34abf0de11ec077e99", "remote_url": "", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\64e266dfae2b4f34abf0de11ec077e99"}, "5c64534759534c869ef98422b4ac2ca8": {"storage_path": "C:/Users/cedric/Desktop/no importante\\testuicrate", "ro_profile": "233ec883a63a4cf8965fb7fab08fe7c5", "uuid": "5c64534759534c869ef98422b4ac2ca8", "remote_url": "", "workspace_path": "C:\\Users\\cedric\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\5c64534759534c869ef98422b4ac2ca8"}, "cb291365244a4720b530158493386535": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\test_osd_good_profile", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "cb291365244a4720b530158493386535", "remote_url": "https://github.com/vliz-be-opsci/test_OSD_datacrate", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\cb291365244a4720b530158493386535"}, "fc7aa54fd2274e9eaea4a997a550ffd2": {"storage_path": "C:/Users/cedric/Desktop/no importante\\test_osd_home_pc", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "fc7aa54fd2274e9eaea4a997a550ffd2", "remote_url": "https://github.com/vliz-be-opsci/test_OSD_datacrate.git", "workspace_path": "C:\\Users\\cedric\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\fc7aa54fd2274e9eaea4a997a550ffd2"}, "eab2ad566ca04102a2fe2eddee5624f0": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\OSD2014", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "eab2ad566ca04102a2fe2eddee5624f0", "remote_url": "https://github.com/ocean-sampling-day/OSD2014", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\eab2ad566ca04102a2fe2eddee5624f0"}, "48b9f7113eb6409e825d4a2541e2c925": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\OSD2018", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "48b9f7113eb6409e825d4a2541e2c925", "remote_url": "https://github.com/ocean-sampling-day/OSD2018", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\48b9f7113eb6409e825d4a2541e2c925"}, "782c733125b543019ef859a04a85d7f2": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\OSD2019", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "782c733125b543019ef859a04a85d7f2", "remote_url": "https://github.com/ocean-sampling-day/OSD2019", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\782c733125b543019ef859a04a85d7f2"}} \ No newline at end of file +{"64e266dfae2b4f34abf0de11ec077e99": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\test_rocrate_vliz", "ro_profile": "233ec883a63a4cf8965fb7fab08fe7c5", "uuid": "64e266dfae2b4f34abf0de11ec077e99", "remote_url": "", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\64e266dfae2b4f34abf0de11ec077e99"}, "5c64534759534c869ef98422b4ac2ca8": {"storage_path": "C:/Users/cedric/Desktop/no importante\\testuicrate", "ro_profile": "233ec883a63a4cf8965fb7fab08fe7c5", "uuid": "5c64534759534c869ef98422b4ac2ca8", "remote_url": "", "workspace_path": "C:\\Users\\cedric\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\5c64534759534c869ef98422b4ac2ca8"}, "cb291365244a4720b530158493386535": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\test_osd_good_profile", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "cb291365244a4720b530158493386535", "remote_url": "https://github.com/vliz-be-opsci/test_OSD_datacrate", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\cb291365244a4720b530158493386535"}, "fc7aa54fd2274e9eaea4a997a550ffd2": {"storage_path": "C:/Users/cedric/Desktop/no importante\\test_osd_home_pc", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "fc7aa54fd2274e9eaea4a997a550ffd2", "remote_url": "https://github.com/vliz-be-opsci/test_OSD_datacrate.git", "workspace_path": "C:\\Users\\cedric\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\fc7aa54fd2274e9eaea4a997a550ffd2"}, "eab2ad566ca04102a2fe2eddee5624f0": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\OSD2014", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "eab2ad566ca04102a2fe2eddee5624f0", "remote_url": "https://github.com/ocean-sampling-day/OSD2014", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\eab2ad566ca04102a2fe2eddee5624f0"}, "48b9f7113eb6409e825d4a2541e2c925": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\OSD2018", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "48b9f7113eb6409e825d4a2541e2c925", "remote_url": "https://github.com/ocean-sampling-day/OSD2018", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\48b9f7113eb6409e825d4a2541e2c925"}, "782c733125b543019ef859a04a85d7f2": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\OSD2019", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "782c733125b543019ef859a04a85d7f2", "remote_url": "https://github.com/ocean-sampling-day/OSD2019", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\782c733125b543019ef859a04a85d7f2"}, "d628dc396f3647398c23233959cac09e": {"storage_path": "C:/Users/cedric/Desktop/no importante\\osd2014home", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "d628dc396f3647398c23233959cac09e", "remote_url": "https://github.com/ocean-sampling-day/OSD2014", "workspace_path": "C:\\Users\\cedric\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\d628dc396f3647398c23233959cac09e"}} \ No newline at end of file diff --git a/frontend/src/pages/git.js b/frontend/src/pages/git.js index dc60934..8135fa7 100644 --- a/frontend/src/pages/git.js +++ b/frontend/src/pages/git.js @@ -1,123 +1,73 @@ -import React from 'react'; -import $ from 'jquery'; -import GitCommit from '../components/git_commit.js'; -import GitHistory from '../components/git_history.js'; +import React, {useState, useEffect, useRef} from 'react'; import axios from 'axios'; +import {useParams} from 'react-router-dom'; import ReactLoading from 'react-loading'; import {BASE_URL_SERVER} from '../App.js'; +import GitCommit from '../components/git_commit.js'; +import GitHistory from '../components/git_history.js'; -$(document).ready(function() { - $(".btn").click(function() { - console.log("button clicked"); - console.log("actionbutton clicked"); - $(":button").each(function(){ - $(this).removeClass("btn-success"); - $(this).addClass("btn-primary"); - }); - $(this).removeClass("btn-primary"); - $(this).addClass("btn-success"); - }); -}); - -export default class GitPage extends React.Component { - constructor(props) { - super(props); - - this.state = { - message: "commit", - Loading: false, - SpaceId: "" - } - this.updateMessage = this.updateMessage.bind(this); - this.setLoading = this.setLoading.bind(this); - this.setSpaceId = this.setSpaceId.bind(this); - } - - componentDidMount() { - const SpaceId = window.location.href.split("/spaces/")[1].split("/git")[0]; - this.setSpaceId(SpaceId); - } - - setSpaceId(id) { - this.setState({ - SpaceId: id - }) - } +function NewGitPage() { - updateMessage(message) { - this.setState({ - message: message - }); - } + //define all constants first + const [Loading, setLoading] = useState(false); + const {SpaceId} = useParams(); + const [message, setMessage] = useState("commit"); + //All the functions here - setLoading(load) { - this.setState({ - Loading: load - }); + //function that will send axios request to server to push git commit + const sendPush = () => { + console.log('pushing to git repo'); + setLoading(true); + axios.post(BASE_URL_SERVER+`apiv1/spaces/${SpaceId}/git/push`,{}) + .then(response => {this.setLoading(false);window.location.reload();}) + .catch(error => { + setLoading(false); + alert(error); + }); } - sendPush(){ - console.log('pushing to git repo'); - console.log(this.state.SpaceId); - //axios request - this.setLoading(true); - axios.post(BASE_URL_SERVER+`apiv1/spaces/${this.state.SpaceId}/git/push`,{}) - .then(response => {this.setLoading(false);window.location.reload();}) - .catch(error => { - this.setLoading(false); - alert(error); - }); + //function that will send axios request to server to pull git commit + const getPull = () => { + console.log('pulling from git repo'); + setLoading(true); + axios.post(BASE_URL_SERVER+`apiv1/spaces/${SpaceId}/git/pull`,{}) + .then(response => {this.setLoading(false);window.location.href = `/spaces/${SpaceId}/all_files`;}) + .catch(error => { + setLoading(false); + console.log(error); + alert(error); + }); } - getPull(){ - console.log('pulling from git repo'); - this.setLoading(true); - axios.post(BASE_URL_SERVER+`apiv1/spaces/${this.state.SpaceId}/git/pull`,{}) - .then(response => {this.setLoading(false);window.location.href = `/spaces/${this.state.SpaceId}/all_files`;}) - .catch(error => { - this.setLoading(false); - console.log(error); - alert(error); - }); + //component to determine whether to display the history or the commit component + const Displaygit = () => { + if(message == "commit"){ + return ; + } + if(message == "history"){ + return ; + } } - render() { - const message = this.state.message; - let todisplay; - if(message == "commit"){ - todisplay = ; - console.log(todisplay); - } - if(message == "history"){ - todisplay = ; - console.log(todisplay); - } - - if(this.state.Loading){ - return( + if(Loading){ + return(
-

View differences: -

- ) - } - - if(this.state.Loading == false){ + ) + }else{ return ( -
-
-
- - - - -
- {todisplay} -
-
- ); - } + <> + + + + +
+ + + ) } - } +} + +export default NewGitPage \ No newline at end of file