-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #322 from ashik-75/work
Add tabs in newsfeed and update colopicker
- Loading branch information
Showing
21 changed files
with
288 additions
and
41 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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ interface NewsType { | |
title: string; | ||
content: string; | ||
url: string; | ||
image?: string; | ||
} | ||
|
||
export type { NewsType }; |
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
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
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,39 @@ | ||
import { TabsProps } from "antd"; | ||
|
||
const SITE_OPTIONS = { | ||
"frontend-focus": { | ||
label: "Frontend Focus", | ||
value: "https://cprss.s3.amazonaws.com/frontendfoc.us.xml", | ||
}, | ||
"status-code": { | ||
label: "Status Code", | ||
value: "https://cprss.s3.amazonaws.com/react.statuscode.com.xml", | ||
}, | ||
news: { | ||
label: "News", | ||
value: "https://raw.githubusercontent.com/lifeparticle/binarytree/main/api/news.json", | ||
}, | ||
}; | ||
|
||
const TAB_ITEMS: TabsProps["items"] = [ | ||
{ | ||
key: SITE_OPTIONS["frontend-focus"].value, | ||
label: SITE_OPTIONS["frontend-focus"].label, | ||
show: true, | ||
}, | ||
{ | ||
key: SITE_OPTIONS["status-code"].value, | ||
label: SITE_OPTIONS["status-code"].label, | ||
show: true, | ||
}, | ||
{ | ||
key: SITE_OPTIONS["news"].value, | ||
label: SITE_OPTIONS["news"].label, | ||
show: true, | ||
}, | ||
].filter((item) => item.show); | ||
const CORS_PROXY_URL = "https://cors-anywhere.herokuapp.com/"; | ||
|
||
const QUERY_KEY_NEWS = "news"; | ||
|
||
export { SITE_OPTIONS, TAB_ITEMS, CORS_PROXY_URL, QUERY_KEY_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function parseXML(value: string) { | ||
const parser = new DOMParser(); | ||
const xmldoc = parser.parseFromString(value, "text/xml"); | ||
|
||
const items = xmldoc.getElementsByTagName("item"); | ||
const list = []; | ||
|
||
for (let i = 0; i < items.length; i++) { | ||
const item = items[i]; | ||
|
||
// Extract data from the 'item' element | ||
const title = item.getElementsByTagName("title")[0].textContent; | ||
const description = parser.parseFromString( | ||
item.getElementsByTagName("description")[0].textContent!, | ||
"text/html" | ||
); | ||
const image = description?.getElementsByTagName("img")?.[0]?.src; | ||
const pubDate = item.getElementsByTagName("pubDate")[0].textContent; | ||
const url = item.getElementsByTagName("link")[0].textContent; | ||
|
||
list.push({ title, pubDate, url, image }); | ||
} | ||
|
||
return list; | ||
} | ||
|
||
export { parseXML }; |
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,21 @@ | ||
import { useState } from "react"; | ||
import { parseXML } from "./helper"; | ||
import { CORS_PROXY_URL, SITE_OPTIONS } from "./constants"; | ||
import useFetchList from "lib/utils/hooks/useFetchList"; | ||
|
||
const useNewsFeed = () => { | ||
const [url, setUrl] = useState(SITE_OPTIONS["frontend-focus"].value); | ||
const isFeedUrl = url.includes(".xml"); | ||
|
||
const { data, isLoading, isError } = useFetchList( | ||
url, | ||
isFeedUrl && import.meta.env.DEV ? CORS_PROXY_URL + url : url | ||
); | ||
let items = undefined; | ||
if (data) { | ||
items = isFeedUrl ? parseXML(data) : data.articles; | ||
} | ||
return { data: items, isLoading, isError, setUrl }; | ||
}; | ||
|
||
export default useNewsFeed; |
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
Oops, something went wrong.