-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
83 lines (75 loc) · 1.96 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import React, { useEffect, useState } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { useTracker } from 'meteor/react-meteor-data';
import { PositionsCollection } from '../api/PositionsCollection';
import { isAPIModule } from '../api/apiModuleCommon';
const block = {
width: 100,
height: 100,
};
const useStyles = makeStyles({
container: {
width: '100vw',
height: '100vh',
backgroundColor: 'black',
backgroundRepeat: 'no-repeat',
backgroundImage: 'url("galaxy.jpg")',
backgroundSize: 'cover',
},
content: {
width: `${block.width}px`,
height: `${block.height}px`,
position: 'relative',
transition: 'linear 0.5s',
},
});
export const App = () => {
const classes = useStyles();
const [width, useWidth] = useState(block.width);
const [height, useHeight] = useState(block.height);
const [rotate, useRotate] = useState(0);
const positions =
useTracker(() => {
return PositionsCollection.findOne();
}, []) || {};
useEffect(() => {
const element = document.getElementById('container');
useWidth(element.offsetWidth);
useHeight(element.offsetHeight);
}, [rotate]);
useEffect(() => {
const timeoutId = setTimeout(
() => useRotate(t => (t === 360 ? 0 : t + 1)),
10
);
return () => clearTimeout(timeoutId);
}, [rotate]);
return (
<div id="container" className={classes.container}>
<div
className={classes.content}
style={{
top: `${Math.min(
height - block.height - block.height * 1.5,
positions.top
)}px`,
left: `${Math.min(
width - block.width - block.height * 1.5,
positions.left
)}px`,
}}
>
<img
src={'yellow.gif'}
alt="cat"
style={{
height: block.height,
transform: `rotate(
${rotate}deg
)`,
}}
/>
</div>
</div>
);
};