Skip to content

Commit

Permalink
feature/map-logic
Browse files Browse the repository at this point in the history
먼지잡기API 추가
#15
  • Loading branch information
moana16 committed Sep 26, 2022
1 parent 4120433 commit a104bea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions apis/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const statDustAPI = axios.create({
accept: "application/json",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
// "ACCESS-TOKEN": getToken() ?? ''
"X-ACCESS-TOKEN": "eyJ0eXBlIjoiand0IiwiYWxnIjoiSFMyNTYifQ.eyJ1c2VySWQiOjE4LCJpYXQiOjE2NjQyMDMwNDUsImV4cCI6MTY2NDgwNzg0NX0.ydZ7EOtz1_MdMpmYLTJNVuLmGyQ3VXkoOaaobtrEXzU"
},
});

Expand All @@ -20,6 +20,6 @@ export async function sendDustLocation(latitude, longitude) {
return await statDustAPI.post('/dust/location', { latitude, longitude })
}

export async function postcatchedDust() {
export async function postcatchedDust(dustNum) {
return await statDustAPI.post(`/catch/dust`,{dustNum})
}
31 changes: 14 additions & 17 deletions pages/qrcode/index.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
import React, {useState, useEffect} from "react";
import { QrReader } from "react-qr-reader";
import { postcatchedDust } from "../../apis/service";
import { useRouter } from "next/router";


export default function QrcodeScanner () {
const router = useRouter();
const [data, setData] = useState('No result');
const [hasRendered, setHasRendered] = useState(false);


useEffect(() => {
setHasRendered(true)
}, [])

const postDustNum = async(dustNum) => {
const postDustNum = async(dustNum) => {
const response = await postcatchedDust(dustNum)

if(response.status==200) {
if(response.body.code == 200) {
//router.back() //map화면으로 다시 돌아가게 해줘야함 근데이게맞아?ㅋ
//

if(response.data.code == 200) {
router.replace("/../map")
}
}
}
}

const dustMapper = {
1: styles.dust_black,
2: styles.dust_white,
3: styles.dust_green,
4: styles.dust_orange,
5: styles.dust_purple,
};

return (
<>
{hasRendered && (
<QrReader
constraints={{
facingMode: 'environment'
}}
onResult={(result, error) => {
if (!!result) {
setData(result?.text);
postDustNum(Number(data));
postDustNum(Number(result.text));


}

Expand Down

0 comments on commit a104bea

Please sign in to comment.