-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
load0ne
committed
Jun 12, 2021
1 parent
d8bd0e9
commit 6368a64
Showing
15 changed files
with
607 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import React from 'react'; | ||
import SpotNavigator from './SpotNavigator'; | ||
import * as $ from './CourseMapView'; | ||
|
||
export default function CourseMap(): JSX.Element { | ||
return null; | ||
return ( | ||
<$.CourseMap> | ||
<SpotNavigator /> | ||
</$.CourseMap> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const CourseMap = styled.div` | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
`; |
19 changes: 18 additions & 1 deletion
19
components/Course/List/CourseMap/SpotNavigator/SpotNavigator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
import React from 'react'; | ||
import SpotNavigatorItem from './SpotNavigatorItem'; | ||
import { useCurrentStickers } from '~/components/Course/List/SideBar/CourseList/CourseListState'; | ||
import * as $ from './SpotNavigatorView'; | ||
|
||
export default function SpotNavigator(): JSX.Element { | ||
return null; | ||
const stickers = useCurrentStickers(); | ||
|
||
return ( | ||
<$.SpotNavigator> | ||
<$.List> | ||
{stickers.map((sticker, i) => ( | ||
<SpotNavigatorItem | ||
key={`sn-${sticker._id}`} | ||
sticker={sticker} | ||
index={i} | ||
/> | ||
))} | ||
</$.List> | ||
</$.SpotNavigator> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
components/Course/List/CourseMap/SpotNavigator/SpotNavigatorItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { getStickerIconWithSugar } from '~/constants/sugar'; | ||
import * as $ from './SpotNavigatorView'; | ||
|
||
type Props = { | ||
index: number; | ||
sticker: GQL.Sticker; | ||
}; | ||
|
||
export default function SpotNavigatorItem(props: Props): JSX.Element { | ||
const { sticker, index } = props; | ||
const Sticker = getStickerIconWithSugar( | ||
sticker.sweet_percent, | ||
sticker.sticker_index | ||
); | ||
|
||
return ( | ||
<$.Item> | ||
<$.Navigator> | ||
<$.AreaSticker> | ||
<Sticker width={56} height={56} /> | ||
</$.AreaSticker> | ||
<$.AreaInfo> | ||
<$.Meta>{`스팟 ${index + 1}`}</$.Meta> | ||
<$.Name>{sticker.spot.place_name}</$.Name> | ||
</$.AreaInfo> | ||
</$.Navigator> | ||
</$.Item> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
components/Course/List/CourseMap/SpotNavigator/SpotNavigatorState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { makeVar, useReactiveVar } from '@apollo/client'; | ||
|
||
const currentStickersState = makeVar<GQL.Sticker[]>([]); | ||
|
||
export function useCurrentStickers(): GQL.Sticker[] { | ||
return useReactiveVar(currentStickersState); | ||
} | ||
|
||
export function updateCurrentStickrs(stickers: GQL.Sticker[]): void { | ||
currentStickersState(stickers); | ||
} |
75 changes: 75 additions & 0 deletions
75
components/Course/List/CourseMap/SpotNavigator/SpotNavigatorView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import styled from 'styled-components'; | ||
import painter from '~/styles/theme/painter'; | ||
|
||
export const SpotNavigator = styled.div` | ||
position: absolute; | ||
left: 0; | ||
bottom: 28px; | ||
width: 100%; | ||
height: 120px; | ||
padding: 8px; | ||
overflow-x: scroll; | ||
overflow-y: hidden; | ||
-ms-overflow-style: none; | ||
scrollbar-width: none; | ||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
`; | ||
|
||
export const List = styled.ul` | ||
white-space: nowrap; | ||
font-size: 0; | ||
`; | ||
|
||
export const Item = styled.li` | ||
display: inline-block; | ||
margin: 0 12px; | ||
vertical-align: top; | ||
&:first-child { | ||
margin-left: 16px; | ||
} | ||
&:last-child { | ||
margin-right: 16px; | ||
} | ||
`; | ||
|
||
export const Navigator = styled.button.attrs({ type: 'button' })` | ||
display: block; | ||
width: 344px; | ||
height: 104px; | ||
padding: 24px; | ||
border-radius: 16px; | ||
border: 1px solid ${painter.grayscale[3]}; | ||
box-shadow: 0 0 8px 1px ${painter.grayscale[3]}; | ||
background-color: #fff; | ||
cursor: pointer; | ||
&::after { | ||
content: ''; | ||
display: block; | ||
clear: both; | ||
} | ||
`; | ||
|
||
export const AreaSticker = styled.div` | ||
float: left; | ||
padding-right: 12px; | ||
`; | ||
|
||
export const AreaInfo = styled.div` | ||
overflow: hidden; | ||
text-align: left; | ||
`; | ||
|
||
export const Meta = styled.div` | ||
font-size: 18px; | ||
font-weight: 600; | ||
line-height: 24px; | ||
color: ${painter.grayscale[8]}; | ||
`; | ||
|
||
export const Name = styled.strong` | ||
display: block; | ||
font-size: 24px; | ||
line-height: 32px; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,61 @@ | ||
import { makeVar, ReactiveVar } from '@apollo/client'; | ||
import { | ||
gql, | ||
makeVar, | ||
ReactiveVar, | ||
useApolloClient, | ||
useReactiveVar, | ||
} from '@apollo/client'; | ||
import { useEffect } from 'react'; | ||
import { changeCurrentCourses } from '~/components/Course/List/SideBar/CourseList/CourseListState'; | ||
|
||
const GET_COURSES_BY_DATE = gql` | ||
query GetCoursesByDate { | ||
courses { | ||
_id | ||
title | ||
courseImage | ||
is_share | ||
stickers(populate: true) { | ||
_id | ||
is_used | ||
sticker_index | ||
sweet_percent | ||
spot(populate: true) { | ||
_id | ||
place_name | ||
x | ||
y | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
type Cursor = [number, number, number]; | ||
|
||
const now: Date = new Date(); | ||
export const cursorState: ReactiveVar<Cursor> = makeVar([ | ||
export const cursorVar: ReactiveVar<Cursor> = makeVar([ | ||
now.getFullYear(), | ||
now.getMonth() + 1, | ||
now.getDate(), | ||
]); | ||
|
||
export function useCursorState(): [Cursor, (newCursor: Cursor) => void] { | ||
const client = useApolloClient(); | ||
const cursor = useReactiveVar(cursorVar); | ||
const setCursor = (newCursor: Cursor) => { | ||
cursorVar(newCursor); | ||
}; | ||
|
||
useEffect(() => { | ||
client | ||
.query<GQL.Query.Courses.Data>({ | ||
query: GET_COURSES_BY_DATE, | ||
}) | ||
.then(({ data }) => { | ||
changeCurrentCourses(data.courses); | ||
}); | ||
}, [cursor]); | ||
|
||
return [cursor, setCursor]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 23 additions & 3 deletions
26
components/Course/List/Sidebar/CourseList/CourseListState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
import { makeVar, ReactiveVar } from '@apollo/client'; | ||
import { makeVar, ReactiveVar, useReactiveVar } from '@apollo/client'; | ||
|
||
export const courses: ReactiveVar<GQL.Course[]> = makeVar([]); | ||
export const currentCourseIndex: ReactiveVar<number> = makeVar(0); | ||
export const currentCoursesVar: ReactiveVar<GQL.Course[]> = makeVar([]); | ||
export const currentCourseIndexVar: ReactiveVar<number> = makeVar(0); | ||
|
||
export function useCurrentCourses(): GQL.Course[] { | ||
return useReactiveVar(currentCoursesVar); | ||
} | ||
|
||
export function useCurrentStickers(): GQL.Sticker[] { | ||
const courses = useReactiveVar(currentCoursesVar); | ||
const currentCourseIndex = useReactiveVar(currentCourseIndexVar); | ||
const course = courses[currentCourseIndex]; | ||
|
||
if (!course) { | ||
return []; | ||
} | ||
|
||
return course.stickers || []; | ||
} | ||
|
||
export function changeCurrentCourses(courses: GQL.Course[]): void { | ||
currentCoursesVar(courses); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.