16 files changed
+264
-67
No files matched your search
+2
-1
@@ -50,7 +50,8 @@
|
||||
"error",
|
||||
"always-multiline"
|
||||
],
|
||||
"no-unused-vars": [
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"warn",
|
||||
{
|
||||
"varsIgnorePattern": "^_",
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { animated, useSpringRef, useTransition } from "@react-spring/web";
|
||||
|
||||
import { findPrefixCount } from "../../../../utils/strings";
|
||||
import { SlotText, SlotWindow } from "./styles";
|
||||
|
||||
type SlotSelectorProps = {
|
||||
items: Array<string>,
|
||||
onChange: (value: string) => void,
|
||||
removePrefix?: boolean,
|
||||
formatter?: (value: string) => string,
|
||||
initialIndex?: number,
|
||||
};
|
||||
export function SlotSelector({
|
||||
items,
|
||||
onChange,
|
||||
removePrefix = false,
|
||||
formatter = (x) => x,
|
||||
initialIndex = 0,
|
||||
}: SlotSelectorProps) {
|
||||
const [index, setIndex] = useState(initialIndex);
|
||||
const [prefixMask, setPrefixMask] = useState(0);
|
||||
const [formattedItems, setFormattedItems] = useState<Array<string>>([]);
|
||||
|
||||
// useMemo makes these functions only run once when mounting. Not ever re-render.
|
||||
useMemo(() => {
|
||||
const tempFormattedItems = items.map(item => formatter(item));
|
||||
setFormattedItems(tempFormattedItems);
|
||||
setPrefixMask(findPrefixCount(tempFormattedItems));
|
||||
}, [items]);
|
||||
|
||||
const onClick = () => {
|
||||
const nextIndex = (index + 1) % items.length;
|
||||
setIndex(nextIndex);
|
||||
onChange(items[nextIndex]);
|
||||
};
|
||||
|
||||
const getItem = (i: number) =>
|
||||
formattedItems.length &&
|
||||
removePrefix &&
|
||||
formattedItems[0].length !== prefixMask ?
|
||||
formattedItems[i].slice(prefixMask) :
|
||||
formattedItems[i];
|
||||
|
||||
const transRef = useSpringRef();
|
||||
const transitions = useTransition(index, {
|
||||
ref: transRef,
|
||||
keys: null,
|
||||
from: { opacity: 0, transform: "translate3d(0, 100%, 0" },
|
||||
enter: { opacity: 1, transform: "translate3d(0, 0%, 0" },
|
||||
leave: { opacity: 0, transform: "translate3d(0, -100%, 0" },
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
transRef.start();
|
||||
}, [index]);
|
||||
|
||||
return (
|
||||
<SlotWindow onClick={onClick}>
|
||||
{transitions((style, i) => (
|
||||
<SlotText as={animated.span} style={style}>{getItem(i)}</SlotText>
|
||||
))}
|
||||
</SlotWindow>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./SlotSelector";
|
||||
@@ -0,0 +1,27 @@
|
||||
import styled from "styled-components";
|
||||
|
||||
export const SlotWindow = styled.div`
|
||||
position: relative;
|
||||
height: 1.7em;
|
||||
width: auto;
|
||||
|
||||
border-radius: 0.6em;
|
||||
background-color: white;
|
||||
box-shadow: inset 0 0 50px -50px ${p => p.theme.colors.darkGrey};
|
||||
border: 1px solid ${p => p.theme.colors.darkGrey};
|
||||
|
||||
cursor: pointer;
|
||||
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
`;
|
||||
|
||||
export const SlotText = styled.span`
|
||||
position: absolute;
|
||||
display: block;
|
||||
margin-left: .4em;
|
||||
font-family: ${p => p.theme.fonts.f1Regular};
|
||||
color: ${p => p.theme.colors.darkGrey};
|
||||
user-select: none;
|
||||
`;
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
export type ToggleProps = {
|
||||
label: string,
|
||||
toggled: boolean,
|
||||
onToggle: (value: boolean) => void, // eslint-disable-line no-unused-vars
|
||||
onToggle: (value: boolean) => void,
|
||||
showIndicators?: boolean,
|
||||
};
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ const hoverRules = css`
|
||||
color: white;
|
||||
`;
|
||||
|
||||
export type MenuItemProps = {
|
||||
type MenuItemProps = {
|
||||
isHovered?: boolean,
|
||||
isActive?: boolean,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { Inline } from "@bedrock-layout/inline";
|
||||
import { PadBox } from "@bedrock-layout/padbox";
|
||||
import { Stack } from "@bedrock-layout/stack";
|
||||
|
||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||
import {
|
||||
@@ -10,31 +11,18 @@ import {
|
||||
} from "../../../features/overlayTool/overlayToolSlice";
|
||||
|
||||
import { Toggle } from "../../Common/Inputs/Toggle";
|
||||
import { MockupBlock } from "../../Common/MockupBlock.styled";
|
||||
import { SlotSelector } from "../../Common/Inputs/SlotSelector";
|
||||
|
||||
|
||||
export function OverlayControl() {
|
||||
const dispatch = useDispatch();
|
||||
const { overlayIds, visible, currentOverlayItem } = useSelector(overlayToolSelector);
|
||||
|
||||
|
||||
|
||||
|
||||
/* For prototyping use only */
|
||||
const [idNum, setIdNum] = useState(0);
|
||||
|
||||
const nextIdNum = () => {
|
||||
const nextIdNum = (idNum + 1) % overlayIds.length;
|
||||
setIdNum(nextIdNum);
|
||||
dispatch(setCurrentOverlayId(overlayIds[nextIdNum]));
|
||||
};
|
||||
/* For prototyping use only */
|
||||
|
||||
|
||||
|
||||
const onToggle = (value: boolean) => {
|
||||
if (currentOverlayItem == null) {
|
||||
dispatch(initNewOverlayItem({
|
||||
overlayId: overlayIds[idNum],
|
||||
overlayId: overlayIds[0],
|
||||
initialPosition: { x: 0, y: 0 },
|
||||
setVisible: true,
|
||||
}));
|
||||
@@ -44,22 +32,27 @@ export function OverlayControl() {
|
||||
};
|
||||
|
||||
return (
|
||||
<PadBox padding="sm">
|
||||
<Toggle
|
||||
label="Show Overlay"
|
||||
toggled={visible}
|
||||
onToggle={onToggle}
|
||||
/>
|
||||
|
||||
{/* For prototyping use only */}
|
||||
<br />
|
||||
<a
|
||||
onClick={nextIdNum}
|
||||
>
|
||||
Id #{idNum}: "{overlayIds[idNum]}"
|
||||
</a>
|
||||
{/* For prototyping use only */}
|
||||
|
||||
</PadBox>
|
||||
<Stack gutter="sm">
|
||||
<Inline gutter="sm" stretch="end">
|
||||
<Toggle
|
||||
label="Show Overlay"
|
||||
toggled={visible}
|
||||
onToggle={onToggle}
|
||||
/>
|
||||
<PadBox padding="sm">
|
||||
<SlotSelector
|
||||
items={overlayIds}
|
||||
onChange={(value) => dispatch(setCurrentOverlayId(value))}
|
||||
removePrefix
|
||||
formatter={(value) => value.replace(/(\.png)|(\.jpg)$/, "")}
|
||||
/>
|
||||
</PadBox>
|
||||
</Inline>
|
||||
<PadBox padding="sm">
|
||||
<MockupBlock color="green" height="1.5rem" width="100%">
|
||||
Opacity Slider
|
||||
</MockupBlock>
|
||||
</PadBox>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { Center } from "@bedrock-layout/center";
|
||||
import { Stack } from "@bedrock-layout/stack";
|
||||
|
||||
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
|
||||
import { setWorkspaceId } from "../../../features/workspace/workspaceSlice";
|
||||
import { updateWorkspace } from "../../../features/workspace/workspaceSlice";
|
||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||
import { newWorkspace } from "../../../features/overlayTool/overlayToolSlice";
|
||||
|
||||
@@ -14,31 +14,33 @@ import { WorkspaceControls } from "./WorkspaceControls";
|
||||
import { MockupBlock } from "../../Common/MockupBlock.styled";
|
||||
import { OverlayDisplay } from "../../OverlayTool";
|
||||
|
||||
import { workspaceObject } from "../workspaces";
|
||||
import { workspaces } from "../workspaces";
|
||||
|
||||
export const Workspace = () => {
|
||||
const dispatch = useDispatch();
|
||||
const { workspaceId } = useParams();
|
||||
const { animatedBG } = useSelector(workspaceSelector);
|
||||
const { animatedBG, workspaceProperties } = useSelector(workspaceSelector);
|
||||
const { currentWorkspaceId: overlayWorkspaceId } = useSelector(overlayToolSelector);
|
||||
|
||||
useEffect(() => {
|
||||
if (workspaceId == null) return;
|
||||
|
||||
// Update workspace store for ID.
|
||||
dispatch(setWorkspaceId(workspaceId));
|
||||
dispatch(updateWorkspace({
|
||||
workspaceId,
|
||||
workspaceProperties: workspaces[workspaceId],
|
||||
}));
|
||||
|
||||
// Switching Workspace means we need to init a newWorkspace for Overlay tool.
|
||||
if (overlayWorkspaceId !== workspaceId) {
|
||||
dispatch(newWorkspace({
|
||||
overlayIds: workspaceObject[workspaceId].overlayIds,
|
||||
overlayIds: workspaces[workspaceId].overlayIds,
|
||||
workspaceId: workspaceId,
|
||||
}));
|
||||
}
|
||||
}, [workspaceId]);
|
||||
|
||||
if (workspaceId == null) return null;
|
||||
const workspace = workspaceObject[workspaceId];
|
||||
|
||||
return (
|
||||
<Stack
|
||||
@@ -47,9 +49,9 @@ export const Workspace = () => {
|
||||
maxWidth="80%"
|
||||
centerChildren
|
||||
>
|
||||
<H2>{workspaceId ? workspace.name : "Unknown"}</H2>
|
||||
<H2>{workspaceId ? workspaceProperties.name : "Unknown"}</H2>
|
||||
<PreviewWindow
|
||||
dimensions={workspace.previewWindowDimensions}
|
||||
dimensions={workspaceProperties.previewWindowDimensions}
|
||||
animatedBG={animatedBG}
|
||||
>
|
||||
<MockupBlock
|
||||
@@ -58,7 +60,7 @@ export const Workspace = () => {
|
||||
width="100px"
|
||||
>Preview Item</MockupBlock>
|
||||
<OverlayDisplay
|
||||
containerDimensions={workspace.previewWindowDimensions}
|
||||
containerDimensions={workspaceProperties.previewWindowDimensions}
|
||||
/>
|
||||
</PreviewWindow>
|
||||
<ControlsContainer>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Grid } from "@bedrock-layout/grid";
|
||||
import { PadBox } from "@bedrock-layout/padbox";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
|
||||
@@ -12,14 +13,18 @@ export const WorkspaceControls = () => {
|
||||
const { animatedBG } = useSelector(workspaceSelector);
|
||||
|
||||
return(
|
||||
<Grid gutter="sm" minItemWidth="25rem">
|
||||
<Toggle
|
||||
label="Animate BG"
|
||||
toggled={animatedBG}
|
||||
onToggle={(value: boolean) => {
|
||||
dispatch(setAnimatedBG(value));
|
||||
}} />
|
||||
<OverlayControl />
|
||||
<Grid gutter="sm" minItemWidth="100px">
|
||||
<PadBox padding="sm">
|
||||
<Toggle
|
||||
label="Animate BG"
|
||||
toggled={animatedBG}
|
||||
onToggle={(value: boolean) => {
|
||||
dispatch(setAnimatedBG(value));
|
||||
}} />
|
||||
</PadBox>
|
||||
<PadBox padding="sm">
|
||||
<OverlayControl />
|
||||
</PadBox>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -5,13 +5,13 @@ import { WorkspaceListBox } from "./styles";
|
||||
import { Stack } from "@bedrock-layout/stack";
|
||||
import { MenuItem } from "../../Common/MenuItem.styled";
|
||||
|
||||
import { workspaceObject } from "../workspaces";
|
||||
import { workspaces } from "../workspaces";
|
||||
|
||||
type WorkspaceListProps = {
|
||||
headerOffset?: number,
|
||||
};
|
||||
export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => {
|
||||
const workspaceList = _.keys(workspaceObject);
|
||||
const workspaceList = _.keys(workspaces);
|
||||
return (
|
||||
<WorkspaceListBox headerOffset={headerOffset}>
|
||||
<Stack as="ul" gutter="md">
|
||||
@@ -19,7 +19,7 @@ export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => {
|
||||
<WorkspaceListNavLink
|
||||
key={id}
|
||||
to={id}
|
||||
label={workspaceObject[id].name}
|
||||
label={workspaces[id].name}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { Dimensions, OverlayIds } from "../../types/state";
|
||||
import { WorkspaceProperties } from "../../types/state";
|
||||
|
||||
export type WorkspaceObject = {
|
||||
[id: string]: {
|
||||
name: string,
|
||||
overlayIds: OverlayIds,
|
||||
previewWindowDimensions: Dimensions,
|
||||
},
|
||||
type WorkspaceObject = {
|
||||
[id: string]: WorkspaceProperties,
|
||||
};
|
||||
export const workspaceObject: WorkspaceObject = {
|
||||
export const workspaces: WorkspaceObject = {
|
||||
chyronSimple: {
|
||||
name: "Chyron Simple",
|
||||
overlayIds: [
|
||||
|
||||
@@ -65,6 +65,10 @@ export const overlayToolSlice = createSlice({
|
||||
state.currentWorkspaceId = action.payload.workspaceId;
|
||||
state.overlayIds = action.payload.overlayIds;
|
||||
},
|
||||
setOpacity: (state, action: PayloadAction<number>) => {
|
||||
if (state.currentOverlayItem == null) return;
|
||||
state.currentOverlayItem.opacity = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -74,5 +78,6 @@ export const {
|
||||
setCurrentOverlayId,
|
||||
setPosition,
|
||||
newWorkspace,
|
||||
setOpacity,
|
||||
} = overlayToolSlice.actions;
|
||||
export default overlayToolSlice.reducer;
|
||||
@@ -1,9 +1,19 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { RootState, WorkspaceId } from "../../types/state";
|
||||
import { RootState, WorkspaceId, WorkspaceProperties } from "../../types/state";
|
||||
|
||||
const initialState: RootState["workspace"] = {
|
||||
workspaceId: "",
|
||||
animatedBG: true,
|
||||
workspaceProperties: {
|
||||
name: "undefined",
|
||||
overlayIds: [],
|
||||
previewWindowDimensions: { width: 0, height: 0 },
|
||||
},
|
||||
};
|
||||
|
||||
export type UpdateWorkspaceAction = {
|
||||
workspaceId: WorkspaceId,
|
||||
workspaceProperties: WorkspaceProperties,
|
||||
};
|
||||
|
||||
export const workspaceSlice = createSlice({
|
||||
@@ -16,8 +26,16 @@ export const workspaceSlice = createSlice({
|
||||
setAnimatedBG: (state, action: PayloadAction<boolean>) => {
|
||||
state.animatedBG = action.payload;
|
||||
},
|
||||
updateWorkspace: (state, action: PayloadAction<UpdateWorkspaceAction>) => {
|
||||
state.workspaceId = action.payload.workspaceId;
|
||||
state.workspaceProperties = action.payload.workspaceProperties;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setWorkspaceId, setAnimatedBG } = workspaceSlice.actions;
|
||||
export const {
|
||||
setWorkspaceId,
|
||||
setAnimatedBG,
|
||||
updateWorkspace,
|
||||
} = workspaceSlice.actions;
|
||||
export default workspaceSlice.reducer;
|
||||
Vendored
+6
@@ -16,9 +16,15 @@ export type Dimensions = { width: number, height: number };
|
||||
export type Workspace = {
|
||||
workspaceId: WorkspaceId,
|
||||
animatedBG: boolean,
|
||||
workspaceProperties: WorkspaceProperties,
|
||||
};
|
||||
|
||||
export type WorkspaceId = string;
|
||||
export type WorkspaceProperties = {
|
||||
name: string,
|
||||
overlayIds: OverlayIds,
|
||||
previewWindowDimensions: Dimensions,
|
||||
};
|
||||
|
||||
// Overlay Tool
|
||||
export type OverlayTool = {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { findPrefixCount } from "./strings";
|
||||
|
||||
describe("strings", () => {
|
||||
describe("findPrefixCount", () => {
|
||||
describe("finds matches", () => {
|
||||
it("gets correct count all the same", () => {
|
||||
expect(findPrefixCount([
|
||||
"hello",
|
||||
"hello",
|
||||
"hello",
|
||||
"hello",
|
||||
], true)).toBe(5);
|
||||
});
|
||||
it("gets correct count for hello prefix", () => {
|
||||
expect(findPrefixCount([
|
||||
"hello world",
|
||||
"hello mother",
|
||||
"hello father",
|
||||
"hello!",
|
||||
], true)).toBe(5);
|
||||
});
|
||||
it("gets zero when nothing matches", () => {
|
||||
expect(findPrefixCount([
|
||||
"cat",
|
||||
"dog",
|
||||
"rat",
|
||||
], true)).toBe(0);
|
||||
});
|
||||
it("returns 0 when only given a single string", () => {
|
||||
expect(findPrefixCount([
|
||||
"by myself",
|
||||
], true)).toBe(0);
|
||||
});
|
||||
it("returns 0 when given no strings", () => {
|
||||
expect(findPrefixCount([], true)).toBe(0);
|
||||
});
|
||||
it("is case sensitive", () => {
|
||||
expect(findPrefixCount([
|
||||
"Hello",
|
||||
"HELLO",
|
||||
"Hello",
|
||||
], true)).toBe(1);
|
||||
});
|
||||
it("is correctly case-insensitive", () => {
|
||||
expect(findPrefixCount([
|
||||
"Hello",
|
||||
"HELLO",
|
||||
"Hello",
|
||||
], false)).toBe(5);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Gives you the number of characters that prefix all the given strings.
|
||||
* I use this to remove redundant repeated characters shared between file names.
|
||||
* Basically, this is a method to do the " you find in a list.
|
||||
* @param strings
|
||||
* @returns number of characters that all strings share from the start
|
||||
*/
|
||||
export function findPrefixCount(strings: Array<string>, caseSensitive = true): number {
|
||||
if (strings.length <= 1) {
|
||||
return 0; // Cannot find anything. So, most neutral return is 0.
|
||||
}
|
||||
|
||||
let maskLength = strings[0].length;
|
||||
for (let x = 1; x < strings.length; ++x) {
|
||||
for (let c = 0; c < maskLength; c++) {
|
||||
const left = caseSensitive ? strings[0][c] : strings[0][c].toLowerCase();
|
||||
const right = caseSensitive ? strings[x][c] : strings[x][c].toLowerCase();
|
||||
if (left !== right) {
|
||||
maskLength = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return maskLength;
|
||||
}
|
||||
Reference in new issue
Block a user