Skip to content

Spootify #66

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ node_modules

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand Down
27,693 changes: 27,693 additions & 0 deletions rocket-ship/package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions rocket-ship/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"name": "rocket-ship",
"version": "1.0.0",
"engines": {
"node" : ">= 15.0.0"
"node": ">= 15.0.0"
},
"dependencies": {
"sass": "^1.43.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3"
"react-scripts": "^5.0.1",
"sass": "^1.43.4",
"shallow-equal": "^1.2.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down
10 changes: 6 additions & 4 deletions rocket-ship/src/routes/LaunchPad/components/LaunchPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import '../styles/_launchpad.scss';

export default function LaunchPad() {
const [, triggerRerender] = useState(Date.now());

useEffect(() => {
setInterval(() => { triggerRerender(Date.now()); }, 500);
}, [])

setInterval(() => {
triggerRerender(Date.now());
}, 500);
}, []);

return (
<div className="launchpad">
<FunctionalRocket />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import React, { useState, Component } from 'react';
import React, { useState, Component, memo } from 'react';
import { shallowEqualObjects as _isEqual } from 'shallow-equal';
import RocketCore from './RocketCore';

export function FunctionalRocket() {
export const FunctionalRocket = memo(() => {
const [initialLaunchTime] = useState(Date.now());

return <RocketCore initialLaunchTime={initialLaunchTime} />;
}
});

export class ClassRocket extends Component {
constructor(props) {
super(props);

this.state = {
initialLaunchTime: Date.now()
initialLaunchTime: Date.now(),
};
}

shouldComponentUpdate(nextProps) {
return !_isEqual(nextProps, this.props);
}

render() {
const { initialLaunchTime } = this.state;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,34 @@ function timeToPositionPercent(startTime) {
const now = Date.now();
const timeDiff = now - startTime;

if (timeDiff >= MS_TO_TAKEOFF) { return FINAL_POSITION_BOTTOM_VAL; }
if (timeDiff >= MS_TO_TAKEOFF) {
return FINAL_POSITION_BOTTOM_VAL;
}

return `calc(300px + ${((timeDiff / MS_TO_TAKEOFF) * 100).toFixed(0)}%)`;
}

function generateEmptyListEls(quantity) {
return [...Array(quantity)].map(() => <li />);
return [...Array(quantity)].map((_, idx) => <li key={idx} />);
}

export default function RocketCore({ initialLaunchTime }) {
return (
<>
<div className="rocket" style={{ bottom: timeToPositionPercent(initialLaunchTime) }}>
<div
className="rocket"
style={{ bottom: timeToPositionPercent(initialLaunchTime) }}
>
<div className="rocket__body">
<div className="rocket__body__main"/>
<div className="rocket__body__fin rocket__body__fin__left"/>
<div className="rocket__body__fin rocket__body__fin__right"/>
<div className="rocket__body__window"/>
<div className="rocket__body__main" />
<div className="rocket__body__fin rocket__body__fin__left" />
<div className="rocket__body__fin rocket__body__fin__right" />
<div className="rocket__body__window" />
</div>
<div className="rocket__exhaust__flame"/>
<ul className="rocket__exhaust__fumes">
{generateEmptyListEls(9)}
</ul>
<div className="rocket__exhaust__flame" />
<ul className="rocket__exhaust__fumes">{generateEmptyListEls(9)}</ul>
</div>
<ul className="stars">
{generateEmptyListEls(7)}
</ul>
<ul className="stars">{generateEmptyListEls(7)}</ul>
</>
);
}
Loading