Skip to content

Commit

Permalink
fix styles, add visual draft for 'Add options to roulette' button
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed Feb 11, 2024
1 parent bdd035e commit cab09ec
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 90 deletions.
5 changes: 3 additions & 2 deletions src/components/ConfigurationPage/WidgetConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import BaseSettings from "./settings/BaseSettings";
import DonatersTopListSettings from "./settings/DonatersTopListSettings";
import DonationTimerSettings from "./settings/DonationTimerSettings";
import { socket } from "../../socket";
import RouletteWidgetSettings from "../../pages/Reel/RouletteWidgetSettings";

interface WidgetConfigurationProps {
id: string;
Expand All @@ -27,8 +28,8 @@ function getSettingsWidget(id: string, type: string, onChange: Function) {
return <PaymentAlertSettings id={id} onChange={onChange} />;
case "donaters-top-list":
return <DonatersTopListSettings id={id} onChange={onChange} />;
case "donation-timer":
return <BaseSettings id={id} onChange={onChange} />;
case "roulette":
return <RouletteWidgetSettings id={id} onChange={onChange} />;
default:
return <BaseSettings id={id} onChange={onChange} />;
}
Expand Down
9 changes: 9 additions & 0 deletions src/components/ConfigurationPage/WidgetSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ const defaultSettings = {
value: "#000000",
displayName: "Цвет",
},
{
name: "optionList",
type: "custom",
value: [
"Ничего",
"Выигрыш"
],
displayName: "Призы",
}
],
},
};
Expand Down
16 changes: 16 additions & 0 deletions src/components/ConfigurationPage/css/WidgetSettings.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
top: 10px;
font-family: "Martian Mono", monospace;
}
.payment-alert-settings .widget-settings-name {
width: 50%;
}

.widget-settings-value:focus-visible,
.widget-settings-value:focus {
Expand All @@ -53,6 +56,15 @@
border-image-slice: 1;
}

.widget-settings-value:hover {
cursor: pointer;
}

.widget-settings-item,
.widget-settings-item label:hover {
cursor: default;
}

.widget-settings-value {
font-family: inherit;
width: 100%;
Expand All @@ -71,6 +83,7 @@
.textarea-container {
width: 100%;
text-align: right;
padding-top: 5px;
}

.widget-settings-value {
Expand All @@ -82,6 +95,7 @@

textarea.widget-settings-value {
text-align: left;
width: 50%;
}

.widget-settings-value.select {
Expand Down Expand Up @@ -224,4 +238,6 @@ textarea.widget-settings-value {
.widget-settings-radiocontainer {
display: flex;
flex-direction: column;
width: 100%;
text-align: right;
}
28 changes: 22 additions & 6 deletions src/components/ConfigurationPage/settings/BaseSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ export default function BaseSettings({
return (
<>
{config.get(id)?.properties?.map((prop) => (
<>
{(prop.type !== "custom" || customHandler) && (
<div key={prop.name} className="widget-settings-item">
<label
htmlFor={`${id}_${prop.name}`}
className="widget-settings-name"
>
{prop.displayName}
</label>
{prop.type !== "custom" && (
<label
htmlFor={`${id}_${prop.name}`}
className="widget-settings-name"
>
{prop.displayName}
</label>
)}
{(!prop.type || prop.type == "string") && (
<input
id={`${id}_${prop.name}`}
Expand Down Expand Up @@ -86,7 +90,19 @@ export default function BaseSettings({
) : (
<></>
)}
{prop.type === "number" && (
<>
<input
value={prop.value}
type="number"
className="widget-settings-value"
onChange={(e) => update(prop.name, e.target.value)}
/>
</>
)}
</div>
)}
</>
))}
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ChangeEvent, useContext } from "react";
import { WidgetsContext } from "../WidgetsContext";
import ColorPicker from "./ColorPicker";
import BaseSettings from "./BaseSettings";

const fonts = [
"Roboto",
Expand Down Expand Up @@ -67,33 +68,12 @@ export default function DonatersTopListSettings({

return (
<>
<BaseSettings id={id} onChange={onChange}/>
{config.get(id)?.properties?.map((prop) => (
<>
{prop.type === "custom" && (
<div key={prop.name} className="widget-settings-item">
<div className="widget-settings-name">{prop.displayName}</div>
{(!prop.type || prop.type == "string") && prop.type != "custom" && (
<input
value={prop.value}
className="widget-settings-value"
onChange={(e) => update(prop.name, e.target.value)}
/>
)}
{prop.type === "fontselect" && (
<select
value={prop.value}
className="widget-settings-value select"
onChange={(e) => update(prop.name, e.target.value)}
>
{fonts.sort().map((font) => (
<option key={font}>{font}</option>
))}
</select>
)}
{prop.type === "color" && (
<ColorPicker
value={prop.value}
onChange={(value) => update(prop.name, value)}
/>
)}
<label className="widget-settings-name">{prop.displayName}</label>
{prop.name === "type" && (
<select
value={prop.value}
Expand Down Expand Up @@ -149,28 +129,11 @@ export default function DonatersTopListSettings({
</div>
</>
)}
{prop.type === "text" && (
<>
<textarea
style={{ width: "100%" }}
className="widget-settings-value"
value={prop.value}
onChange={(e) => update(prop.name, e.target.value)}
/>
</>
)}
{prop.type === "number" && (
<>
<input
value={prop.value}
type="number"
className="widget-settings-value"
onChange={(e) => update(prop.name, e.target.value)}
/>
</>
)}
</div>
))}
)}
</>
))
}
</>
);
}
30 changes: 20 additions & 10 deletions src/components/MediaWidget/PlaylistController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,36 @@ export class PlaylistController {
this.handleNewRequestedSongEvent(song);
message.ack();
});
subscribe(widgetId, conf.topic.finishedmedia, (message) => {
const song = JSON.parse(message.body);
this.current.markListened(song.id);
message.ack();
});
subscribe(
`${widgetId}_playlistController`,
conf.topic.remoteplayerfeedback,
(message) => {
const feedback = JSON.parse(message.body);
if (feedback.state === "finished") {
this.current.markListened(feedback.song.id);
}
message.ack();
},
);
}

handleNewRequestedSongEvent(song:Song){
handleNewRequestedSongEvent(song: Song) {
this.playlists.get(PLAYLIST_TYPE.REQUESTED)?.addSong(song);
if (this.current.type() == PLAYLIST_TYPE.PERSONAL) {
this.switchTo(PLAYLIST_TYPE.REQUESTED);
}
}

previousSong(){
previousSong() {
const index = this.current.index();
if (index != null && index > 0) {
this.current.setIndex(index - 1);
}
}

finishSong(){
finishSong() {
const song = this.current.song();
if (song?.id){
if (song?.id) {
this.current.markListened(song?.id);
}
}
Expand All @@ -98,7 +104,11 @@ export class PlaylistController {
}

switchTo(type: PLAYLIST_TYPE) {
log.debug(`switching to ${type == PLAYLIST_TYPE.PERSONAL ? "personal" : "requested"}`);
log.debug(
`switching to ${
type == PLAYLIST_TYPE.PERSONAL ? "personal" : "requested"
}`,
);
const playlist = this.playlists.get(type);
if (playlist) {
this.playlistRenderers.forEach((renderer) => {
Expand Down
18 changes: 0 additions & 18 deletions src/components/MediaWidget/PopupPlayerImpl.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/MediaWidget/VideoJSComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default function VideoJSComponent({
}
log.debug(`sending song ${JSON.stringify(song)} to remote player`);
publish(conf.topic.remoteplayer, { command: "play", song: song });
setPlayerState(PLAYER_STATE.PLAYING);
}, [isRemote, song]);

function sendAlert(title: string) {
Expand All @@ -127,7 +128,6 @@ export default function VideoJSComponent({
if (isRemote || song === null) {
return;
}
log.debug("Creating new player instance");
log.debug(`playing song ${JSON.stringify(song)}`);

const videoElement = document.createElement("video-js");
Expand Down
17 changes: 10 additions & 7 deletions src/components/PlayerPopup/PlayerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export default function PlayerPopup({}) {
const videoRef = useRef(null);
const [hideVideo, setHideVideo] = useState(false);
const { recipientId, settings, conf, widgetId } = useLoaderData();
const [song, setSong] = useState<Song|null>(null);
const [song, setSong] = useState<Song | null>(null);

useEffect(() => {
const audioOnly = findSetting(settings, "audioOnly", false);
setHideVideo(audioOnly);
},[conf]);
}, [conf]);

function createPlayer(song: Song) {
if (playerRef.current) {
Expand All @@ -49,7 +49,10 @@ export default function PlayerPopup({}) {
playerRef.current.uuid = uuidv4();
playerRef.current.on("ended", () => {
log.debug(`finished playing song`);
publish(conf.topic.finishedmedia, song);
publish(conf.topic.remoteplayerfeedback, {
state: "finished",
song: song,
});
playerRef.current?.dispose();
playerRef.current = null;
});
Expand All @@ -60,17 +63,17 @@ export default function PlayerPopup({}) {
subscribe(widgetId, conf.topic.remoteplayer, (message) => {
let json = JSON.parse(message.body);
log.debug(`playing ${JSON.stringify(json.song)}`);
if (json.command === "play"){
if (json.command === "play") {
setSong(json.song);
}
if (json.command === "stop"){
if (json.command === "stop") {
playerRef.current?.dispose();
setSong(null);
}
if (json.command === "pause"){
if (json.command === "pause") {
playerRef.current?.pause();
}
if (json.command === "resume"){
if (json.command === "resume") {
playerRef.current?.play();
}
message.ack();
Expand Down
18 changes: 18 additions & 0 deletions src/pages/Reel/RouletteWidgetSettings.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.optionscontainer {
width: 100%;
display: flex;
flex-direction: column;
align-items: end;
}

.addoptionsbutton {
border: none;
background-color: initial;
color: #684aff;
}

.addbuttoncontainer {
width: 50%;
text-align: center;
padding-top: 10px;
}
Loading

0 comments on commit cab09ec

Please sign in to comment.