feat: use scratchFetch

BREAKING CHANGE: servers must accept new header x-projectid
This commit is contained in:
Christopher Willis-Ford committed 2023-04-04 08:36:52 -07:00
1 parent 4564cf6be6
commit 76f869b7a2
1 file changed
+18 -2
+18 -2
View File
@@ -40,15 +40,31 @@ import cloudManagerHOC from '../lib/cloud-manager-hoc.jsx';
import GUIComponent from '../components/gui/gui.jsx';
import {setIsScratchDesktop} from '../lib/isScratchDesktop.js';
const {RequestMetadata, setMetadata, unsetMetadata} = storage.scratchFetch;
const setProjectIdMetadata = projectId => {
// If project ID is '0' or zero, it's not a real project ID. In that case, remove the project ID metadata.
// Same if it's null undefined.
if (projectId && projectId !== '0') {
setMetadata(RequestMetadata.ProjectId, projectId);
} else {
unsetMetadata(RequestMetadata.ProjectId);
}
};
class GUI extends React.Component {
componentDidMount () {
setIsScratchDesktop(this.props.isScratchDesktop);
this.props.onStorageInit(storage);
this.props.onVmInit(this.props.vm);
setProjectIdMetadata(this.props.projectId);
}
componentDidUpdate (prevProps) {
if (this.props.projectId !== prevProps.projectId && this.props.projectId !== null) {
this.props.onUpdateProjectId(this.props.projectId);
if (this.props.projectId !== prevProps.projectId) {
if (this.props.projectId !== null) {
this.props.onUpdateProjectId(this.props.projectId);
}
setProjectIdMetadata(this.props.projectId);
}
if (this.props.isShowingProject && !prevProps.isShowingProject) {
// this only notifies container when a project changes from not yet loaded to loaded