Skip to content

Commit

Permalink
[Task] use fetch and avatar (#41)
Browse files Browse the repository at this point in the history
* fix useFetch & transparent

* fix: remove base layout
  • Loading branch information
ranjabi authored Aug 4, 2022
1 parent 687bea3 commit 4043fe2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 29 deletions.
14 changes: 14 additions & 0 deletions src/assets/images/oskm-logo-text.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 4 additions & 9 deletions src/assets/images/oskm-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 10 additions & 12 deletions src/hooks/useFetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ const useFetch = (url: Promise<any>, page?: number) => {
});

const fetchData = React.useCallback(async () => {
try {
const data = await url;
if (data) {
setFetchedData({
data: data.results || data,
isLoading: false,
error: false,
message: '',
});
}
} catch (err: any) {
const data = await url;
if (data instanceof Error) {
setFetchedData({
data: {},
isLoading: false,
error: true,
message: err.message || 'An error occured from server',
message: data.message || 'An error occured from server',
});
} else {
setFetchedData({
data: data.results || data,
isLoading: false,
error: false,
message: '',
});
}
}, [url]);
Expand Down
6 changes: 3 additions & 3 deletions src/layout/BaseLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React from 'react';
import { AiFillHome, AiFillTag } from 'react-icons/ai';
import { FaInfo, FaTwitter, FaInstagram, FaYoutube } from 'react-icons/fa';
import Navbar from '@components/Navbar';
import Logo from '@styles/images/oskm-logo.svg';
import Logo from '@/assets/images/oskm-logo.svg';
import { Link, useNavigate } from 'react-router-dom';
import { LAYOUT_TITLE } from '@/types/constant';
import { BaseProps } from '../types/interface';
Expand Down Expand Up @@ -75,7 +75,7 @@ const BaseLayout: React.FC<BaseProps> = (props) => {
>
<Link to="/">
<Flex alignItems="center" gap="2">
<Avatar size="md" src={Logo} />
<Avatar size="md" src={Logo} bg='transparent' />
<h1 className="font-Heading m-auto pt-3px hidden md:block text-2xl">
{LAYOUT_TITLE}
</h1>
Expand Down Expand Up @@ -179,7 +179,7 @@ const BaseLayout: React.FC<BaseProps> = (props) => {
gap="2"
flexDirection={{ base: 'column', md: 'row' }}
>
<Avatar size="md" src={Logo} />
<Avatar size="md" src={Logo} bg='transparent' />
<h1 className="font-Heading pt-3px text-2xl">
{LAYOUT_TITLE}
</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/About/About.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ABOUT_US_TITLE } from '@/types/constant';
import oskmLogo from '@/assets/images/oskm-logo.svg';
import oskmLogo from '@/assets/images/oskm-logo-text.svg';
import { useToggle } from '@/hooks/useToggle';
import AboutDetail from './AboutDetail';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/About/AboutDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import oskmLogo from '@/assets/images/oskm-logo.svg';
import oskmLogo from '@/assets/images/oskm-logo-text.svg';
import { AboutProps } from '@/types/interface';

const AboutDetail: React.FC<AboutProps> = ({ toggle }) => {
Expand Down
4 changes: 1 addition & 3 deletions src/service/ghostAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const fetchAllPost = async () => {
};

export const fetchSinglePost = async (postId: string) => {
let errMessage;
let data;
try {
const detailPost: DetailPost = await GhostAPI.posts.read(
Expand All @@ -63,9 +62,8 @@ export const fetchSinglePost = async (postId: string) => {
}
return data;
} catch (err: any) {
errMessage = err.message || 'An error occured from server';
return err;
}
return errMessage;
};

export const fetchPostsFilterByTag = async (tag: string[]) => {
Expand Down

0 comments on commit 4043fe2

Please sign in to comment.