Skip to content
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
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
5 changes: 3 additions & 2 deletions week4_ts/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import styled from "styled-components";
import { storeSearch } from "../libs/api";
import { flexColumnCenter } from "../mixxin";
import theme from "../styles/theme";
import { Result } from "../type/result";

interface MainHeaderProps {
handleIsSearch: (newIsSearch: boolean) => void;
handleResults: (newResults: void[]) => void;
handleResults: (newResults: Result[]) => void;
}

interface Params {
Expand All @@ -22,6 +23,7 @@ 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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘 지정한거 아니에여?!!!

const position = useRef<Coordinates>({ longitude: 0, latitude: 0 });
// 위치에 따른 가게 검색 handler
Expand Down Expand Up @@ -81,7 +83,6 @@ function Header(props: MainHeaderProps) {
storeSearchHttpHandler(params);
} else {
handleMyLocation();
console.log("position 타입은?", position);
}
}
};
Expand Down
16 changes: 11 additions & 5 deletions week4_ts/src/components/ResultSection.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import React from "react";
import { Result } from "../type/result";
import Skeleton from "./StoreArticle/Skeleton";
import StoreArticle from "./StoreArticle/StoreArticle";

function ResultSection(props) {
interface MainResultProps {
isSearch: boolean;
results: Result[];
}

function ResultSection(props: MainResultProps) {
const { isSearch, results } = props;
// 이건 대체 뭔뜻일까
if (isSearch) return new Array(10).fill(1).map((_, i) => <Skeleton key={i} />);
if (results.length === 0) return <StoreArticle placeName="여기엔 BAR가 없다..!" />;
if (results.length === 0) return <StoreArticle place_name="여기엔 BAR가 없다..!" />;

return results.map((result) => (
<StoreArticle
key={result.id}
placeUrl={result.place_url}
placeName={result.place_name}
roadAddressName={result.road_address_name}
place_url={result.place_url}
place_name={result.place_name}
road_address_name={result.road_address_name}
distance={result.distance}
phone={result.phone}
/>
Expand Down
26 changes: 14 additions & 12 deletions week4_ts/src/components/StoreArticle/StoreArticle.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from 'react';
import { StyledRoot, StoreName, StoreAddress, StorePhoneNumber } from './articleStyle';
import { Result } from "../../type/result";
import { StyledRoot, StoreName, StoreAddress, StorePhoneNumber } from "./articleStyle";

const StoreArticle = props => {
return (
<StyledRoot>
<StoreName href={props.placeUrl} target="_blank" rel="noreferrer">
{props.placeName}
</StoreName>
<StoreAddress>{props.distance ? `${props.distance} m` : props.roadAddressName}</StoreAddress>
<StorePhoneNumber>{props.phone ? props.phone : '전화번호 없음'}</StorePhoneNumber>
</StyledRoot>
);
const StoreArticle = (props: Result) => {
const { place_url, place_name, road_address_name, distance, phone } = props;

return (
<StyledRoot>
<StoreName href={place_url} target="_blank" rel="noreferrer">
{place_name}
</StoreName>
<StoreAddress>{distance ? `${distance} m` : road_address_name}</StoreAddress>
<StorePhoneNumber>{phone ? phone : "전화번호 없음"}</StorePhoneNumber>
</StyledRoot>
);
};

export default StoreArticle;
7 changes: 4 additions & 3 deletions week4_ts/src/pages/Main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import styled from "styled-components";
import { flexColumnCenter } from "../../mixxin";
import React, { useState } from "react";
import Header from "../../components/Header.js";
import Header from "../../components/Header";
import ResultSection from "../../components/ResultSection";
import { Result } from "../../type/result";

function Main() {
const [results, setResults] = useState<void[]>([]);
const [results, setResults] = useState<Result[]>([]);
const [isSearch, setIsSearch] = useState<boolean>(false);

const handleResults = (newResults: void[]) => {
const handleResults = (newResults: Result[]) => {
setResults(newResults);
};
const handleIsSearch = (newIsSearch: boolean) => {
Expand Down
8 changes: 8 additions & 0 deletions week4_ts/src/type/result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Result {
id?: number;
place_url?: string;
place_name?: string;
road_address_name?: string;
distance?: string;
phone?: string;
Comment on lines +2 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모두 옵셔널로 타입지정 해준 이유가 있을까요 ??

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러게!!!!!!!!머야머야 왜머야!!!!!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옵셔널로 안주니까 에러가 떠서 옵셔널로 줬어유!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나니요....! 왜그러지

}