Skip to content

Commit 62a72d6

Browse files
committed
feat : audio book working
1 parent c95fcfb commit 62a72d6

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

src/api/service/Payload.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ export class PayloadService extends ApiService {
114114
list_count: albumDetails.list_count,
115115
list_type: albumDetails.list_type,
116116
songs: albumDetails.list.map((current) => {
117+
118+
/**
119+
*
120+
* id: string
121+
title: string
122+
artist: string
123+
artwork: string
124+
url: string
125+
*/
117126
return {
118127
id: current.id,
119128
title: current.title.replaceAll(""", '"'),

src/components/audioBook/AudioBook.details.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import React, { memo } from "react"
1+
import React, { memo, useEffect } from "react"
22
import { View } from "react-native"
33
import { audioBookImageBaseUrl } from "../../api/base/constrants"
4+
import { useAppDispatch } from "../../hooks/store.hook"
45
import { Docs } from "../../screens/Home/Albums"
6+
import { audioBookDetails } from "../../store/actions/audioBookDetails.action"
57
import Header from "../DetailsScreen/Header"
68
interface AudioBookData {
79
key: string
@@ -15,6 +17,21 @@ export interface AudioBookDetailsProps {
1517
}
1618
const AudioBookDetails: React.FC<AudioBookDetailsProps> = ({ route }) => {
1719
const { audios } = route.params
20+
const dispatch = useAppDispatch()
21+
22+
const get = async () => {
23+
try {
24+
dispatch(
25+
audioBookDetails.getAudioBookDetails({ identifier: audios.identifier })
26+
)
27+
} catch (error) {
28+
console.log(error)
29+
}
30+
}
31+
32+
useEffect(() => {
33+
get()
34+
}, [])
1835
return (
1936
<View>
2037
<Header

src/screens/Home/Albums.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface AudioBookScreenInterface {
2727

2828
const Albums = () => {
2929
const audioData = TypedSelectorHook(audioBooks)
30+
console.log(audioData.data[0].audios[0])
3031
const dispatch = useAppDispatch()
3132
useEffect(() => {
3233
dispatch(getAudioBooks())
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { createAsyncThunk } from "@reduxjs/toolkit";
2+
import axios from "axios";
3+
import { PayloadService } from "../../api/service/Payload.service";
4+
type Prop = {
5+
identifier: string
6+
}
7+
interface AudioDetails {
8+
name: string;
9+
source: string;
10+
creator: string;
11+
title: string;
12+
track: string;
13+
album: string;
14+
genre: string;
15+
bitrate: string;
16+
length: string;
17+
format: string;
18+
original: string;
19+
mtime: string;
20+
size: string;
21+
md5: string;
22+
crc32: string;
23+
sha1: string;
24+
}
25+
type AudioDetailsResponse = {
26+
result: Array<AudioDetails>
27+
}
28+
class AudioBookeDetails extends PayloadService {
29+
public getAudioBookDetails = createAsyncThunk("/audioBookeDetails", async (prop: Prop, ASYNC) => {
30+
try {
31+
const response = await axios.get<AudioDetailsResponse>(`https://archive.org/metadata/${prop.identifier}/files?output=json`)
32+
const responseData = response.data.result.filter((current) => current.source == "original" && current.track != null)
33+
console.log(prop.identifier)
34+
console.log(responseData[0].name)
35+
} catch (error: any) {
36+
return ASYNC.rejectWithValue(error?.message)
37+
}
38+
})
39+
}
40+
41+
export const audioBookDetails = new AudioBookeDetails()

0 commit comments

Comments
 (0)