-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: minor UI patch + NEWS api integration
- Loading branch information
1 parent
2208f84
commit bf4840e
Showing
17 changed files
with
1,966 additions
and
862 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useEffect, useState } from "react"; | ||
import apiClient from "../libs/api.client"; | ||
|
||
const News = () => { | ||
const [news, setNews] = useState([]); | ||
|
||
useEffect(() => { | ||
apiClient.get("/news", { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${localStorage.getItem("token")}`, | ||
} | ||
}).then((response) => { | ||
setNews(response.data.message); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<div className='news'> | ||
{news.map((item) => ( | ||
<div className='news-item'> | ||
<h3> | ||
message : { | ||
item.msg | ||
} | ||
</h3> | ||
<p> | ||
posted_at : { | ||
(new Date(item.created_at)).toUTCString() | ||
} | ||
</p> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default News |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
|
||
import Navbar from "../components/navbar"; | ||
import News from "../components/news"; | ||
|
||
function News() { | ||
function NewsHome() { | ||
return ( | ||
<> | ||
<Navbar pageTitle={"News"} /> | ||
<News /> | ||
</> | ||
); | ||
} | ||
|
||
export default News; | ||
export default NewsHome; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Context } from "hono"; | ||
|
||
import { NewsService } from "../services/news.service"; | ||
|
||
export class NewsController extends NewsService { | ||
public getNews = async (ctx: Context) => { | ||
try { | ||
const data = await this.getNewsS(); | ||
return ctx.json({ | ||
status: 200, | ||
message: data | ||
}); | ||
} | ||
catch (error: any) { | ||
return ctx.json({ | ||
status: 500, | ||
message: error.message | ||
}, 500); | ||
} | ||
}; | ||
|
||
public addNews = async (ctx: Context) => { | ||
try { | ||
const { msg } = await ctx.req.json(); | ||
if (!msg) { | ||
return ctx.json({ | ||
status: 400, | ||
message: "No message provided" | ||
}, 400); | ||
} | ||
const data = await this.addNewsS(msg); | ||
return ctx.json({ | ||
status: 201, | ||
message: data | ||
}, 201); | ||
} | ||
catch (error: any) { | ||
return ctx.json({ | ||
status: 500, | ||
message: error.message | ||
}, 500); | ||
} | ||
}; | ||
} |
Oops, something went wrong.