aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/pages/timeline/view/PlainTextPostView.tsx
blob: b964187da60c8fe852a3f6d5a4d62731bb09faec (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
50
import { useState } from "react";
import classNames from "classnames";

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

import Skeleton from "~src/components/Skeleton";
import { useAutoUnsubscribePromise } from "~src/components/hooks";

import "./PlainTextPostView.css";

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

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

  useAutoUnsubscribePromise(
    () => {
      if (post) {
        return 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>
  );
}