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

refactor: Add Redux #4

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@fortawesome/free-solid-svg-icons": "^6.7.2",
"@fortawesome/react-fontawesome": "^0.2.2",
"@pixi/react": "8.0.0-beta.21",
"@reduxjs/toolkit": "^2.5.1",
"@types/node": "^22.10.5",
"audio-decode": "^2.2.2",
"eventemitter3": "^5.0.1",
Expand All @@ -26,7 +27,9 @@
"rc-dock": "^3.3.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-redux": "^9.2.0",
"react-split-pane": "^0.1.92",
"redux": "^5.0.1",
"uuid": "^11.0.4"
},
"devDependencies": {
Expand Down
89 changes: 89 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 46 additions & 1 deletion src/Chart/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullable } from '@/utils/types';
import { BeatArray, Nullable } from '@/utils/types';

export type ChartInfo = {
name: string,
Expand Down Expand Up @@ -27,3 +27,48 @@ export type FloorPosition = {
endTime: number,
value: number,
};

export type ChartNote = {
id: string,
lineID: string,
type: NoteType,
time: BeatArray,
speed: number,
isAbove: boolean,
holdEndTime: BeatArray,
};

export type ChartKeyframe = {
id: string,
lineID: string,
time: BeatArray,
value: number,
continuous: boolean,
easing: number,
};

export type ChartJudglineProps = {
speed: ChartKeyframe[],
positionX: ChartKeyframe[],
positionY: ChartKeyframe[],
rotate: ChartKeyframe[],
alpha: ChartKeyframe[],
};

export type ChartJudgeline = {
id: string,
props: ChartJudglineProps,
notes: ChartNote[],
};

export type ChartBPM = {
id: string,
time: BeatArray,
bpm: number,
};

export type Chart = {
bpms: ChartBPM[],
lines: ChartJudgeline[],
notes: ChartNote[],
};
9 changes: 5 additions & 4 deletions src/ui/Timeline/LeftPanel/LeftPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import React from "react";
import TimelineList from "../List/List";
import ChartJudgeline from "@/Chart/Judgeline";
import LeftPanelHead from "./Head";
import LeftPanelLine from './Line';
import './styles.css';
import { useAppSelector } from "@/ui/store/hooks";
import { selectAllLinesState } from "@/ui/store/selectors/chart";

export type TimelineLeftPanelProps = {
lines: ChartJudgeline[],
expandedLines: number[],
onLineExpanded: (lineIndex: number, isExpanded: boolean) => void,
};

const TimelineLeftPanel: React.FC<TimelineLeftPanelProps> = ({
lines,
expandedLines,
onLineExpanded,
}) => {
const lines = useAppSelector((state) => selectAllLinesState(state));

return (
<div className="timeline-panel-left">
<LeftPanelHead />
<TimelineList>
{lines.map((line, index) => { // TODO: Render line props & add right click menu
return <LeftPanelLine
line={line}
lineID={line.id}
name={`Line #${index}`}
isExpanded={expandedLines.includes(index)}
onExpandClick={(e) => onLineExpanded(index, e)}
Expand Down
17 changes: 7 additions & 10 deletions src/ui/Timeline/LeftPanel/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,28 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { useCallback } from 'react';
import TimelineList from '../List/List';
import TimelineListItem from '../List/Item';
import { useSelectedItem } from '@/ui/contexts/SelectedItem';
import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
import ChartJudgeline from '@/Chart/Judgeline';
import { selectLine } from "@/ui/store/slices/chart";
import { useAppDispatch } from '@/ui/store/hooks';

export type TimelineLeftPanelLineProps = {
line: ChartJudgeline,
lineID: string,
name: string,
isExpanded: boolean,
onExpandClick: (isExpanded: boolean) => void
};

const TimelineLeftPanelLine: React.FC<TimelineLeftPanelLineProps> = ({
line,
lineID,
name,
isExpanded,
onExpandClick
}: TimelineLeftPanelLineProps) => {
const [ , setSelectedItem ] = useSelectedItem()!;
const dispatch = useAppDispatch();

const handleLineClicked = useCallback(() => {
setSelectedItem((oldItem) => {
if (oldItem === null) return { line, keyframe: null, note: null };
else return { ...oldItem, line };
});
}, [line, setSelectedItem]);
dispatch(selectLine(lineID));
}, [dispatch, lineID]);

return <TimelineListItem className="line-detail" onClick={handleLineClicked}>
<div className="line-info">
Expand Down
Loading