Skip to content

Commit 27a6c62

Browse files
committed
refactor: remove duplication on speakerAdapter.ts
1 parent d39ddab commit 27a6c62

File tree

4 files changed

+26
-44
lines changed

4 files changed

+26
-44
lines changed
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { useQuery, UseQueryResult } from "react-query";
1+
import {useQuery, UseQueryResult} from "react-query";
22
import axios from "axios";
3-
import { IResponse, ISpeaker } from "./Speaker.types";
3+
import {ISpeaker} from "./Speaker.types";
4+
import {speakerAdapter} from "../../services/speakerAdapter";
45

56
export const useFetchSpeakers = (id?: string): UseQueryResult<ISpeaker[]> => {
67
return useQuery("api-speakers", async () => {
@@ -18,16 +19,4 @@ export const useFetchSpeakers = (id?: string): UseQueryResult<ISpeaker[]> => {
1819
return speakerAdapter(returnData);
1920
});
2021
};
21-
export const speakerAdapter = (response: IResponse[]): ISpeaker[] =>
22-
response.map((response) => ({
23-
id: response.id,
24-
fullName: response.fullName,
25-
speakerImage: response.profilePicture,
26-
tagLine: response.tagLine,
27-
bio: response.bio,
28-
sessions: response.sessions,
29-
twitterUrl: response.links.filter((link) => link.linkType === "Twitter")[0],
30-
linkedInUrl: response.links.filter(
31-
(link) => link.linkType === "LinkedIn"
32-
)[0],
33-
}));
22+
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {useQuery, UseQueryResult} from "react-query";
22
import axios from "axios";
3-
import {IResponse, ISpeaker} from "../../views/Speakers/Speaker.types";
3+
import {ISpeaker} from "../../views/Speakers/Speaker.types";
4+
import {speakerAdapter} from "../../services/speakerAdapter";
45

56
export const useFetchSpeakers = (id?: string): UseQueryResult<ISpeaker[]> => {
67
return useQuery("api-speakers", async () => {
@@ -18,16 +19,4 @@ export const useFetchSpeakers = (id?: string): UseQueryResult<ISpeaker[]> => {
1819
return speakerAdapter(returnData);
1920
});
2021
};
21-
export const speakerAdapter = (response: IResponse[]): ISpeaker[] =>
22-
response.map((response) => ({
23-
id: response.id,
24-
fullName: response.fullName,
25-
speakerImage: response.profilePicture,
26-
tagLine: response.tagLine,
27-
bio: response.bio,
28-
sessions: response.sessions,
29-
twitterUrl: response.links.filter((link) => link.linkType === "Twitter")[0],
30-
linkedInUrl: response.links.filter(
31-
(link) => link.linkType === "LinkedIn",
32-
)[0],
33-
}));
22+

src/services/speakerAdapter.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {IResponse, ISpeaker} from "../views/Speakers/Speaker.types";
2+
3+
export const speakerAdapter = (response: IResponse[]): ISpeaker[] =>
4+
response.map((response) => ({
5+
id: response.id,
6+
fullName: response.fullName,
7+
speakerImage: response.profilePicture,
8+
tagLine: response.tagLine,
9+
bio: response.bio,
10+
sessions: response.sessions,
11+
twitterUrl: response.links.filter((link) => link.linkType === "Twitter")[0],
12+
linkedInUrl: response.links.filter(
13+
(link) => link.linkType === "LinkedIn",
14+
)[0],
15+
}));
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { useQuery, UseQueryResult } from "react-query";
1+
import {useQuery, UseQueryResult} from "react-query";
22
import axios from "axios";
3-
import { IResponse, ISpeaker } from "./Speaker.types";
3+
import {ISpeaker} from "./Speaker.types";
4+
import {speakerAdapter} from "../../services/speakerAdapter";
45

56
export const useFetchSpeakers = (id?: string): UseQueryResult<ISpeaker[]> => {
67
return useQuery("api-speakers", async () => {
@@ -18,16 +19,4 @@ export const useFetchSpeakers = (id?: string): UseQueryResult<ISpeaker[]> => {
1819
return speakerAdapter(returnData);
1920
});
2021
};
21-
export const speakerAdapter = (response: IResponse[]): ISpeaker[] =>
22-
response.map((response) => ({
23-
id: response.id,
24-
fullName: response.fullName,
25-
speakerImage: response.profilePicture,
26-
tagLine: response.tagLine,
27-
bio: response.bio,
28-
sessions: response.sessions,
29-
twitterUrl: response.links.filter((link) => link.linkType === "Twitter")[0],
30-
linkedInUrl: response.links.filter(
31-
(link) => link.linkType === "LinkedIn",
32-
)[0],
33-
}));
22+

0 commit comments

Comments
 (0)