Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load project into editor when app starts + autosave #2

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e6843fb
poc: get project files and store in redux
aquino-luane Oct 3, 2024
07facdf
refactor: improve way of fetching project files
aquino-luane Oct 9, 2024
1cace5f
feat: consume user session POC
aquino-luane Oct 9, 2024
d7658bd
feat(user session): get token from mock api
aquino-luane Oct 18, 2024
edf9b2e
fix: session store
aquino-luane Oct 18, 2024
d645755
feat: return original menu-bar logic
aquino-luane Oct 18, 2024
7ecf17c
feat: consume project from mock api passing project id parameter
aquino-luane Oct 18, 2024
7528680
refactor: change place of token request to API
aquino-luane Oct 22, 2024
c55f1ca
feat: show error page when token is not returned
aquino-luane Oct 22, 2024
9061af9
feat: set hash router to show project id in the address bar
aquino-luane Oct 22, 2024
7c771fd
feat: use projectId from redux
aquino-luane Oct 28, 2024
dd99715
feat: set projectId from url
aquino-luane Oct 28, 2024
abbfbda
feat: save project to server
aquino-luane Oct 29, 2024
5f12f5c
Merge branch 'main' into poc/user-session-v2
aquino-luane Dec 25, 2024
a2f9640
feat: consume token API
aquino-luane Dec 26, 2024
6db3c5c
refactor(session.js): change default value
aquino-luane Dec 26, 2024
805ca2a
refactor(constants.js): create utils that contain constants
aquino-luane Dec 27, 2024
2e61562
refactor(extension-modal): rename variable that indicates modal has a…
aquino-luane Dec 27, 2024
b9f0cb5
feat: create custom fetch to refresh token
aquino-luane Jan 6, 2025
a26e91a
feat: redirect to login page when token refresh fails
aquino-luane Jan 6, 2025
fa952c6
feat: make api call to get token when app starts
aquino-luane Jan 6, 2025
4e67471
Merge branch 'main' into poc/load-project
aquino-luane Jan 8, 2025
2130559
feat(autosave): send request to api
aquino-luane Jan 10, 2025
9cbfde2
feat(error handling): add a link to go back to project list when ther…
aquino-luane Jan 10, 2025
4fd390b
feat: adjust code for updating projectId + add mock url
aquino-luane Jan 20, 2025
3aec069
fix: add necessary logic to make it work
aquino-luane Jan 20, 2025
2b8009b
feat: change base api url
aquino-luane Jan 21, 2025
d8923a8
feat: add token and retry logic
aquino-luane Jan 27, 2025
1201e8d
refactor: update url
aquino-luane Jan 27, 2025
6514919
resolve merge conflicts with poc/user-session-v2
aquino-luane Jan 27, 2025
e8d7917
feat: update API request passing userId param
aquino-luane Jan 27, 2025
5e8e401
feat: get token from store
aquino-luane Jan 31, 2025
ca64765
feat: get project data from api response
aquino-luane Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/lib/hash-parser-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const HashParserHOC = function (WrappedComponent) {
}
componentDidMount () {
window.addEventListener('hashchange', this.handleHashChange);
// FIXME: replace mock projectId with real one
window.addEventListener('load', () => {
window.location.hash = '/project/1'
});
this.handleHashChange();
}
componentDidUpdate (prevProps) {
Expand All @@ -37,7 +41,7 @@ const HashParserHOC = function (WrappedComponent) {
window.removeEventListener('hashchange', this.handleHashChange);
}
handleHashChange () {
const hashMatch = window.location.hash.match(/#(\d+)/);
const hashMatch = window.location.hash.match(/\/(\d+)$/);
const hashProjectId = hashMatch === null ? defaultProjectId : hashMatch[1];
this.props.setProjectId(hashProjectId.toString());
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/project-fetcher-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const ProjectFetcherHOC = function (WrappedComponent) {
};
ProjectFetcherComponent.defaultProps = {
assetHost: 'https://assets.scratch.mit.edu',
projectHost: 'https://projects.scratch.mit.edu'
projectHost: 'http://localhost:3000/ccm/scratch-api/projects'
};

const mapStateToProps = state => ({
Expand Down
20 changes: 1 addition & 19 deletions src/lib/project-saver-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
// serialized project refers to a newer asset than what
// we just finished saving).
const savedVMState = this.props.vm.toJSON();
return Promise.all(this.props.vm.assets
.filter(asset => !asset.clean)
.map(
asset => storage.store(
asset.assetType,
asset.dataFormat,
asset.data,
asset.assetId
).then(response => {
// Asset servers respond with {status: ok} for successful POSTs
if (response.status !== 'ok') {
// Errors include a `code` property, e.g. "Forbidden"
return Promise.reject(response.code);
}
asset.clean = true;
})
)
)
.then(() => this.props.onUpdateProjectData(projectId, savedVMState, requestParams))
return this.props.onUpdateProjectData(projectId, savedVMState, requestParams)
.then(response => {
this.props.onSetProjectUnchanged();
const id = response.id.toString();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/save-project-to-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function (projectId, vmState, params) {
headers: {
'Content-Type': 'application/json'
},
withCredentials: true
withCredentials: false // FIXME: check if this should be true
};
const creatingProject = projectId === null || typeof projectId === 'undefined';
const queryParams = {};
Expand Down
2 changes: 1 addition & 1 deletion src/playground/render-gui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default appTarget => {
backpackVisible
showComingSoon
backpackHost={backpackHost}
canSave={false}
canSave={true}
onClickLogo={onClickLogo}
/>,
appTarget);
Expand Down