Page 270 - MDP2022-3
P. 270
나. 메인 화면 코드
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { firestore } from "../firebase.js";
import { Link } from 'react-router-dom';
function Home(props) {
useEffect(()=>{
getTime();
/*개발중 주석 해제 금지 countUsers(CurrentHours,CurrentMin);*/
},[]);
var [CurrentHours, SetTime] = useState(0);
var [CurrentMin, SetMinTime] = useState(0);
var [TotalUsers, SetTotalUser] = useState(0);
var [TodayUsers, SetTodayUser] = useState(0);
function getTime(){
let today = new Date();
let hours = today.getHours();
let min = today.getMinutes();
SetTime(hours);
SetMinTime(min);
}
function updateUsers(name, num){
const coll = firestore.collection("Howmany");
coll.doc("LnAhENSX6OoTqloqOA1z").update(name,num);
}
function countUsers(hours,min){
const coll = firestore.collection("Howmany");
coll.doc("LnAhENSX6OoTqloqOA1z").get().then((doc) => {
updateUsers('Total',doc.data()['Total']+1);
if(hours===0 && min===0){
updateUsers('Today',0);
}
else{
updateUsers('Today',doc.data()['Today']+1);
}
SetTotalUser(doc.data()['Total']);
SetTodayUser(doc.data()['Today']);
});
}
return (
<MiddleSection>
<MidText>첫 취업 제대로 알고 하자 ! <br/>인마고 취업 도우미 !</MidText>
<Scrollimg/>
<ConnectedPeople>현재까지 {TotalUsers}명의 사람들이 INBTI를 이용했어요 ! <br/> Today