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

[Feat] Create settings route and class #48

Merged
merged 12 commits into from
Dec 18, 2019
Merged

[Feat] Create settings route and class #48

merged 12 commits into from
Dec 18, 2019

Conversation

kwajiehao
Copy link
Contributor

@kwajiehao kwajiehao commented Dec 6, 2019

Note

This PR is to be reviewed with PR#99 in the frontend.

Overview

This PR introduces the settings route and Settings class which will retrieve the relevant settings information to be rendered in the frontend. The type of settings data falls into two classes:

  • general config and colors (retrieved from _config.yml)
  • social media pages (retrieved from _data/social-media.yml)

This PR resolves issue #15

classes/Settings.js Outdated Show resolved Hide resolved
})
const { content: socialMediaResp, sha: socialMediaSha } = await socialMedia

return ({ configResp, socialMediaResp, configSha, socialMediaSha })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should dump the entire content of _config.yml and pass it to the frontend. Since some of the data in the .yml file is meant to be read only, we should just provide data that is sufficient for the frontend's settings page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to transmit only relevant fields

// update files
const newConfigContent = base64.encode(yaml.safeDump(configSettings))
const newSocialMediaContent = base64.encode(yaml.safeDump(socialMediaSettings))
await config.update(newConfigContent, configSha)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise when updating, I feel that the frontend should only send in selective fields and not the entire file content to the backend.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to receive only relevant fields

routes/settings.js Show resolved Hide resolved
This commit limits the response being sent to the frontend to the
relevant fields (title, favicon, resources_name, colors) from the
config.yml file.

It also modifies the code to receive these same fields and make
updates to the config file as opposed to rewriting it completely.

This commit also switches out the base64 library for the js-base64
library for the Settings file as we had some problems with
encoding/decoding with this library in the past
@kwajiehao kwajiehao requested a review from taufiq December 17, 2019 07:54
@kwajiehao
Copy link
Contributor Author

Made changes so that only the relevant fields are transmitted - please remember to pull from the latest feat/settings branch in the frontend

@kwajiehao kwajiehao merged commit 6fe69a9 into staging Dec 18, 2019
@kwajiehao kwajiehao deleted the feat/settings branch December 18, 2019 03:50
harishv7 pushed a commit that referenced this pull request Feb 17, 2023
* feat: add settings router to server file

* feat: add OtherType file type to File class

* feat: add GET settings route

* feat: Create a separate Settings class

* feat: Create a new POST method for settings route

* fix: defer content decoding to frontend

* refactor: remove unnecessary file type in File class

* refactor: general cleanup

* fix: retintroduce yaml package import

* refactor: rename variables for clarity

* feat: send and receive only fields that the frontend requires

This commit limits the response being sent to the frontend to the
relevant fields (title, favicon, resources_name, colors) from the
config.yml file.

It also modifies the code to receive these same fields and make
updates to the config file as opposed to rewriting it completely.

This commit also switches out the base64 library for the js-base64
library for the Settings file as we had some problems with
encoding/decoding with this library in the past

* feat: remove transmission of config sha to frontend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants