-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4주차-ts] Search BAR with TS #7
Open
henization
wants to merge
16
commits into
main
Choose a base branch
from
week4-ts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9eccd76
init: 폴더구조 세팅
henization efa9ab0
Merge branch 'main' into week4-ts
henization 144a906
chore: .env.local 파일 추가
henization 3b7e71e
init: 파일 복사
henization 81fb754
feat: styles 폴더 ts로 변환
henization fa563f5
feat: Main 페이지 타입 지정
henization 0bda0df
feat: MainHeader 타입 지정
henization ed7ea6b
feat: MainResult 타입 지정 및 Result 타입 파일 생성
henization 48dbda3
style: 주석 정리
henization 4f3a2bb
fix: style.d.ts 파일 수정
henization 57051ed
chore: interface import 하ㅣㄱ
henization f6d222f
fix: App.tsx 수정
henization a2e97b9
fix: isChoice 제네릭으로 선언
henization ee8befe
feat: h1 css 선언
henization 3a4d32c
fix: query 수정
henization a6f7a40
fix: 오타 수정
henization File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
.env.local |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.tsx"></script> | ||
</body> | ||
</html> |
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,27 @@ | ||
{ | ||
"name": "week4_ts", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@types/react-router-dom": "^5.3.3", | ||
"@types/styled-components": "^5.1.25", | ||
"axios": "^0.27.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.0.0", | ||
"react-router-dom": "^6.3.0", | ||
"styled-components": "^5.3.5", | ||
"styled-reset": "^4.4.1" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.14", | ||
"@types/react-dom": "^18.0.0", | ||
"@vitejs/plugin-react": "^1.3.0", | ||
"typescript": "^4.6.3", | ||
"vite": "^2.9.9" | ||
} | ||
} |
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,129 @@ | ||
/* http://meyerweb.com/eric/tools/css/reset/ | ||
v2.0 | 20110126 | ||
License: none (public domain) | ||
*/ | ||
|
||
html, | ||
body, | ||
div, | ||
span, | ||
applet, | ||
object, | ||
iframe, | ||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5, | ||
h6, | ||
p, | ||
blockquote, | ||
pre, | ||
a, | ||
abbr, | ||
acronym, | ||
address, | ||
big, | ||
cite, | ||
code, | ||
del, | ||
dfn, | ||
em, | ||
img, | ||
ins, | ||
kbd, | ||
q, | ||
s, | ||
samp, | ||
small, | ||
strike, | ||
strong, | ||
sub, | ||
sup, | ||
tt, | ||
var, | ||
b, | ||
u, | ||
i, | ||
center, | ||
dl, | ||
dt, | ||
dd, | ||
ol, | ||
ul, | ||
li, | ||
fieldset, | ||
form, | ||
label, | ||
legend, | ||
table, | ||
caption, | ||
tbody, | ||
tfoot, | ||
thead, | ||
tr, | ||
th, | ||
td, | ||
article, | ||
aside, | ||
canvas, | ||
details, | ||
embed, | ||
figure, | ||
figcaption, | ||
footer, | ||
header, | ||
hgroup, | ||
menu, | ||
nav, | ||
output, | ||
ruby, | ||
section, | ||
summary, | ||
time, | ||
mark, | ||
audio, | ||
video { | ||
margin: 0; | ||
padding: 0; | ||
border: 0; | ||
font-size: 100%; | ||
font: inherit; | ||
vertical-align: baseline; | ||
} | ||
/* HTML5 display-role reset for older browsers */ | ||
article, | ||
aside, | ||
details, | ||
figcaption, | ||
figure, | ||
footer, | ||
header, | ||
hgroup, | ||
menu, | ||
nav, | ||
section { | ||
display: block; | ||
} | ||
body { | ||
line-height: 1; | ||
} | ||
ol, | ||
ul { | ||
list-style: none; | ||
} | ||
blockquote, | ||
q { | ||
quotes: none; | ||
} | ||
blockquote:before, | ||
blockquote:after, | ||
q:before, | ||
q:after { | ||
content: ""; | ||
content: none; | ||
} | ||
table { | ||
border-collapse: collapse; | ||
border-spacing: 0; | ||
} |
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,15 @@ | ||
import Router from "./core/router"; | ||
import { ThemeProvider } from "styled-components"; | ||
import GlobalStyle from "./styles/globalStyle"; | ||
import theme from "./styles/theme"; | ||
|
||
export default function App() { | ||
return ( | ||
<> | ||
<ThemeProvider theme={theme}> | ||
<GlobalStyle /> | ||
<Router /> | ||
</ThemeProvider> | ||
</> | ||
); | ||
} |
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,133 @@ | ||||||
import React, { useRef, useState } from "react"; | ||||||
import styled from "styled-components"; | ||||||
import { storeSearch } from "../libs/api"; | ||||||
import theme from "../styles/theme"; | ||||||
import { Params, Result } from "../type/result"; | ||||||
|
||||||
interface MainHeaderProps { | ||||||
handleIsSearch: (newIsSearch: boolean) => void; | ||||||
handleResults: (newResults: Result[]) => void; | ||||||
} | ||||||
|
||||||
interface Coordinates { | ||||||
longitude: number; | ||||||
latitude: number; | ||||||
} | ||||||
|
||||||
function Header(props: MainHeaderProps) { | ||||||
const { handleIsSearch, handleResults } = props; | ||||||
const [isLocation, setIsLocation] = useState<boolean>(false); | ||||||
const [input, setInput] = useState<string>(""); | ||||||
//useRef의 타입을 어떻게 정의해여!?!!? | ||||||
const searchRef = useRef<HTMLInputElement>(null); | ||||||
const position = useRef<Coordinates>({ longitude: 0, latitude: 0 }); | ||||||
// 위치에 따른 가게 검색 handler | ||||||
const storeSearchHttpHandler = async (params: Params) => { | ||||||
const { data } = await storeSearch(params); | ||||||
handleIsSearch(false); | ||||||
handleResults(data.documents); | ||||||
}; | ||||||
// 위치 handler | ||||||
const handleMyLocation = () => { | ||||||
// !position.current 가 무슨뜻일까? | ||||||
// 그리고 내 위치를 켜면 내 위치가 아니라 이름에 바가 들어간게 나옴 | ||||||
if (!position.current) { | ||||||
new Promise((resolve) => { | ||||||
navigator.geolocation.getCurrentPosition((currentPosition) => { | ||||||
position.current = currentPosition.coords; | ||||||
const params = { | ||||||
y: position.current.latitude, | ||||||
x: position.current.longitude, | ||||||
radius: 1000, | ||||||
query: "바", | ||||||
}; | ||||||
storeSearchHttpHandler(params); | ||||||
}); | ||||||
}); | ||||||
} else { | ||||||
const params = { | ||||||
x: position.current.longitude, | ||||||
y: position.current.latitude, | ||||||
radius: 1000, | ||||||
query: "바", | ||||||
}; | ||||||
storeSearchHttpHandler(params); | ||||||
} | ||||||
}; | ||||||
|
||||||
// 클릭 시 검색 input 비활성화 | ||||||
const handleInputDisabled = () => { | ||||||
if (searchRef.current !== null) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
로 해도 될것같은느낌~.~ |
||||||
searchRef.current.disabled = !searchRef.current.disabled; | ||||||
setIsLocation((prev) => !prev); | ||||||
} | ||||||
}; | ||||||
// input 변화 감지 | ||||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||||||
setInput(e.target.value); | ||||||
}; | ||||||
// 검색 버튼 | ||||||
const handleSearchButton = (e: React.MouseEvent<HTMLButtonElement>) => { | ||||||
handleIsSearch(true); | ||||||
e.preventDefault(); | ||||||
if (searchRef.current) { | ||||||
if (!searchRef.current.disabled) { | ||||||
const params = { | ||||||
query: input + " " + "바", | ||||||
}; | ||||||
storeSearchHttpHandler(params); | ||||||
} else { | ||||||
handleMyLocation(); | ||||||
} | ||||||
} | ||||||
}; | ||||||
|
||||||
return ( | ||||||
<Styled.Root> | ||||||
<Styled.Title>우리 동네 BAR 🥂</Styled.Title> | ||||||
<Styled.SearchWrapper> | ||||||
<MyLocationButton isChoice={isLocation} onClick={handleInputDisabled}> | ||||||
현위치로 할래 | ||||||
</MyLocationButton> | ||||||
<SearchLabel>찾고싶은 동네는</SearchLabel> | ||||||
<SearchInput | ||||||
ref={searchRef} | ||||||
type="text" | ||||||
onChange={handleInputChange} | ||||||
value={input} | ||||||
placeholder="지역을 입력해주세요" | ||||||
/> | ||||||
<SearchButton isChoice={handleIsSearch} type="submit" onClick={handleSearchButton}> | ||||||
검색 | ||||||
</SearchButton> | ||||||
</Styled.SearchWrapper> | ||||||
</Styled.Root> | ||||||
); | ||||||
} | ||||||
|
||||||
export default Header; | ||||||
|
||||||
const Styled = { | ||||||
Root: styled.header` | ||||||
${({ theme }) => theme.flexColumnCenter}; | ||||||
`, | ||||||
Title: styled.h1` | ||||||
margin: 2rem 0; | ||||||
`, | ||||||
SearchWrapper: styled.div` | ||||||
display: flex; | ||||||
gap: 2rem; | ||||||
`, | ||||||
}; | ||||||
|
||||||
const MyLocationButton = styled.button<{ isChoice: boolean }>` | ||||||
color: ${({ isChoice }) => (isChoice ? theme.colors.skyblue : theme.colors.lightgreen)}; | ||||||
`; | ||||||
|
||||||
const SearchLabel = styled.label` | ||||||
font-size: 2rem; | ||||||
`; | ||||||
|
||||||
const SearchInput = styled.input``; | ||||||
|
||||||
const SearchButton = styled.button<{ isChoice: boolean }>``; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잘한 것 같은데,!! 관련 아티클 첨부합니당
useRef 의 3가지 정의와 사용법(링크)