Skip to content

Commit

Permalink
Merge pull request #77 from DSM-PICK/feature/66-changeplace-connect-api
Browse files Browse the repository at this point in the history
⚡️ :: (#66) 방과후 학교 층수에 따라 교실 띄우기
  • Loading branch information
wlsdn1101 authored Jan 3, 2022
2 parents a886bd3 + 7275712 commit d9b3ef1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
41 changes: 27 additions & 14 deletions src/components/ClassList/ClassList.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import React, { useState, useEffect, useLayoutEffect } from "react";
import React, { useState, useEffect } from "react";
import { getAfterSchool, getMajorClub } from "../../utils/api/Afterschool";
import { getLocationList } from "../../utils/api/Locationlist";
import * as S from "./styles";
const floorArr = ["4층", "3층", "2층", "기타"];
interface PlaceType {
after_school_id?: number;
name: string;
teacher_name: string;
location_name: string;
floor: number;
}
const ClassList = () => {
const [afterschool, setAfterschool] = useState<number>(1);
const [floor, setFloor] = useState<number>(0);

const [place, setPlace] = useState<PlaceType[]>([
{
after_school_id: 0,
name: "",
teacher_name: "",
location_name: "",
floor: 0,
},
]);
useEffect(() => {
setFloor(0);
if (afterschool === 1) {
getAfterSchool().then((res) => console.log(res));
getAfterSchool().then((res) => setPlace(res.data));
} else if (afterschool === 2) {
getMajorClub().then((res) => console.log(res));
getMajorClub().then((res) => setPlace(res.data));
}
}, [afterschool]);
useEffect(() => {}, [floor]);

useLayoutEffect(() => {
const token = localStorage.getItem("access_token");
if (!token) {
return;
}
getLocationList(token).then((res) => console.log(res.data));
}, []);

const changeFloor = (index: number) => {
setFloor(index);
Expand All @@ -42,12 +48,19 @@ const ClassList = () => {
<S.FloorName
key={i}
onClick={() => changeFloor(i)}
select={floor === i}
select={floor !== i}
>
{floorname}
</S.FloorName>
))}
</S.Location>
<S.Location>
{place.map((pn, i) => (
<S.FloorName key={i} floor={floor !== pn.floor}>
{pn.location_name}
</S.FloorName>
))}
</S.Location>
</S.ClubLocationWrapper>
<S.BtnWrapper>
<S.BtnItem onClick={() => setAfterschool(1)} select={afterschool === 1}>
Expand Down
17 changes: 10 additions & 7 deletions src/components/ClassList/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import styled from '@emotion/styled'

interface FloorNameType {
select?:boolean;
floor?:boolean;
}
export const BtnContainer = styled.div`
width: 350px;
height: 600px;
Expand Down Expand Up @@ -39,13 +42,13 @@ export const Location = styled(ClubState)`
box-sizing: border-box;
padding: 40px 0;
border:none;
`;
export const FloorName = styled.span<{select:boolean}>`
color: ${props=>props.select ? "black" : "#767676"};
:hover{
cursor: pointer;
}
export const FloorName = styled.span<FloorNameType>`
color: ${props=>props.select ? "#767676" : "black"};
:hover{
cursor: pointer;
}
display: ${props=>props.floor ? "none" : "block"}
`
export const BtnWrapper = styled.div`
width: 80%;
Expand Down

0 comments on commit d9b3ef1

Please sign in to comment.