Skip to content

Commit 0a667e4

Browse files
committed
feat: add minimal page to view comments
1 parent c39e57a commit 0a667e4

File tree

6 files changed

+2140
-4379
lines changed

6 files changed

+2140
-4379
lines changed

browser-extension/entrypoints/report-page/ReportPage.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Link } from "react-router";
12
import { Post } from "../shared/model/post";
23
import { getPosts as getPostsFromStorage } from "../shared/storage/posts-storage";
34
import "./ReportPage.css";
@@ -15,7 +16,7 @@ function downloadPost(post: Post) {
1516
}
1617
}
1718

18-
function ReportPageApp() {
19+
function ReportPage() {
1920
const [posts, setPosts] = useState<Post[] | undefined>(undefined);
2021
useEffect(() => {
2122
getPostsFromStorage().then((posts) => {
@@ -42,6 +43,7 @@ function ReportPageApp() {
4243

4344
<th>Nb commentaires</th>
4445
<th>Id</th>
46+
<th>View details</th>
4547
<th>Télécharger</th>
4648
</tr>
4749
</thead>
@@ -59,6 +61,9 @@ function ReportPageApp() {
5961
<td>
6062
<a href={post.url}>{post.postId}</a>
6163
</td>
64+
<td>
65+
<Link to={"/posts/" + post.postId}>View</Link>
66+
</td>
6267
<td>
6368
<button onClick={() => downloadPost(post)}>
6469
Télécharger
@@ -80,4 +85,4 @@ function ellipsis(str: string, maxLength: number = 50): string {
8085
return str.substring(0, maxLength - 1) + "…";
8186
}
8287

83-
export default ReportPageApp;
88+
export default ReportPage;
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import React from "react";
22
import ReactDOM from "react-dom/client";
3-
import ReportPageApp from "./ReportPage.tsx";
3+
import ReportPage from "./ReportPage.tsx";
44
import "../shared/main-style.css";
5+
import { HashRouter, Route, Routes } from "react-router";
6+
import PostDetailPage from "./posts/PostScrapDetails.tsx";
57

68
ReactDOM.createRoot(document.getElementById("root")!).render(
79
<React.StrictMode>
8-
<ReportPageApp />
9-
</React.StrictMode>,
10+
<HashRouter>
11+
<Routes>
12+
<Route index path="/" element={<ReportPage />} />
13+
<Route path="/posts/:postId" element={<PostDetailPage />} />
14+
</Routes>
15+
</HashRouter>
16+
</React.StrictMode>
1017
);
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { getPost } from "@/entrypoints/shared/storage/posts-storage";
2+
import { Post } from "@/entrypoints/shared/model/post";
3+
import { useParams } from "react-router";
4+
5+
function PostDetailPage() {
6+
const { postId } = useParams();
7+
const [post, setPost] = useState<Post | undefined>(undefined);
8+
useEffect(() => {
9+
getPost(postId || "").then((post) => {
10+
setPost(post);
11+
});
12+
}, [postId]);
13+
14+
return (
15+
<>
16+
<h1>BTH app - Report Page</h1>
17+
18+
<h2>Posts</h2>
19+
{!post && <div>Loading...</div>}
20+
{post && (
21+
<>
22+
<div>
23+
<div>
24+
<a href={post.author.accountHref}>{post.author.name}</a>
25+
</div>
26+
<div>{post.postId}</div>
27+
<div>{post.publishedAt}</div>
28+
<div>{post.scrapedAt}</div>
29+
<div>{post.socialNetwork}</div>
30+
<div>{post.textContent}</div>
31+
<div>{post.title}</div>
32+
<div>
33+
<a href={post.url}>{post.url}</a>
34+
</div>
35+
</div>
36+
<h2>Commentaires</h2>
37+
<table>
38+
<thead>
39+
<tr>
40+
<th>Date scraping</th>
41+
<th>Auteur</th>
42+
<th>Date publication</th>
43+
<th>Aperçu contenu/description</th>
44+
45+
<th>Nb likes</th>
46+
<th>Nb replies</th>
47+
<th>Id</th>
48+
<th>Screenshot</th>
49+
</tr>
50+
</thead>
51+
<tbody>
52+
{post.comments.map((comment, index) => (
53+
<tr key={index}>
54+
<td> {comment.scrapedAt}</td>
55+
56+
<td> {comment.author.name}</td>
57+
<td> {comment.publishedAt}</td>
58+
<td> {ellipsis(comment.textContent || "")}</td>
59+
60+
<td> {comment.nbLikes}</td>
61+
<td> {comment.replies.length}</td>
62+
63+
<td>
64+
<img
65+
src={"data:image/png;base64," + comment.screenshotData}
66+
/>
67+
</td>
68+
</tr>
69+
))}
70+
</tbody>
71+
</table>
72+
</>
73+
)}
74+
</>
75+
);
76+
}
77+
78+
function ellipsis(str: string, maxLength: number = 50): string {
79+
if (str.length <= maxLength) {
80+
return str;
81+
}
82+
return str.substring(0, maxLength - 1) + "…";
83+
}
84+
85+
export default PostDetailPage;

browser-extension/entrypoints/shared/storage/posts-storage.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ export async function getPosts(): Promise<Post[]> {
1010
const partial = await browser.storage.local.get("posts");
1111
return (partial["posts"] as Post[]) || [];
1212
}
13+
14+
export async function getPost(postId: string): Promise<Post | undefined> {
15+
const posts = await getPosts();
16+
const post = posts.find((p) => p.postId === postId);
17+
console.log("getPost", postId, post);
18+
return post;
19+
}

browser-extension/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"dependencies": {
2222
"puppeteer-core": "^24.34.0",
2323
"react": "^19.2.3",
24-
"react-dom": "^19.2.3"
24+
"react-dom": "^19.2.3",
25+
"react-router": "^7.12.0"
2526
},
2627
"devDependencies": {
2728
"@eslint/css": "^0.14.1",

0 commit comments

Comments
 (0)