spacex's People
spacex's Issues
Pagination should re-communicate with the servers
When the data's pagination settings are changed, the UI should resend for the new data from the backend, use the limit
and offset
methods provided by the API to achieve this. This goes for both launches and missions.
Field onChange
A cleaner approach to specify fields' handlers, is to eliminate custom implementation where applicable.
Example:
Instead of
function Selection({ e, index, formData }) {
return (
<Select key={index} value={formData[e.state] || e.name} style={e.style} allowClear onChange={(value) => e.setData(value)}>
{e.contents.map((x, ind) => <Option key={ind} value={x.value}>{x.text}</Option>)}
</Select>
);
}
.
.
.
state: 'launch_year', setData: (value) => { setFormData({ launch_year: value }); }, name: 'Year', style: { width: 80, marginLeft: 20 }, contents: years.map((e) => ({ value: e, text: e })),
You can do:
function Selection({ field, form, onChange }) {
return (
<Select key={index} value={form[field.name]} style={e.style} allowClear onChange={(value) => onChange({ name, value })}>
{field.options.map((x, ind) => <Option key={ind} value={x.value}>{x.text}</Option>)}
</Select>
);
}
.
.
.
name: 'launch_year', label: 'Year', style: { width: 80, marginLeft: 20 }, contents: years.map((e) => ({ value: e, text: e })),
This way, you don't need to create a custom onChange for every input in your system
Incorrect limit calculation
File structure
General components like Loading
, ModalRow
and Selection
are not exclusive to RecentLaunches
and should be exported elsewhere.
Performance optimization
SpaceX/src/components/RecentLaunches/index.jsx
Lines 247 to 249 in 611961a
Do not map any array on rerender, memoize any mappings and update their contents only when necessary.
No hardcoding
SpaceX/src/components/RecentLaunches/index.jsx
Lines 342 to 354 in 388b2a2
SpaceX/src/components/RecentLaunches/index.jsx
Lines 424 to 483 in 388b2a2
SpaceX/src/components/RecentLaunches/index.jsx
Lines 357 to 383 in 388b2a2
In these sections, options and labels are hard coded, it's a much better practice to store the schema of your forms in one place "Like a JSON object", which will contain the labels and general options, and then use that JSON object in your components, rather than hardcoding the values into JSX.
Fix console warnings
Keep your code clean
Remove all unused variables, commented code, and unreadable comments.
Component separation
SpaceX/src/components/RecentLaunches/index.jsx
Lines 427 to 428 in 388b2a2
When a piece of code seems to be written over and over again, it's better to separate that piece of code into its own component, and then reuse that piece of code in the rest of the project.
One state for the form
SpaceX/src/components/RecentLaunches/index.jsx
Lines 109 to 117 in 388b2a2
SpaceX/src/components/RecentLaunches/index.jsx
Lines 203 to 242 in 388b2a2
All of these fields are part of the same form, changing any of the fields will result in that "Form" updating the table, create a single state for all the form fields, and a generic "handleChange" function that can be passed to any of the inputs.
Delete unused files
Remove all unused files in the repository
Project configuration
Everything similar to API URLs or code or keys should be declared only in one place in the project and then used from there. The idea is to not need to traverse the entire project if we needed to change that portion.
Graphql can be passed variables
You shouldn't use Template literals to define your graphql variables, use the documentation to correctly generate a query.
Do not abbreviate variable names
Variable names should be descriptive, and never abbreviated.
Separation of concerns
SpaceX/src/components/RecentLaunches/index.jsx
Lines 264 to 305 in 388b2a2
Every seemingly different functionality in a component (e.g. Store, API calls, Gql queries/mutations, translations, ...etc) should exist in a different location than the component.
Use a single state for relevant variables
SpaceX/src/components/RecentLaunches/index.jsx
Lines 156 to 158 in d1f1c23
Instead of having separate states for every variable, combine all the states into one pagination
state.
Use the menu component for the sidebar navigation
https://ant.design/components/menu/
Use this component for navigation.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.