v0.1 #1
| @ -3,6 +3,7 @@ import * as React from "react"; | |||||||
| import Quick from "./Quick"; | import Quick from "./Quick"; | ||||||
| import QuickItem from "./QuickItem"; | import QuickItem from "./QuickItem"; | ||||||
| import QuickCategory from "./QuickCategory"; | import QuickCategory from "./QuickCategory"; | ||||||
|  | import Clock from "./Clock"; | ||||||
| 
 | 
 | ||||||
| class App extends React.Component { | class App extends React.Component { | ||||||
| 	constructor(props) { | 	constructor(props) { | ||||||
| @ -12,6 +13,7 @@ class App extends React.Component { | |||||||
| 	render(): JSX.Element { | 	render(): JSX.Element { | ||||||
| 		return <div> | 		return <div> | ||||||
| 			<div className="center-wrapper"> | 			<div className="center-wrapper"> | ||||||
|  | 				<Clock/> | ||||||
| 				<Quick> | 				<Quick> | ||||||
| 					<QuickCategory name="Productivity"> | 					<QuickCategory name="Productivity"> | ||||||
| 						<QuickItem name="Nextcloud" url="#"/> | 						<QuickItem name="Nextcloud" url="#"/> | ||||||
|  | |||||||
							
								
								
									
										64
									
								
								src/components/Clock.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/components/Clock.tsx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,64 @@ | |||||||
|  | import * as React from "react"; | ||||||
|  | 
 | ||||||
|  | import "../style/clock.scss"; | ||||||
|  | 
 | ||||||
|  | interface State { | ||||||
|  | 	time: string; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class Clock extends React.Component<{}, State> { | ||||||
|  | 
 | ||||||
|  | 	private interval: NodeJS.Timeout; | ||||||
|  | 
 | ||||||
|  | 	constructor(props) { | ||||||
|  | 		super(props); | ||||||
|  | 		this.state = { | ||||||
|  | 			time: "12:00" | ||||||
|  | 		}; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	updateTime() { | ||||||
|  | 		const now = new Date(); | ||||||
|  | 		 | ||||||
|  | 		// Is there a native function for formatting time ??
 | ||||||
|  | 		this.setState({ | ||||||
|  | 			time: `${this.zeroPad(now.getHours(), 2)}:${this.zeroPad(now.getMinutes(), 2)}` | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	zeroPad(number: number, pad: number): string { | ||||||
|  | 		const length = number.toString().length; | ||||||
|  | 		if (length < pad) { | ||||||
|  | 			return "0".repeat(pad - length) + number.toString(); | ||||||
|  | 		} else { | ||||||
|  | 			return number.toString(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	startTimer() { | ||||||
|  | 		this.interval = setInterval(()=>{ | ||||||
|  | 			this.updateTime(); | ||||||
|  | 		},1000); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	componentDidMount() { | ||||||
|  | 		this.updateTime(); | ||||||
|  | 		this.startTimer(); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	componentWillUnmount(){ | ||||||
|  | 		clearInterval(this.interval); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	render(): JSX.Element { | ||||||
|  | 		return <div className="clock-component"> | ||||||
|  | 			<div className="time"> | ||||||
|  | 				{this.state.time} | ||||||
|  | 			</div> | ||||||
|  | 		</div>; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | export default Clock; | ||||||
							
								
								
									
										8
									
								
								src/style/clock.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/style/clock.scss
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | .clock-component{ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	.time{ | ||||||
|  | 		font-size: 10em; | ||||||
|  | 		text-align: center; | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -9,5 +9,5 @@ body { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .center-wrapper{ | .center-wrapper{ | ||||||
| 	margin-top: 25%; | 	margin-top: 15%; | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user