Display User Within Tweet:

name and username:

  • in /twittme-web/src/tweets/detail.js

    • ignore tweet id for a while
    • display first name, last name, username in front of their tweets ```javascript //… export function Tweet(props) { //…

    /* return (

    1. <div>
    2. <p>
    3. {tweet.id} - {tweet.content}
    4. </p>
    5. <ParentTweet tweet={tweet} />
    6. </div>
    7. <div className="btn btn-group">
    8. {actionTweet && hideActions !== true && (
    9. <React.Fragment>
    10. <ActionBtn
    11. tweet={actionTweet}
    12. didPerformAction={handlePerformAction}
    13. action={{ type: "like", display: "Likes" }}
    14. />
    15. <ActionBtn
    16. tweet={actionTweet}
    17. didPerformAction={handlePerformAction}
    18. action={{ type: "unlike", display: "Unlike" }}
    19. />
    20. <ActionBtn
    21. tweet={actionTweet}
    22. didPerformAction={handlePerformAction}
    23. action={{ type: "retweet", display: "Retweet" }}
    24. />
    25. </React.Fragment>
    26. )}
    27. {isDetail === true ? null : (
    28. <button
    29. className="btn btn-outline-primary btn-sm"
    30. onClick={handleLink}
    31. >
    32. View
    33. </button>
    34. )}
    35. </div>

    ); */ return (

    1. <div>
    2. <p>
    3. {tweet.user.first_name}{" "}
    4. {tweet.user.last_name}{" "}
    5. @{tweet.user.username}
    6. </p>
    7. <p>{tweet.content}</p>
    8. <ParentTweet tweet={tweet} />
    9. </div>
    10. <div className="btn btn-group">
    11. {actionTweet && hideActions !== true && (
    12. <React.Fragment>
    13. <ActionBtn
    14. tweet={actionTweet}
    15. didPerformAction={handlePerformAction}
    16. action={{ type: "like", display: "Likes" }}
    17. />
    18. <ActionBtn
    19. tweet={actionTweet}
    20. didPerformAction={handlePerformAction}
    21. action={{ type: "unlike", display: "Unlike" }}
    22. />
    23. <ActionBtn
    24. tweet={actionTweet}
    25. didPerformAction={handlePerformAction}
    26. action={{ type: "retweet", display: "Retweet" }}
    27. />
    28. </React.Fragment>
    29. )}
    30. {isDetail === true ? null : (
    31. <button
    32. className="btn btn-outline-primary btn-sm"
    33. onClick={handleLink}
    34. >
    35. View
    36. </button>
    37. )}
    38. </div>

    ); } ``` runserver and npm start, access http://localhost:30/
    image.png
    From left to right, we got first name, last name, username.
    (I just setup the first name and last name of root)

align the column:

  • still in the same file,

    • add “px-0” in div of buttons to align first name and buttons
    • add div “d-flex”, and “col-11”, prepare for profile
    • add a span block for a simple icon about users ```javascript export function Tweet(props) { //…

    /* return (

    1. <div>
    2. <p>
    3. {tweet.user.first_name}{" "}
    4. {tweet.user.last_name}{" "}
    5. @{tweet.user.username}
    6. </p>
    7. <p>{tweet.content}</p>
    8. <ParentTweet tweet={tweet} />
    9. </div>
    10. <div className="btn btn-group">
    11. {actionTweet && hideActions !== true && (
    12. <React.Fragment>
    13. <ActionBtn
    14. tweet={actionTweet}
    15. didPerformAction={handlePerformAction}
    16. action={{ type: "like", display: "Likes" }}
    17. />
    18. <ActionBtn
    19. tweet={actionTweet}
    20. didPerformAction={handlePerformAction}
    21. action={{ type: "unlike", display: "Unlike" }}
    22. />
    23. <ActionBtn
    24. tweet={actionTweet}
    25. didPerformAction={handlePerformAction}
    26. action={{ type: "retweet", display: "Retweet" }}
    27. />
    28. </React.Fragment>
    29. )}
    30. {isDetail === true ? null : (
    31. <button
    32. className="btn btn-outline-primary btn-sm"
    33. onClick={handleLink}
    34. >
    35. View
    36. </button>
    37. )}
    38. </div>

    ); */ return (

    1. <div className="d-flex">
    2. <div className="">
    3. <span className="mx-1 px-3 py-2 rounded-circle bg-dark text-white">
    4. {tweet.user.username[0]}
    5. </span>
    6. </div>
    7. <div className="col-11">
    8. <div>
    9. <p>
    10. {tweet.user.first_name} {tweet.user.last_name} @
    11. {tweet.user.username}
    12. </p>
    13. <p>{tweet.content}</p>
    14. <ParentTweet tweet={tweet} />
    15. </div>
    16. <div className="btn btn-group px-0">
    17. {actionTweet && hideActions !== true && (
    18. <React.Fragment>
    19. <ActionBtn
    20. tweet={actionTweet}
    21. didPerformAction={handlePerformAction}
    22. action={{ type: "like", display: "Likes" }}
    23. />
    24. <ActionBtn
    25. tweet={actionTweet}
    26. didPerformAction={handlePerformAction}
    27. action={{ type: "unlike", display: "Unlike" }}
    28. />
    29. <ActionBtn
    30. tweet={actionTweet}
    31. didPerformAction={handlePerformAction}
    32. action={{ type: "retweet", display: "Retweet" }}
    33. />
    34. </React.Fragment>
    35. )}
    36. {isDetail === true ? null : (
    37. <button
    38. className="btn btn-outline-primary btn-sm"
    39. onClick={handleLink}
    40. >
    41. View
    42. </button>
    43. )}
    44. </div>
    45. </div>
    46. </div>

    ); } ``` and the workout looks like:
    image.png

    position and separate class of “retweet”:

  • still in the same file

    • ParentTweet doesn’t need to pass 2 div and 1 p blocks, instead it need to add a isRetweet property
    • get isRetweet in Tweet
    • change where the position of “retweet” text is by adding a span ```javascript import React, { useState } from “react”;

import { ActionBtn } from “./buttons”;

export function ParentTweet(props) { const { tweet } = props; / return tweet.parent ? (

Retweet

) : null; / return tweet.parent ? ( ) : null; }

export function Tweet(props) { //const { tweet, didRetweet, hideActions } = props; const { tweet, didRetweet, hideActions, isRetweet } = props; //…

/ return (

{tweet.user.username[0]}

{tweet.user.first_name} {tweet.user.last_name} @ {tweet.user.username}

{tweet.content}

{actionTweet && hideActions !== true && ( )} {isDetail === true ? null : ( )}
); / return (
{isRetweet === true && (
Retweet{“ “}
)}
{tweet.user.username[0]}

{tweet.user.first_name} {tweet.user.last_name}@{tweet.user.username}

{tweet.content}

{actionTweet && hideActions !== true && ( )} {isDetail === true ? null : ( )}
); }

  1. and we got<br />![image.png](https://cdn.nlark.com/yuque/0/2020/png/1243266/1597094438205-c6c8781a-5a0b-4770-9903-d2b168db507a.png#align=left&display=inline&height=437&margin=%5Bobject%20Object%5D&name=image.png&originHeight=873&originWidth=713&size=31312&status=done&style=none&width=356.5)
  2. - we also can add a border in the class of retweet if it is a retweet
  3. ```javascript
  4. export function Tweet(props) {
  5. //...
  6. //const className = props.className ? props.className : "col-10 mx-auto col-md-6";
  7. let className = props.className ? props.className : 'col-10 mx-auto col-md-6'
  8. className = isRetweet === true ? `${className} p-2 border rounded` : className //add a border if it's retweet
  9. //...
  10. }

image.png

Who is the retweeter:

  • still in /twittme-web/src/tweets/detail.js
    • add property “retweeter” (retweeter={tweet.user})
    • show who is the retweeter in Tweets() ```javascript import React, { useState } from “react”;

import { ActionBtn } from “./buttons”;

export function ParentTweet(props) { const { tweet } = props; / return tweet.parent ? ( ) : null; /

return tweet.parent ? ( //new ) : null; }

export function Tweet(props) { //const { tweet, didRetweet, hideActions, isRetweet } = props; const { tweet, didRetweet, hideActions, isRetweet, retweeter } = props;

  1. //...

/ return (

{isRetweet === true && (
Retweet{“ “}
)}
{tweet.user.username[0]}

{tweet.user.first_name} {tweet.user.last_name}@{tweet.user.username}

{tweet.content}

{actionTweet && hideActions !== true && ( )} {isDetail === true ? null : ( )}
); /

return (

{isRetweet === true && (
Retweet via @{retweeter.username}
)}
{tweet.user.username[0]}

{tweet.user.first_name} {tweet.user.last_name}@{tweet.user.username}

{tweet.content}

{actionTweet && hideActions !== true && ( )} {isDetail === true ? null : ( )}
); } ```