PluginProbe ʕ •ᴥ•ʔ
Presto Player / 1.8.2
Presto Player v1.8.2
4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / src / admin / analytics / pages / Video.js
presto-player / src / admin / analytics / pages Last commit date
AnalyticsUpgrade.js 5 years ago Dashboard.js 4 years ago User.js 5 years ago Video.js 4 years ago illustration.js 5 years ago
Video.js
225 lines
1 const { __ } = wp.i18n;
2
3 const {
4 Flex,
5 FlexBlock,
6 FlexItem,
7 Spinner,
8 Button,
9 TextControl,
10 } = wp.components;
11
12 import { history } from "@/router/context";
13 import DatePicker from "../components/DatePicker";
14 import VideoAverageWatchTime from "../components/VideoAverageWatchTime";
15 import VideoTimeline from "../components/VideoTimeline";
16 import VideoViews from "../components/VideoViews";
17 import Player from "../../blocks/shared/Player";
18 import { getProvider } from "../../blocks/util";
19
20 const { useEffect, useState } = wp.element;
21 const { apiFetch } = wp;
22
23 const Video = ({ route, startDate, endDate, setStartDate, setEndDate }) => {
24 const [loading, setLoading] = useState(true);
25 const [video, setVideo] = useState({});
26 const [error, setError] = useState("");
27 const [thisName, setThisName] = useState(null);
28 const [editing, setEditing] = useState(false);
29
30 const back = () => {
31 history.push(`#/`);
32 };
33
34 const getVideo = async () => {
35 setLoading(true);
36 try {
37 let video = await apiFetch({
38 url: `${prestoPlayer?.root}${prestoPlayer?.prestoVersionString}videos/${route?.params?.id}`,
39 });
40 setVideo(video);
41 setThisName(video?.title);
42 } catch (e) {
43 if (e.code === "rest_no_route") {
44 setError("Video Not Found");
45 }
46 } finally {
47 setLoading(false);
48 }
49 };
50
51 const putVideo = async () => {
52 console.log(`New Video title ${thisName}`);
53 setLoading(true);
54 try {
55 const data = {
56 ...video,
57 ...{ title: thisName },
58 };
59 let saved = await wp.apiFetch({
60 method: "POST",
61 url: wp.url.addQueryArgs(
62 `${prestoPlayer.root}${prestoPlayer.prestoVersionString}videos/${video.id}`,
63 { _method: "PUT" }
64 ),
65 data,
66 });
67
68 if (!saved) {
69 throw genericError;
70 }
71 setEditing(false);
72 setVideo(saved);
73 } catch (e) {
74 setError(e?.message ? e.message : genericError);
75 } finally {
76 setLoading(false);
77 }
78 };
79
80 const cancelEditing = () => {
81 setThisName(video?.title);
82 setEditing(false);
83 };
84
85 const renderVideoEditableTitle = () => {
86 if (loading) {
87 return <Spinner />;
88 } else if (editing) {
89 return (
90 <div className="presto-inline-edit presto-inline-edit--editing">
91 <TextControl
92 className="presto-inline-edit__input"
93 type="text"
94 value={thisName}
95 onChange={(title) => setThisName(title)}
96 />
97 <Button
98 className="presto-inline-edit__button"
99 isPrimary
100 onClick={putVideo}
101 >
102 {" "}
103 Save{" "}
104 </Button>
105 <Button
106 className="presto-inline-edit__button"
107 isSecondary
108 onClick={cancelEditing}
109 >
110 {" "}
111 Cancel{" "}
112 </Button>
113 </div>
114 );
115 } else {
116 return (
117 <div className="presto-inline-edit">
118 <h1 className="presto-dashboard__title presto-inline-edit__text">
119 {video?.title}
120 </h1>
121
122 <button
123 className="presto-inline-edit__edit"
124 onClick={() => setEditing(true)}
125 >
126 <span className="dashicon dashicons dashicons-edit"></span>
127 </button>
128 </div>
129 );
130 }
131 };
132
133 useEffect(() => {
134 getVideo();
135 }, []);
136
137 if (error) {
138 return (
139 <div className="presto-flow">
140 <Flex>
141 <FlexBlock>
142 <h2>{error}</h2>
143 </FlexBlock>
144 </Flex>
145 </div>
146 );
147 }
148
149 return (
150 <div className="presto-flow">
151 <Flex>
152 <FlexBlock>
153 <Button isSecondary onClick={back}>
154 &larr; {__("Back to Dashboard", "presto-player")}
155 </Button>
156 </FlexBlock>
157 </Flex>
158 <Flex wrap>
159 <FlexBlock>{renderVideoEditableTitle()}</FlexBlock>
160 <FlexItem>
161 <DatePicker
162 startDate={startDate}
163 setStartDate={setStartDate}
164 endDate={endDate}
165 setEndDate={setEndDate}
166 />
167 </FlexItem>
168 </Flex>
169
170 <div className="presto-dashboard presto-flow">
171 <div className="presto-dashboard__row">
172 <div className="presto-dashboard__item is-large">
173 <VideoViews
174 video_id={route?.params?.id}
175 startDate={startDate}
176 endDate={endDate}
177 />
178 </div>
179 <div className="presto-dashboard__item">
180 {!!Object.keys(video || {}).length && (
181 <Player
182 src={video?.src}
183 attributes={{
184 title: video.title,
185 }}
186 type={getProvider(video.src)}
187 preset={{
188 "play-large": true,
189 play: true,
190 progress: true,
191 rewind: true,
192 "fast-forward": true,
193 "current-time": true,
194 background_color: "#8421cb",
195 volume: true,
196 mute: true,
197 i18n: window.prestoPlayer.i18n,
198 }}
199 />
200 )}
201 </div>
202 <div className="presto-dashboard__item">
203 <VideoAverageWatchTime
204 video_id={route?.params?.id}
205 startDate={startDate}
206 endDate={endDate}
207 />
208 </div>
209 </div>
210 <div className="presto-dashboard__row">
211 <div className="presto-dashboard__item is-large">
212 <VideoTimeline
213 video_id={route?.params?.id}
214 startDate={startDate}
215 endDate={endDate}
216 />
217 </div>
218 </div>
219 </div>
220 </div>
221 );
222 };
223
224 export default Video;
225