Skip to content

Commit f84e9f3

Browse files
committed
was implemented list component to show items searched
1 parent 2f787a4 commit f84e9f3

File tree

8 files changed

+88
-62
lines changed

8 files changed

+88
-62
lines changed

src/modules/domain/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export namespace Common{
2+
3+
export const YOUTUBE_URL = 'https://www.googleapis.com/youtube/v3/search';
4+
export const API_KEY = 'AIzaSyAvucYb8pcxTx20CHE6StwLF8iGT76K1RA';
5+
}

src/modules/domain/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './models';
33
export * from './reducers';
44
export * from './selectors';
55
export * from './services';
6+
export * from './common';
67
export * from './actions';
78
export * from './actionTypes';
89
export * from './videoSearchBar';

src/modules/domain/services.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as u from 'updeep';
2+
import axios from 'axios';
3+
import YTSearch from 'youtube-api-search';
24

35
import {
46

@@ -10,13 +12,15 @@ import {
1012
import {
1113

1214
//Models
13-
IdEntityBase
15+
IdEntityBase,
16+
Common,
17+
VideoSearchBar
1418

1519
} from './';
1620

1721
export namespace Services {
1822

19-
export class EntityMapStorageService{
23+
export class EntityMapStorageService {
2024

2125
public storeById<TEntity extends IdEntityBase>(previousEntityMap: EntityMap<TEntity>, newEntityMap: TEntity): EntityMap<TEntity> {
2226

@@ -31,9 +35,9 @@ export namespace Services {
3135
return newEntityMapState;
3236
}
3337

34-
public storeByAllIds(previousIdsList:Array<string>, idEntityBase:IdEntityBase) : Array<string>{
35-
36-
if(previousIdsList.indexOf(idEntityBase.id) == -1){
38+
public storeByAllIds(previousIdsList: Array<string>, idEntityBase: IdEntityBase): Array<string> {
39+
40+
if (previousIdsList.indexOf(idEntityBase.id) == -1) {
3741
return [...previousIdsList, idEntityBase.id];
3842
}
3943

src/modules/video-list-item/components/VideoListItem.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,49 @@ import {
44
Media
55
} from 'react-bootstrap';
66

7-
export class VideoListItem extends React.Component<undefined, undefined>{
7+
import {
8+
9+
Video
10+
11+
} from '../../domain';
12+
13+
interface OwnProps {
14+
videosList: Array<Video>;
15+
}
16+
17+
export class VideoListItem extends React.Component<OwnProps, undefined>{
818

919
render() {
1020

1121
return (
1222
<div>
13-
<Panel>
14-
<Media>
15-
<Media.Left align="top">
16-
<img width={64} height={64} src="/assets/thumbnail.png" alt="Image" />
17-
</Media.Left>
18-
<Media.Body>
19-
<Media.Heading>Top aligned media</Media.Heading>
20-
</Media.Body>
21-
</Media>
22-
</Panel>
23-
<Panel>
24-
<Media>
25-
<Media.Left align="top">
26-
<img width={64} height={64} src="/assets/thumbnail.png" alt="Image" />
27-
</Media.Left>
28-
<Media.Body>
29-
<Media.Heading>Top aligned media</Media.Heading>
30-
</Media.Body>
31-
</Media>
32-
</Panel>
33-
<Panel>
23+
{
24+
this.getContent()
25+
}
26+
</div>
27+
);
28+
}
29+
30+
private getContent() {
31+
32+
if (!this.props.videosList ||
33+
this.props.videosList.length == 0) {
34+
return <span></span>
35+
}
36+
37+
return this.props.videosList.map((video: Video, index: number) => {
38+
return (
39+
<Panel key={index}>
3440
<Media>
3541
<Media.Left align="top">
36-
<img width={64} height={64} src="/assets/thumbnail.png" alt="Image" />
42+
<img width={64} height={64} src={video.videoImgUrl} alt="Image" />
3743
</Media.Left>
3844
<Media.Body>
39-
<Media.Heading>Top aligned media</Media.Heading>
45+
<Media.Heading>{video.title}</Media.Heading>
4046
</Media.Body>
4147
</Media>
4248
</Panel>
43-
</div>
44-
);
49+
);
50+
});
4551
}
4652
}

src/modules/video-list/components/VideoList.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,40 @@ import {
33
Panel
44
} from 'react-bootstrap';
55

6+
import {
7+
8+
Video
9+
10+
} from '../../domain';
11+
612
import {
713
VideoListItem
814
} from '../../video-list-item/components/VideoListItem';
915

10-
export class VideoList extends React.Component<undefined, undefined>{
16+
export interface OwnProps {
17+
18+
}
19+
20+
export interface VideoListProps{
21+
videosList: Array<Video>;
22+
}
23+
24+
export interface VideoListDispatch{
25+
26+
}
27+
28+
export class VideoList extends React.Component<VideoListProps & VideoListDispatch & OwnProps, undefined>{
29+
30+
constructor(props: VideoListProps & VideoListDispatch & OwnProps){
31+
32+
super(props);
33+
}
1134

1235
render() {
1336

1437
return (
1538
<Panel>
16-
<VideoListItem />
39+
<VideoListItem videosList={this.props.videosList} />
1740
</Panel>
1841
);
1942
}

src/modules/video-list/containers/VideoListContainer.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,27 @@ import { connect } from 'react-redux';
55

66
import {
77

8-
AppState,
8+
AppState,
9+
Actions,
10+
Selectors
911

1012
} from '../../domain';
1113

12-
/*import {
13-
Actions
14-
} from '../actions';
15-
16-
import {
17-
Selectors
18-
} from '../selectors';*/
19-
2014
import {
15+
16+
OwnProps,
17+
VideoListProps,
18+
VideoListDispatch,
2119
VideoList
20+
2221
} from '../components/VideoList';
2322

24-
interface OwnProps {
25-
26-
}
2723

28-
interface VideoListProps{
29-
30-
}
3124

3225
const mapStateToProps = (appState: AppState): VideoListProps => ({
33-
26+
videosList: Selectors.Videos.getVideosList(appState)
3427
});
3528

36-
interface VideoListDispatch{
37-
38-
}
39-
4029
const mapDispatchToProps = (dispatch: any /*redux.Dispatch<Captions.ManageCaptionViewModel>*/): VideoListDispatch => ({
4130

4231
});

src/modules/video-search-bar/components/VideoSearchBar.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
import {
1010

1111
AppState,
12-
VideoSearchBar as VideoSearchBarModule
12+
VideoSearchBar as VideoSearchBarModule,
13+
Common
1314

1415
} from '../../domain';
1516

@@ -25,9 +26,6 @@ export interface VideoSearchBarDispatch {
2526
storeVideosResult: (videoSearchViewModel: VideoSearchBarModule.VideoSearchViewModel) => void;
2627
}
2728

28-
const YOUTUBE_URL = 'https://www.googleapis.com/youtube/v3/search';
29-
const API_KEY = 'AIzaSyAvucYb8pcxTx20CHE6StwLF8iGT76K1RA';
30-
3129
export class VideoSearchBar extends React.Component<VideoSearchBarProps & VideoSearchBarDispatch & OwnProps, undefined>{
3230

3331
private videoSearchViewModel: VideoSearchBarModule.VideoSearchViewModel;
@@ -82,22 +80,22 @@ export class VideoSearchBar extends React.Component<VideoSearchBarProps & VideoS
8280

8381
const params = {
8482
part: 'snippet',
85-
key: API_KEY,
83+
key: Common.API_KEY,
8684
q: this.videoSearchViewModel.videoSearchName,
8785
type: 'video'
8886
};
8987

90-
const request = axios.get(YOUTUBE_URL, { params: params });
88+
const request = axios.get(Common.YOUTUBE_URL, { params: params });
9189

9290
request.then((response: any) => {
9391
console.log(response.data);
9492

95-
let videoDTO = new VideoSearchBarModule.VideoDTO();
96-
9793
this.videoSearchViewModel.videoSearchDTO.searchResult = [];
9894

9995
response.data.items.map((item) => {
10096

97+
let videoDTO = new VideoSearchBarModule.VideoDTO();
98+
10199
videoDTO.id = item.id.videoId;
102100
videoDTO.title = item.snippet.title;
103101
videoDTO.imageUrl = item.snippet.thumbnails.medium.url;

src/modules/video-search-bar/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export namespace Services {
8484
let video = new Video();
8585

8686
video.id = this.nextId.toString();
87-
video.title = video.title;
87+
video.title = videoDTO.title;
8888
video.videoImgUrl = videoDTO.imageUrl;
8989
video.videoDetailId = this.nextId.toString();
9090

0 commit comments

Comments
 (0)