본문 바로가기
프로그래밍/프로젝트

React Twittler SPA

by monicada 2022. 6. 3.
728x90

npm script

  • npm run start : 실제 React Web App을 개발 모드로 브라우저에서 실행
  • npm run test : 기술 요구사항에 대한 유닛 테스트를 실행하고, 결과를 확인해 볼 수 있습니다.
  • npm run submit : 과제 제출을 위한 스크립트

react-router 라이브러리 설치하기

npm install react-router-dom@^6.3.0
  • App 루트 컴포넌트(App.js)
    • import 를 이용하여 Tweets, MyPage, About 컴포넌트를 연결합니다.
    • App 루트 컴포넌트(App.js)
      • <BrowserRouter>, <Routes>, <Route> 로 React Router 문법에 맞게 컴포넌트가 있어야 합니다.
      • 주소에 따른 페이지를 <Route> 컴포넌트를 이용하여 구분 지어 줍니다.
        • Tweets컴포넌트의 Route path는 "/"입니다.
        • About 컴포넌트의 Route path는 "/about"입니다.
        • MyPage 컴포넌트의 Route path는 "/mypage"입니다.
import React from 'react';
import './App.css';
import { BrowserRouter, Routes, Route } from "react-router-dom";
// TODO - react-router-dom을 설치 후, import 구문을 이용하여 BrowserRouter, Routes, Route 컴포넌트를 불러오세요.

import Sidebar from './Sidebar';
import Tweets from './Pages/Tweets';
// TODO - import문을 이용하여 MyPage, About 컴포넌트를 불러오세요.
import MyPage from "./Pages/MyPage";
import About from "./Pages/About";

const App = () => {
  return (
    <BrowserRouter>
      <div>
          <div className="App">
            <main>
              <Sidebar />
              <section className="features">
                <Routes>
                  <Route path="/" element={<Tweets />} />
                  <Route path="/about" element={<About />} />
                  <Route path="/mypage" element={<MyPage />} />
                </Routes>
                <Tweets />
              </section>
            </main>
          </div>
      </div>
    </BrowserRouter>
  );
};

// ! 아래 코드는 수정하지 않습니다.
export default App;
  • Sidebar 메뉴 컴포넌트(Sidebar.js)
    • Font Awesome을 활용하여 About 아이콘 <i className="far fa-question-circle"></i>을 넣어야 합니다.
    • Font Awesome을 활용하여 MyPage 아이콘 <i className="far fa-user"></i>을 넣어야 합니다.
    • Sidebar 메뉴 컴포넌트(Sidebar.js)
      • <Link> 컴포넌트의 to 속성을 사용하여 SPA 내에서 페이지 전환에 따른 URL 업데이트를 진행해야 합니다.
        • Tweets 컴포넌트의 Route path는 "/"입니다.
        • About 컴포넌트의 Route path는 "/about"입니다.
        • MyPage 컴포넌트의 Route path는 "/mypage"입니다.
import React from 'react';
// TODO - import문을 이용하여 react-router-dom 라이브러리의 Link 컴포넌트를 불러옵니다.
import { Link } from "react-router-dom";

const Sidebar = () => {
  return (
    <section className="sidebar">
      {/* TODO : About 메뉴 아이콘과 Mypage 메뉴 아이콘을 작성하고 Link 컴포넌트를 이용하여 경로(path)를 연결합니다. */}

        <Link to="/"><i className="far fa-comment-dots" /></Link>
        <Link to="/about"><i className="far fa-question-circle"></i></Link>
        <Link to="/mypage"><i className="far fa-user"></i></Link>
    </section>
  );
};

export default Sidebar;ç
  • Tweets 컴포넌트(Tweets.js)
    • import 를 이용하여 Footer 컴포넌트를 연결합니다.
    • dummyTweets의 길이만큼 트윗이 보여야 합니다
import React from 'react';
import { dummyTweets } from '../static/dummyData';
import './Tweets.css';
// ! 위 코드는 수정하지 않습니다.

// TODO - import문을 이용하여 Footer 컴포넌트를 불러오세요.
import Footer from '../Footer';

const Tweets = () => {
  return (
    <div>
      <div className="tweetForm__container">
        <div className="tweetForm__wrapper">
          <div className="tweetForm__input">
            <div className="tweetForm__inputWrapper">
              <div className="tweetForm__count" role="status">
                <span className="tweetForm__count__text">
                  {'total: ' + dummyTweets.length}
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <ul className="tweets">
        {dummyTweets.map((tweet) => {
          return (
          <li className="tweet" id={tweet.id} key={tweet.id}>
            <div className="tweet__profile">
              <img src={tweet.picture} />
            </div>
            <div className="tweet__content">
              <div className="tweet__userInfo">
                <span className="tweet__username">{tweet.username}</span>
                <span className="tweet__createdAt">{tweet.createdAt}</span>
              </div>
              <div className="tweet__message">{tweet.content}</div>
            </div>
          </li>
          )
        })}
      </ul>
      {/* TODO - Footer 컴포넌트를 작성합니다. */}
      <Footer />
    </div>
  );
};


export default Tweets;
  • MyPage 컴포넌트(MyPage.js)
    • import 를 이용하여 Footer 컴포넌트를 연결합니다.
    • kimcoding이 작성한 트윗만 보여야 합니다.
import React from "react";
import { dummyTweets } from "../static/dummyData";
import "./MyPage.css";

import Footer from '../Footer';

// ! 위 코드는 수정하지 않습니다.

// TODO - import문을 이용하여 Footer 컴포넌트를 불러옵니다.


const MyPage = () => {
  // TODO - filter 메소드를 이용하여 username이 kimcoding인 요소만 있는 배열을 filteredTweet에 할당합니다.
  const filteredTweets = dummyTweets.filter(ele => ele.username === "kimcoding");

  return (
    <section className="myInfo">
      <div className="myInfo__container">
        <div className="myInfo__wrapper">
          <div className="myInfo__profile">
            <img src={filteredTweets[0].picture} />
          </div>
          <div className="myInfo__detail">
            <p className="myInfo__detailName">
              {filteredTweets[0].username} Profile
            </p>
            <p>28 팔로워 100 팔로잉</p>
          </div>
        </div>
      </div>
      <ul className="tweets__mypage">
        {/* TODO : dummyTweets중 kimcoding 이 작성한 트윗 메세지만 있어야 합니다. */}
        {filteredTweets.map((tweet) => {
          return (
        <li className="tweet" id={tweet.id} key={tweet.id}>
          <div className="tweet__profile">
            <img src={tweet.picture} />
          </div>
          <div className="tweet__content">
            <div className="tweet__userInfo">
              <span className="tweet__username">{tweet.username}</span>
              <span className="tweet__createdAt">{tweet.createdAt}</span>
            </div>
            <div className="tweet__message">{tweet.content}</div>
          </div>
        </li>
        )
      })}
      </ul>
      {/*TODO : Footer 컴포넌트를 작성합니다.*/}
      <Footer />
    </section>
  );
};

export default MyPage;

'프로그래밍 > 프로젝트' 카테고리의 다른 글

번들링과 웹팩(web-pack)  (0) 2022.07.25
구글 클론 코딩  (0) 2022.07.24
[Backend] 인증/보안 auth-basic-cookie  (0) 2022.07.15
StatesAirline Client part1  (0) 2022.06.14
Beesbeesbees 과제(코드스테이츠)  (0) 2022.05.26

댓글