Skip to content

Commit

Permalink
List with article titles is visible in aside for both users and non-u…
Browse files Browse the repository at this point in the history
…sers
  • Loading branch information
Gilajoanna committed May 5, 2022
1 parent da7c571 commit 9118313
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
15 changes: 13 additions & 2 deletions client/application.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { useContext } from "react";
import { BrowserRouter, Link, Route, Routes } from "react-router-dom";
import { Articles, ListArticles } from "./articles";
import { Articles, AsideArticleList, ListArticles } from "./articles";

import "./style.css";
import { useLoader } from "./globals/useLoader";
Expand Down Expand Up @@ -58,6 +58,17 @@ function HomePage({ user }) {
);
}

function NonUser() {
async function listAllArticles() {
return await fetchJSON("/api/articles");
}
return (
<article>
<AsideArticleList listAllArticles={listAllArticles} />
</article>
);
}

export function Application() {
const { fetchLogin } = useContext(AppContext);
const { loading, error, data, reload } = useLoader(fetchLogin);
Expand All @@ -74,7 +85,7 @@ export function Application() {
<h1>Express Yourself</h1>
</header>
<aside>
<h2>Non users</h2>
<NonUser />
</aside>
<nav>
<UserNavigation user={data?.user} />
Expand Down
34 changes: 34 additions & 0 deletions client/articles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,40 @@ export function ListArticles({ listAllArticles }) {
);
}

export function AsideArticleItem({ article: { title } }) {
return (
<div>
<h2>{title}</h2>
</div>
);
}

export function AsideArticleList({ listAllArticles }) {
const { loading, data, error } = useLoader(listAllArticles);

if (loading) {
return <div>Please wait..</div>;
}

if (error) {
return (
<div>
<h1>An error occurred</h1>
<div id="error-message">Something went wrong. Please try again.</div>
</div>
);
}
return (
<div>
<h1>List of articles</h1>

{data.map((article) => (
<AsideArticleItem key={article.title} article={article} />
))}
</div>
);
}

export function Articles() {
async function listAllArticles() {
return await fetchJSON("/api/articles");
Expand Down

2 comments on commit 9118313

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for client

St.
Category Percentage Covered / Total
🔴 Statements 30.91% 34/110
🔴 Branches 10.53% 4/38
🔴 Functions 26.32% 10/38
🔴 Lines 30.91% 34/110

Test suite run success

5 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from 9118313

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for server

St.
Category Percentage Covered / Total
🔴 Statements 26.32% 10/38
🔴 Branches 0% 0/4
🔴 Functions 36.36% 4/11
🔴 Lines 26.32% 10/38

Test suite run success

2 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 9118313

Please sign in to comment.