Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added image support for Ticker #128

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/backend-api/src/main/kotlin/org/icpclive/api/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ data class TextTickerSettings(
override fun toMessage() = TextTickerMessage(this)
}

@Serializable
@SerialName("image")
data class ImageTickerSettings(
override val part: TickerPart, override val periodMs: Long, val path: String
) : TickerMessageSettings() {
override fun toMessage() = ImageTickerMessage(this)
}


@Serializable
@SerialName("clock")
data class ClockTickerSettings(override val part: TickerPart, override val periodMs: Long) : TickerMessageSettings() {
Expand Down
13 changes: 12 additions & 1 deletion src/backend-api/src/main/kotlin/org/icpclive/api/Ticker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ class TextTickerMessage(val settings: TextTickerSettings) :
}
}

@Serializable
@SerialName("image")
class ImageTickerMessage(val settings: ImageTickerSettings)
: TickerMessage(generateId(TICKER_ID_PREFIX), settings.part, settings.periodMs) {
companion object {
const val TICKER_ID_PREFIX: String = "ticker_image"
}
}



@Serializable
@SerialName("clock")
class ClockTickerMessage(val settings: ClockTickerSettings) :
Expand All @@ -38,4 +49,4 @@ class ScoreboardTickerMessage(val settings: ScoreboardTickerSettings) :
companion object {
const val TICKER_ID_PREFIX: String = "ticker_scoreboard"
}
}
}
6 changes: 6 additions & 0 deletions src/frontend/admin/src/components/TickerMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AddIcon from "@mui/icons-material/Add";
import ClockIcon from "@mui/icons-material/AccessTime";
import ScoreboardIcon from "@mui/icons-material/EmojiEvents";
import TextIcon from "@mui/icons-material/Abc";
import ImageIcon from "@mui/icons-material/Image";
import { TickerTableRow } from "./TickerTableRow";
import Dashboard from "./Dashboard";
import { usePresetWidgetService } from "../services/presetWidget";
Expand All @@ -29,6 +30,11 @@ const addPresetButtons = [
component: TextIcon,
settings: { text: "", periodMs: 30000 },
},
{
type: "image",
component: ImageIcon,
settings: { path: "", periodMs: 30000 },
},
];

const makeAddButtons = (part) => {
Expand Down
10 changes: 10 additions & 0 deletions src/frontend/admin/src/components/TickerTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DeleteIcon from "@mui/icons-material/Delete";
import ClockIcon from "@mui/icons-material/AccessTime";
import ScoreboardIcon from "@mui/icons-material/EmojiEvents";
import TextIcon from "@mui/icons-material/Abc";
import ImageIcon from "@mui/icons-material/Image";
import ShowPresetButton from "./ShowPresetButton";
import { activeRowColor } from "../styles";
import PropTypes from "prop-types";
Expand Down Expand Up @@ -37,6 +38,7 @@ export function TickerTableRow({ data, onShow, onEdit, onDelete }) {
{data.settings.type === "clock" && <ClockIcon/>}
{data.settings.type === "scoreboard" && <ScoreboardIcon/>}
{data.settings.type === "text" && <TextIcon/>}
{data.settings.type === "image" && <ImageIcon/>}
</TableCell>
<TableCell component="th" scope="row">
{data.settings.type === "text" &&
Expand All @@ -47,6 +49,14 @@ export function TickerTableRow({ data, onShow, onEdit, onDelete }) {
onChange={onChangeFieldEventHandler(setEditData, "text")}/>
</Box>)
)}
{data.settings.type === "image" &&
(editData === undefined ? data.settings.text : (
<Box onSubmit={onSubmitEdit} component="form" type="submit">
<TextField autoFocus hiddenLabel fullWidth defaultValue={data.settings.path}
id="filled-hidden-label-small" type="text" size="small" sx={{ width: 1 }}
onChange={onChangeFieldEventHandler(setEditData, "path")}/>
</Box>)
)}
{data.settings.type === "scoreboard" &&
(editData === undefined ?
"From " + data.settings.from + " to " + data.settings.to :
Expand Down
16 changes: 16 additions & 0 deletions src/frontend/common/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,14 @@ export namespace TickerEvent {

export type TickerMessage =
| TickerMessage.clock
| TickerMessage.image
| TickerMessage.scoreboard
| TickerMessage.text;

export namespace TickerMessage {
export enum Type {
clock = "clock",
image = "image",
scoreboard = "scoreboard",
text = "text",
}
Expand All @@ -685,6 +687,14 @@ export namespace TickerMessage {
settings: clock;
}

export interface image {
type: TickerMessage.Type.image;
id: string;
part: TickerPart;
periodMs: number;
settings: image;
}

export interface scoreboard {
type: TickerMessage.Type.scoreboard;
id: string;
Expand Down Expand Up @@ -712,6 +722,12 @@ export interface clock {
periodMs: number;
}

export interface image {
part: TickerPart;
periodMs: number;
path: string;
}

export interface scoreboard {
part: TickerPart;
periodMs: number;
Expand Down
26 changes: 26 additions & 0 deletions src/frontend/overlay/src/components/organisms/tickers/Image.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import styled from "styled-components";


export const ImageWrap = styled.div`
width: 100%;
height: 100%;
max-height: 100%;
max-width: 100%;
background: url(${(props) => props.path}) no-repeat;
display: flex;
padding: 0 16px;
box-sizing: border-box;
background-size: contain;
background-position: center;
`;


export const Image = ({tickerSettings, part}) => {
return <ImageWrap
path={tickerSettings.path}
/>;
};

export default Image;

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import live from "../../../assets/icons/live.svg";
import Clock from "../tickers/Clock";
import Scoreboard from "../tickers/Scoreboard";
import Text from "../tickers/Text";
import Image from "../tickers/Image";

const rowAppear = keyframes`
from {
Expand Down Expand Up @@ -73,7 +74,8 @@ const SingleTickerWrap = styled.div`
const widgetTypes = Object.freeze({
text: Text,
clock: Clock,
scoreboard: Scoreboard
scoreboard: Scoreboard,
image: Image,
});

const DefaultTicker = ({ tickerSettings }) => {
Expand Down