-
Notifications
You must be signed in to change notification settings - Fork 0
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 #11 from johanesPao/dev
Refaktor kueri rute /tulisan/id dan UI TulisanCard, Tulisan
- Loading branch information
Showing
14 changed files
with
220 additions
and
133 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ResponTulisanProps, TulisanProps } from "../props/Tulisan.props"; | ||
|
||
export const fetchTulisanDiterbitkan = async ( | ||
setDaftarTulisan: React.Dispatch<React.SetStateAction<TulisanProps[] | null>> | ||
) => { | ||
try { | ||
const APIEndpoint = import.meta.env.DEV ? import.meta.env.VITE_DEV_API : import.meta.env.VITE_PROD_API; | ||
const APIUrl = `${APIEndpoint}/tulisan/diterbitkan` | ||
const respon = await fetch(`${APIUrl}`, { | ||
method: 'GET' | ||
}) | ||
|
||
// return eraly jika gagal detch | ||
if (!respon.ok) { | ||
throw new Error(`Gagal fetch data dari ${APIUrl}`) | ||
} | ||
|
||
// ubah respon menjadi json dan iterasi ektraksi tulisan | ||
const data: [] = await respon.json(); | ||
let arrayTulisan: TulisanProps[] = []; | ||
if (data.length > 0) { | ||
data.map((tulisan: ResponTulisanProps) => { | ||
const dataTulisan: TulisanProps = { | ||
id: tulisan.id.id.String, | ||
judul: tulisan.judul, | ||
penulis: tulisan.penulis, | ||
kategori: tulisan.kategori, | ||
konten: tulisan.konten, | ||
dibuat: new Date(tulisan.dibuat), | ||
dimodifikasi: new Date(tulisan.dimodifikasi) | ||
}; | ||
arrayTulisan.push(dataTulisan) | ||
}); | ||
}; | ||
setDaftarTulisan(arrayTulisan); | ||
} catch (kesalahan) { | ||
console.error(kesalahan); | ||
} | ||
}; | ||
|
||
export const fetchTulisan = async ( | ||
id: string, | ||
setTulisan: React.Dispatch<React.SetStateAction<TulisanProps | null>> | ||
) => { | ||
try { | ||
const APIEndpoint = import.meta.env.DEV ? import.meta.env.VITE_DEV_API : import.meta.env.VITE_PROD_API; | ||
const APIUrl = `${APIEndpoint}/tulisan/${id}` | ||
const respon = await fetch(`${APIUrl}`, { | ||
method: 'GET' | ||
}) | ||
|
||
// return eraly jika gagal detch | ||
if (!respon.ok) { | ||
console.log(respon); | ||
throw new Error(`Gagal fetch data dari ${APIUrl}: ${respon}`) | ||
} | ||
|
||
// ubah respon menjadi json dan set tulisan | ||
const data = await respon.json(); | ||
let tulisan: TulisanProps = { | ||
id: data.id.id.String, | ||
judul: data.judul, | ||
penulis: data.penulis, | ||
kategori: data.kategori, | ||
konten: data.konten, | ||
dibuat: new Date(data.dibuat), | ||
dimodifikasi: new Date(data.dimodifikasi) | ||
}; | ||
|
||
// set stat tulisan | ||
setTulisan(tulisan); | ||
} catch (kesalahan) { | ||
console.log(kesalahan); | ||
} | ||
}; |
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,4 +1,15 @@ | ||
export interface IRepoData { | ||
namaRepo: string, | ||
dataRepo: [] | ||
} | ||
|
||
// const interface | ||
export const opsiStringDate: Intl.DateTimeFormatOptions = { | ||
year: "numeric", | ||
month: "short", | ||
day: "numeric", | ||
hour: "numeric", | ||
hourCycle: "h12", | ||
dayPeriod: "short", | ||
timeZone: "Asia/Jakarta" | ||
} |
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,24 @@ | ||
import { IconStack2 } from "@tabler/icons-react"; | ||
import { ResponKategoriProps } from "../props/Tulisan.props"; | ||
|
||
const KategoriCard = ({props}: {props:ResponKategoriProps}) => { | ||
const lihatKategori = (id: string) => { | ||
console.log(`Lihat tulisan dengan kategori id kategori:${id}`) | ||
} | ||
|
||
return ( | ||
<div | ||
className="flex flex-row gap-1 items-center italic text-sm group cursor-pointer" | ||
onClick={() => lihatKategori(props.id.id.String)} | ||
> | ||
<div> | ||
<IconStack2 color={`${props.warna}`}/> | ||
</div> | ||
<div className="text-zinc-300"> | ||
{props.deskripsi} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default KategoriCard; |
Oops, something went wrong.