-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat(visualizer): update block colors #1193
Changes from 2 commits
18b49c8
a33992a
ea21b5d
5eb6b4d
cee811e
d1cc4e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react"; | ||
import { useGetThemeMode } from "~/helpers/hooks/useGetThemeMode.js"; | ||
import { VisualizerRouteProps } from "~/app/routes/VisualizerRouteProps.js"; | ||
import { RouteComponentProps } from "react-router-dom"; | ||
import NovaVisualizer from "./VisualizerInstance"; | ||
|
||
export default function NovaVisualizerWrapper(props: RouteComponentProps<VisualizerRouteProps>): React.JSX.Element { | ||
const theme = useGetThemeMode(); | ||
|
||
return <NovaVisualizer key={theme} {...props} />; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { devtools } from "zustand/middleware"; | |
import { ZOOM_DEFAULT, SPRAY_DISTANCE } from "../constants"; | ||
import { IFeedBlockData } from "~models/api/nova/feed/IFeedBlockData"; | ||
import { IThreeDimensionalPosition } from "../interfaces"; | ||
import { BlockId, SlotIndex } from "@iota/sdk-wasm-nova/web"; | ||
import { BlockId, BlockState, SlotIndex } from "@iota/sdk-wasm-nova/web"; | ||
import { getVisualizerConfigValues } from "~features/visualizer-threejs/ConfigControls"; | ||
|
||
export interface IBlockAnimationPosition { | ||
|
@@ -80,6 +80,9 @@ interface TangleState { | |
confirmedBlocksBySlot: Map<number, string[]>; | ||
addToConfirmedBlocksBySlot: (blockId: BlockId, slot: SlotIndex) => void; | ||
removeConfirmedBlocksSlot: (slot: SlotIndex) => void; | ||
|
||
blockIdToState: Map<BlockId, BlockState>; | ||
setBlockIdToBlockState: (blockId: BlockId, blockState: BlockState) => void; | ||
Comment on lines
+84
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that we have a lot of data that related to blockId. Maybe it's a good sign to:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created a new issue for this: |
||
} | ||
|
||
const INITIAL_STATE = { | ||
|
@@ -97,12 +100,32 @@ const INITIAL_STATE = { | |
bps: 0, | ||
clickedInstanceId: null, | ||
confirmedBlocksBySlot: new Map(), | ||
blockIdToState: new Map(), | ||
}; | ||
|
||
export const useTangleStore = create<TangleState>()( | ||
devtools((set) => ({ | ||
...INITIAL_STATE, | ||
resetConfigState: () => set(INITIAL_STATE), | ||
resetConfigState: () => | ||
// hard cleanup of the store | ||
set((state) => { | ||
state.blockQueue = []; | ||
state.edgeQueue = []; | ||
state.colorQueue = []; | ||
state.blockIdToEdges = new Map(); | ||
state.blockIdToIndex = new Map(); | ||
state.blockIdToPosition = new Map(); | ||
state.blockMetadata = new Map(); | ||
state.blockIdToAnimationPosition = new Map(); | ||
state.indexToBlockId = []; | ||
state.zoom = ZOOM_DEFAULT; | ||
state.forcedZoom = undefined; | ||
state.bps = 0; | ||
state.clickedInstanceId = null; | ||
state.confirmedBlocksBySlot = new Map(); | ||
state.blockIdToState = new Map(); | ||
return state; | ||
}), | ||
updateBlockIdToAnimationPosition: (updatedPositions) => { | ||
set((state) => { | ||
updatedPositions.forEach((value, key) => { | ||
|
@@ -196,15 +219,18 @@ export const useTangleStore = create<TangleState>()( | |
updateBlockIdToIndex: (blockId: string, index: number) => { | ||
set((state) => { | ||
state.blockIdToIndex.set(blockId, index); | ||
if (state.indexToBlockId[index]) { | ||
const previousBlockId = state.indexToBlockId[index]; | ||
if (previousBlockId) { | ||
Comment on lines
+222
to
+223
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I see. Maybe this is something that I was talking about in comment above. |
||
// Clean up map from old blockIds | ||
state.blockIdToIndex.delete(state.indexToBlockId[index]); | ||
state.blockIdToIndex.delete(previousBlockId); | ||
// Clean up old block edges | ||
state.blockIdToEdges.delete(state.indexToBlockId[index]); | ||
state.blockIdToEdges.delete(previousBlockId); | ||
// Clean up old block position | ||
state.blockIdToPosition.delete(state.indexToBlockId[index]); | ||
state.blockIdToPosition.delete(previousBlockId); | ||
// Clean up old block metadata | ||
state.blockMetadata.delete(state.indexToBlockId[index]); | ||
state.blockMetadata.delete(previousBlockId); | ||
// Cleanup old block state | ||
state.blockIdToState.delete(previousBlockId); | ||
} | ||
|
||
const nextIndexToBlockId = [...state.indexToBlockId]; | ||
|
@@ -268,5 +294,14 @@ export const useTangleStore = create<TangleState>()( | |
}; | ||
}); | ||
}, | ||
setBlockIdToBlockState(blockId, blockState) { | ||
set((state) => { | ||
state.blockIdToState.set(blockId, blockState); | ||
return { | ||
...state, | ||
blockIdToState: state.blockIdToState, | ||
}; | ||
}); | ||
}, | ||
})), | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, { memo } from "react"; | ||
|
||
const ColorPanel = ({ label, color }: { label: string; color: string }): React.JSX.Element => ( | ||
<div className="key-panel-item"> | ||
<div | ||
className="key-marker" | ||
style={{ | ||
backgroundColor: color, | ||
}} | ||
/> | ||
<div className="key-label">{label}</div> | ||
</div> | ||
); | ||
|
||
export default memo(ColorPanel); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
NovaVisualizer
name instead ofNovaVisualizerWrapper
?Seems it could be more convenient according to names on this page.
Could we create in folder
features/visualizer-threejs
file like index.ts and make all exports from this file? It will look like all what exported fromindex.ts
is like public. What not exported only for internal using.And maybe we could rename
NovaVisualizerWrapper.tsx → NovaVisualizer.tsx
In file client/src/features/visualizer-threejs/NovaVisualizerWrapper.tsx
from import NovaVisualizer from "./VisualizerInstance";
to import VisualizerInstance from "./VisualizerInstance";
Not requirement, just discussion.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the file name and made a new task for the store refactor:
#1196