PluginProbe ʕ •ᴥ•ʔ
Presto Player / 2.2.2
Presto Player v2.2.2
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 3 years ago Video.js 3 years ago illustration.js 5 years ago
Video.js
220 lines
1 const { __ } = wp.i18n;
2
3 const { Flex, FlexBlock, FlexItem, Spinner, Button, TextControl } =
4 wp.components;
5
6 import { history } from "@/router/context";
7 import DatePicker from "../components/DatePicker";
8 import VideoAverageWatchTime from "../components/VideoAverageWatchTime";
9 import VideoTimeline from "../components/VideoTimeline";
10 import VideoViews from "../components/VideoViews";
11 import Player from "../../blocks/shared/Player";
12 import { getProvider } from "../../blocks/util";
13
14 const { useEffect, useState } = wp.element;
15 const { apiFetch } = wp;
16
17 const Video = ({ route, startDate, endDate, setStartDate, setEndDate }) => {
18 const [loading, setLoading] = useState(true);
19 const [video, setVideo] = useState({});
20 const [error, setError] = useState("");
21 const [thisName, setThisName] = useState(null);
22 const [editing, setEditing] = useState(false);
23
24 const back = () => {
25 const { search } = history.location;
26 history.push(`${search}#/`);
27 };
28
29 const getVideo = async () => {
30 setLoading(true);
31 try {
32 let video = await apiFetch({
33 url: `${prestoPlayer?.root}${prestoPlayer?.prestoVersionString}videos/${route?.params?.id}`,
34 });
35 setVideo(video);
36 setThisName(video?.title);
37 } catch (e) {
38 if (e.code === "rest_no_route") {
39 setError("Video Not Found");
40 }
41 } finally {
42 setLoading(false);
43 }
44 };
45
46 const putVideo = async () => {
47 console.log(`New Video title ${thisName}`);
48 setLoading(true);
49 try {
50 const data = {
51 ...video,
52 ...{ title: thisName },
53 };
54 let saved = await wp.apiFetch({
55 method: "POST",
56 url: wp.url.addQueryArgs(
57 `${prestoPlayer.root}${prestoPlayer.prestoVersionString}videos/${video.id}`,
58 { _method: "PUT" }
59 ),
60 data,
61 });
62
63 if (!saved) {
64 throw genericError;
65 }
66 setEditing(false);
67 setVideo(saved);
68 } catch (e) {
69 setError(e?.message ? e.message : genericError);
70 } finally {
71 setLoading(false);
72 }
73 };
74
75 const cancelEditing = () => {
76 setThisName(video?.title);
77 setEditing(false);
78 };
79
80 const renderVideoEditableTitle = () => {
81 if (loading) {
82 return <Spinner />;
83 } else if (editing) {
84 return (
85 <div className="presto-inline-edit presto-inline-edit--editing">
86 <TextControl
87 className="presto-inline-edit__input"
88 type="text"
89 value={thisName}
90 onChange={(title) => setThisName(title)}
91 />
92 <Button
93 className="presto-inline-edit__button"
94 isPrimary
95 onClick={putVideo}
96 >
97 {" "}
98 Save{" "}
99 </Button>
100 <Button
101 className="presto-inline-edit__button"
102 isSecondary
103 onClick={cancelEditing}
104 >
105 {" "}
106 Cancel{" "}
107 </Button>
108 </div>
109 );
110 } else {
111 return (
112 <div className="presto-inline-edit">
113 <h1 className="presto-dashboard__title presto-inline-edit__text">
114 {video?.title}
115 </h1>
116
117 <button
118 className="presto-inline-edit__edit"
119 onClick={() => setEditing(true)}
120 >
121 <span className="dashicon dashicons dashicons-edit"></span>
122 </button>
123 </div>
124 );
125 }
126 };
127
128 useEffect(() => {
129 getVideo();
130 }, []);
131
132 if (error) {
133 return (
134 <div className="presto-flow">
135 <Flex>
136 <FlexBlock>
137 <h2>{error}</h2>
138 </FlexBlock>
139 </Flex>
140 </div>
141 );
142 }
143
144 return (
145 <div className="presto-flow">
146 <Flex>
147 <FlexBlock>
148 <Button isSecondary onClick={back}>
149 &larr; {__("Back to Dashboard", "presto-player")}
150 </Button>
151 </FlexBlock>
152 </Flex>
153 <Flex wrap>
154 <FlexBlock>{renderVideoEditableTitle()}</FlexBlock>
155 <FlexItem>
156 <DatePicker
157 startDate={startDate}
158 setStartDate={setStartDate}
159 endDate={endDate}
160 setEndDate={setEndDate}
161 />
162 </FlexItem>
163 </Flex>
164
165 <div className="presto-dashboard presto-flow">
166 <div className="presto-dashboard__row">
167 <div className="presto-dashboard__item is-large">
168 <VideoViews
169 video_id={route?.params?.id}
170 startDate={startDate}
171 endDate={endDate}
172 />
173 </div>
174 <div className="presto-dashboard__item">
175 {!!Object.keys(video || {}).length && (
176 <Player
177 src={video?.src}
178 attributes={{
179 title: video.title,
180 }}
181 type={getProvider(video.src)}
182 preset={{
183 "play-large": true,
184 play: true,
185 progress: true,
186 rewind: true,
187 "fast-forward": true,
188 "current-time": true,
189 background_color: "#8421cb",
190 volume: true,
191 mute: true,
192 i18n: window.prestoPlayer.i18n,
193 }}
194 />
195 )}
196 </div>
197 <div className="presto-dashboard__item">
198 <VideoAverageWatchTime
199 video_id={route?.params?.id}
200 startDate={startDate}
201 endDate={endDate}
202 />
203 </div>
204 </div>
205 <div className="presto-dashboard__row">
206 <div className="presto-dashboard__item is-large">
207 <VideoTimeline
208 video_id={route?.params?.id}
209 startDate={startDate}
210 endDate={endDate}
211 />
212 </div>
213 </div>
214 </div>
215 </div>
216 );
217 };
218
219 export default Video;
220