aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/pages/timeline/view/PlainTextPostView.tsx
blob: d66bf05b29f3b768c3d9d08be1102e45ced0f2fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { useEffect, useState } from "react";
import classNames from "classnames";

import {
  HttpTimelinePostInfo,
  getHttpTimelineClient,
} from "~src/http/timeline";

import { subscribePromise } from "~src/components/utilities";
import Skeleton from "~src/components/Skeleton";

import "./PlainTextPostView.css";

interface PlainTextPostViewProps {
  post?: HttpTimelinePostInfo;
  className?: string;
}

export default function PlainTextPostView({
  post,
  className,
}: PlainTextPostViewProps) {
  const [text, setText] = useState<string | null>(null);

  useEffect(() => {
    if (post) {
      return subscribePromise(
        getHttpTimelineClient().getPostDataAsString(
          post.timelineOwnerV2,
          post.timelineNameV2,
          post.id,
        ),
        setText,
      );
    }
  }, [post]);

  return (
    <div
      className={classNames("timeline-view-plain-text-container", className)}
    >
      {text == null ? (
        <Skeleton />
      ) : (
        <div className="timeline-view-plain-text">{text}</div>
      )}
    </div>
  );
}