-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/organize state #212
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
Open
meganrm
wants to merge
16
commits into
main
Choose a base branch
from
fix/organize-state
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix/organize state #212
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
69c58f7
equ plot shows Ki
meganrm 96023f7
format
meganrm ed462c2
separate context
meganrm 4bf2562
new context
meganrm 01751c9
add claude settings
meganrm 93669f9
ignore claude settings
meganrm e0b9f95
remove claude settings
meganrm 606713f
Merge branch 'main' of https://github.com/simularium/binding-sim-edu …
meganrm 8f18f1f
revert to main
meganrm a7fb9e1
fix bug where plots were getting added with only 0,0 as a value
meganrm c905ea3
Potential fix for pull request finding
meganrm 1035c38
use satisfies
meganrm a1f8309
move into docs folder
meganrm 46ed355
remove personal notification setting
meganrm 0a92a61
remove whitespace
meganrm d7736e6
use createContext
meganrm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,3 +22,4 @@ dist-ssr | |
| *.njsproj | ||
| *.sln | ||
| *.sw? | ||
| .claude | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # binding-sim-edu — Claude Code Guidelines | ||
|
|
||
| An educational web app for exploring molecular binding simulations, built for the Allen Institute for Cell Science. Runs interactive binding simulations via the Simularium viewer, guides students through experiments, and displays analysis results (concentration plots, equilibrium graphs). | ||
|
|
||
| --- | ||
|
|
||
| ## Quick Reference | ||
|
|
||
| ``` | ||
| binding-sim-edu/ | ||
| ├── CLAUDE.md <- this file | ||
| ├── CONTEXT_ORGANIZATION.md <- context/state architecture docs | ||
| ├── src/ | ||
| │ ├── components/ <- UI components | ||
| │ ├── hooks/ <- React hooks (incl. useSimulationContext.ts) | ||
| │ ├── simulation/ <- simulation engine logic | ||
| │ ├── constants/ <- app constants | ||
| │ ├── content/ <- module content / copy | ||
| │ ├── types/ <- shared TypeScript types | ||
| │ └── utils/ <- pure utility functions | ||
| └── .claude/skills/ <- Claude Code skills | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## State Architecture | ||
|
|
||
| Context is split into three providers — see `CONTEXT_ORGANIZATION.md` for full details: | ||
|
|
||
| - **SimulariumUiContext** — page, module, section, viewport type, quiz, progression, completed modules | ||
| - **SimulariumSimulationContext** — playback, controller, trajectory, concentrations, agents, handlers | ||
| - **SimulariumAnalysisContext** — recorded concentrations, analysis reset | ||
|
|
||
| Always import via the typed hooks, not `useContext` directly: | ||
| ```tsx | ||
| import { useSimulariumUi, useSimulariumSimulation, useSimulariumAnalysis } from "../hooks/useSimulationContext"; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Build Commands | ||
|
|
||
| | What | Command | | ||
| | ---------- | ------------------- | | ||
| | Dev server | `bun run dev` | | ||
| | Build | `bun run build` | | ||
| | Lint | `bun run lint` | | ||
| | Type check | `bunx tsc --noEmit` | | ||
|
|
||
| --- | ||
|
|
||
| ## Code Standards | ||
|
|
||
| ### General | ||
| - Prefer editing existing files over creating new ones | ||
| - No speculative abstractions — build for what's needed now | ||
| - No commented-out code | ||
| - No `console.log` / debug prints left in production code | ||
| - Destructured keys in alphabetical order (imports, params, props) | ||
|
|
||
| ### TypeScript / React | ||
| - All public APIs must have explicit types | ||
| - Prefer `interface` over `type` for object shapes | ||
| - No `any` — use `unknown` + narrowing if type is genuinely unknown | ||
| - Components own their props types — don't scatter them into shared types files | ||
| - Custom hooks for shared stateful logic, plain functions for shared pure logic | ||
| - Co-locate component, styles, and tests in the same directory | ||
|
|
||
| ### Import order | ||
| External libs → internal aliases → relative imports, each group alphabetical. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Context Organization | ||
|
|
||
| The app context has been organized into three separate contexts for better separation of concerns and easier state management. | ||
|
|
||
| ## Contexts | ||
|
|
||
| ### SimulariumUiContext | ||
| Contains UI-related state: | ||
| - `page`, `setPage` - Current page number | ||
| - `module`, `setModule` - Current module | ||
| - `progressionElement` - Current progression element for hints | ||
| - `quizQuestion` - Current quiz question | ||
| - `section` - Current section | ||
| - `viewportType`, `setViewportType` - Lab vs Simulation view | ||
| - `completedModules`, `addCompletedModule` - Track module completion | ||
| - `resetAllState()` - Reset all application state | ||
|
Contributor
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. Odd that this lives in a specific branch if it resets them all but I guess it has to go somewhere |
||
|
|
||
| ### SimulariumSimulationContext | ||
| Contains simulation-related state: | ||
| - `isPlaying`, `setIsPlaying` - Playback state | ||
| - `simulariumController` - Viewer controller | ||
| - `trajectoryName` - Current trajectory | ||
| - `timeFactor`, `timeUnit` - Time settings | ||
| - `viewportSize`, `setViewportSize` - Viewer dimensions | ||
| - `productName`, `adjustableAgentName` - Agent info | ||
| - `currentProductionConcentration`, `fixedAgentStartingConcentration`, `maxConcentration` - Concentration values | ||
| - `getAgentColor()` - Color mapping | ||
| - `handleMixAgents()`, `handleStartExperiment()`, `handleTimeChange()`, `handleTrajectoryChange()` - Handlers | ||
|
|
||
| ### SimulariumAnalysisContext | ||
| Contains analysis and recorded data: | ||
| - `recordedConcentrations` - User-recorded concentration values | ||
| - `resetAnalysisState()` - Clear recorded data without resetting UI | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Using the Hooks | ||
|
|
||
| Import the hooks instead of using `useContext` directly: | ||
|
|
||
| ```tsx | ||
| import { | ||
| useSimulariumUi, | ||
| useSimulariumSimulation, | ||
| useSimulariumAnalysis, | ||
| } from "../hooks/useSimulationContext"; | ||
|
|
||
| const MyComponent = () => { | ||
| const { page, setPage } = useSimulariumUi(); | ||
| const { isPlaying, setIsPlaying } = useSimulariumSimulation(); | ||
| const { recordedConcentrations } = useSimulariumAnalysis(); | ||
|
|
||
| // Use the values... | ||
| }; | ||
| ``` | ||
|
|
||
| ### Using the Reset Button | ||
|
|
||
| A `ResetButton` component is available for resetting state: | ||
|
|
||
| ```tsx | ||
| import ResetButton from "../shared/ResetButton"; | ||
|
|
||
| // Reset all state (UI + simulation + analysis) | ||
| <ResetButton resetAll /> | ||
|
|
||
| // Reset only analysis data | ||
| <ResetButton /> | ||
|
|
||
| // Custom label | ||
| <ResetButton resetAll>Start Over</ResetButton> | ||
| ``` | ||
|
|
||
| ## Benefits | ||
|
|
||
| 1. **Clearer separation of concerns** - UI, simulation, and analysis state are separate | ||
| 2. **Easier to reset** - Individual contexts can be reset without affecting others | ||
| 3. **Better performance** - Components only re-render when their specific context changes | ||
| 4. **Type safety** - Each context has its own strongly-typed interface | ||
| 5. **Cleaner imports** - Use hooks instead of context + useContext everywhere | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.