-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Restructured the client codebase for maintainability and re…
…adability
- Loading branch information
1 parent
d9e5eef
commit 5ded54f
Showing
8 changed files
with
71 additions
and
54 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,11 @@ | ||
import axios from 'axios'; | ||
import { apiUrl } from "../Utils/Config"; | ||
|
||
export const fetchArticle = async (id) => { | ||
try { | ||
const response = await axios.get(`${apiUrl}${id}/`); | ||
return response.data.data; | ||
} catch (err) { | ||
console.log("Error fetching article: ", err); | ||
} | ||
}; |
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,23 @@ | ||
import { backendBaseUrl } from "../Utils/Config"; | ||
|
||
// clean up unwanted HTML tags | ||
export const cleanContent = (content) => { | ||
return ( | ||
content | ||
?.replace(/<p> <\/p>/g, "") | ||
.replace(/src="\/media\//g, `src="${backendBaseUrl}/media/`) || "" | ||
); | ||
}; | ||
|
||
// get thumb URL or default image | ||
export const getThumbUrl = (thumb) => { | ||
return thumb ? `${thumb}` : "/static/images/cards/contemplative-reptile.jpg"; | ||
}; | ||
|
||
// format article data | ||
export const formatArticleData = (data) => { | ||
const updatedContent = cleanContent(data.content); | ||
const updatedThumb = getThumbUrl(data.thumb); | ||
|
||
return { ...data, content: updatedContent, thumb: updatedThumb }; | ||
}; |
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,11 @@ | ||
import axios from 'axios'; | ||
import { apiUrl } from "../Utils/Config"; | ||
|
||
export const fetchArticles = async () => { | ||
try { | ||
const response = await axios.get(`${apiUrl}`); | ||
return response.data; | ||
} catch (err) { | ||
console.log("Error fetching articles: ", err); | ||
} | ||
}; |
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,2 @@ | ||
export const backendBaseUrl = "http://127.0.0.1:8000"; | ||
export const apiUrl = `${backendBaseUrl}/api/articles/`; |
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