1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
import { IProps, IState } from '../interfaces/components/Sidebar.interface';
import { FaChevronLeft, FaChevronRight } from 'react-icons/fa';
import { IStream } from '../interfaces/Stream.interface';
import React, { Component } from 'react';
import Card from './Card';
import {
SidebarDropdown,
SidebarDropdownButton,
SidebarDropdownContent,
SidebarStreamContent,
SidebarStream,
SidebarStreamSection,
SidebarStreamInput,
SidebarStreamButton,
SidebarBlock
} from '../design/components/Sidebar.design';
class Sidebar extends Component<IProps, IState> {
sourceInput: any = React.createRef();
titleInput: any = React.createRef();
constructor(props: IProps) {
super(props);
this.state = {
showContent: false,
streams: []
};
}
removeStream = (toRemove: IStream) =>
this.setState({
streams: this.state.streams.filter(
(stream: IStream) => (
!(stream.source === toRemove.source
&& stream.title === toRemove.title)
)
)
});
addStream = () => {
const source = this.sourceInput.current;
const title = this.titleInput.current;
const sourceValue = source.value.trim();
const titleValue = title.value.trim();
let sourcePassed = true;
let titlePassed = true;
if (sourceValue === '') {
source.style.border = 'solid thin rgb(225, 53, 57)';
sourcePassed = false;
} else
source.style.border = 'solid thin rgb(31, 93, 117)';
if (titleValue === '') {
title.style.border = 'solid thin rgb(225, 53, 57)';
titlePassed = false;
} else
title.style.border = 'solid thin rgb(31, 93, 117)';
if (sourcePassed && titlePassed)
if (this.streamExists(sourceValue, titleValue))
alert('Stream Already Exists!')
else {
this.state.streams.push({
source: sourceValue,
title: titleValue
});
source.value = '';
title.value = '';
}
}
streamExists = (source: string, title: string) => {
for (const stream of this.state.streams)
if (stream.source === source && stream.title === title)
return true;
return false;
}
updateShowContent = () =>
this.setState({ showContent: !this.state.showContent });
render() {
const { showContent, streams } = this.state;
return (
<SidebarDropdown>
<SidebarDropdownButton onClick={this.updateShowContent}>
{showContent ? (
<FaChevronRight size=".8rem" />
) : (
<FaChevronLeft size=".8rem" />
)}
</SidebarDropdownButton>
<SidebarDropdownContent active={showContent}>
<SidebarStream>
<SidebarStreamInput
type="search"
placeholder="Flash video source..."
ref={this.sourceInput}
/>
<SidebarStreamSection>
<SidebarStreamInput
type="search"
placeholder="Stream title..."
ref={this.titleInput}
/>
<SidebarStreamButton
onClick={this.addStream}
>
Add
</SidebarStreamButton>
</SidebarStreamSection>
</SidebarStream>
{streams.length === 0 ? (
<SidebarBlock>No Streams Available</SidebarBlock>
) : (
<SidebarStreamContent>
{streams.map((stream: IStream) => (
<Card
removeStream={this.removeStream}
source={stream.source}
title={stream.title}
/>
))}
</SidebarStreamContent>
)}
</SidebarDropdownContent>
</SidebarDropdown>
);
}
}
export default Sidebar;
|