React 실습 - Twittler SPA

김도영·2022년 5월 11일
0
post-thumbnail
post-custom-banner

App.js

import React from 'react';
import { BrowserRouter, Route, Switch, Link} from "react-router-dom";
import './App.css';

import Sidebar from './Sidebar';
import Tweets from './Pages/Tweets';
import MyPage from './Pages/MyPage';
import About from './Pages/About';


const App = () => {
  return (
    <div>
    // BrowserRouter, Switch, Route 컴포넌트 작성
      <BrowserRouter>
        <div className="App">
          <main>
            <Sidebar />
            <section className="features">
              <Switch>
                <Route exact path="/">
                  <Tweets />
                </Route>
                <Route path="/about">
                  <About />
                </Route>
                <Route path="/mypage">
                  <MyPage />
                </Route>
              </Switch>
            </section>
          </main>
        </div>
        </BrowserRouter>
    </div>
  );
};

export default App;

Sidebar.js

import React from 'react';
import { Link } from "react-router-dom";

const Sidebar = () => {
  return (
    <section className="sidebar">
    //About 메뉴 아이콘과 Mypage 메뉴 아이콘을 작성하고 Link 컴포넌트를 이용하여 경로(path)를 연결
      <Link to="/">
        <i className="far fa-comment-dots"></i>
      </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.js

import React from 'react';
import { dummyTweets } from '../static/dummyData';
import './Tweets.css';

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>
      <Footer />
    </div>
  );
};

export default Tweets;

MyPage.js

import React from "react";
import { dummyTweets } from "../static/dummyData";
import "./MyPage.css";
import Footer from "../Footer";


const MyPage = () => {
  // filter 메소드를 이용하여 username이 kimcoding인 요소만 있는 배열을 filteredTweet에 할당
  const filteredTweets = dummyTweets.filter( (tweet) => {
    return tweet.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">
//dummyTweets중 kimcoding이 작성한 트윗 메세지만 표시
        <li className="tweet" id={"1"}>
          <div className="tweet__profile">
            <img src={filteredTweets[0].picture} />
          </div>
          <div className="tweet__content">
            <div className="tweet__userInfo">
              <span className="tweet__username">{filteredTweets[0].username}</span>
              <span className="tweet__createdAt">{filteredTweets[0].createdAt}</span>
            </div>
            <div className="tweet__message">{filteredTweets[0].content}</div>
          </div>
        </li>
      </ul>
      TODO : Footer 컴포넌트를 작성합니다.
      <Footer />
    </section>
  );
};

export default MyPage;

About.js

import React from 'react';
import './About.css';
import Footer from "../Footer"

const About = (props) => {
  return (
    <section className="aboutTwittler">
      <div className="aboutTwittler__container">
        <div className="aboutTwittler__wrapper">
          <div className="aboutTwittler__detail">
            <p className="aboutTwittler__detailName">React Twittler Info</p>
          </div>
        </div>
      </div>
      <div className="aboutTwittler__content">
        <i className="fas fa-users"></i>
        <p>나만의 Twittler 소개페이지를 꾸며보세요.</p>
      </div>
      <Footer />
    </section>
  );
};

export default About;
profile
Blockchain Developer
post-custom-banner

0개의 댓글