aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/pages/timeline/view/TimelinePostContentView.tsx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-09-14 18:58:44 +0800
committercrupest <crupest@outlook.com>2023-09-20 18:50:08 +0800
commitbdc69c18c1986544497b6974ffe5d8e073e4be6d (patch)
tree4283f2fcc4af9b8849588e8db21e4f52d136a1e7 /FrontEnd/src/pages/timeline/view/TimelinePostContentView.tsx
parentaef14be13c3bd9e93eeea598dbfbf707ba98d448 (diff)
downloadtimeline-bdc69c18c1986544497b6974ffe5d8e073e4be6d.tar.gz
timeline-bdc69c18c1986544497b6974ffe5d8e073e4be6d.tar.bz2
timeline-bdc69c18c1986544497b6974ffe5d8e073e4be6d.zip
...
Diffstat (limited to 'FrontEnd/src/pages/timeline/view/TimelinePostContentView.tsx')
-rw-r--r--FrontEnd/src/pages/timeline/view/TimelinePostContentView.tsx37
1 files changed, 37 insertions, 0 deletions
diff --git a/FrontEnd/src/pages/timeline/view/TimelinePostContentView.tsx b/FrontEnd/src/pages/timeline/view/TimelinePostContentView.tsx
new file mode 100644
index 00000000..851a9a33
--- /dev/null
+++ b/FrontEnd/src/pages/timeline/view/TimelinePostContentView.tsx
@@ -0,0 +1,37 @@
+import ImagePostView from "./ImagePostView";
+import MarkdownPostView from "./MarkdownPostView";
+import PlainTextPostView from "./PlainTextPostView";
+
+import type { HttpTimelinePostInfo } from "~src/http/timeline";
+
+interface TimelinePostContentViewProps {
+ post?: HttpTimelinePostInfo;
+ className?: string;
+}
+
+const viewMap: Record<string, React.FC<TimelinePostContentViewProps>> = {
+ "text/plain": PlainTextPostView,
+ "text/markdown": MarkdownPostView,
+ "image/png": ImagePostView,
+ "image/jpeg": ImagePostView,
+ "image/gif": ImagePostView,
+ "image/webp": ImagePostView,
+};
+
+export default function TimelinePostContentView({
+ post,
+ className,
+}: TimelinePostContentViewProps) {
+ if (post == null) {
+ return <div />;
+ }
+
+ const type = post.dataList[0].kind;
+
+ if (type in viewMap) {
+ const View = viewMap[type];
+ return <View post={post} className={className} />;
+ }
+
+ return <div>Unknown post type.</div>;
+}