Skip to content

Commit

Permalink
New checkpoints and questions, v2, closes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
davetaz committed Aug 28, 2024
1 parent 3448a68 commit 3795962
Show file tree
Hide file tree
Showing 7 changed files with 691 additions and 487 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Data Sharing Risk Assessment - Client",
"version": "1.6.0",
"version": "2.0.0",
"private": true,
"repository": {
"type": "git",
Expand Down
545 changes: 267 additions & 278 deletions client/public/json/checkpoints.json

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions client/src/CheckpointConsiderations.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ export default function CheckpointConsiderations() {
const dispatch = useDispatch();

// Initialize local state based on activeCheckpoint considerations or fallback to empty
const initialConsiderations = activeCheckpoint?.considerations?.items.map((item) => ({
text: item,
answer: false,
})) || [];
const getInitialConsiderations = () => {
return activeCheckpoint?.considerations?.items.map((item) => ({
text: item,
answer: false,
})) || [];
};

const [localConsiderations, setLocalConsiderations] = useState(getInitialConsiderations());

const [localConsiderations, setLocalConsiderations] = useState(activeCheckpointAnswer?.considerations || initialConsiderations);
useEffect(() => {
if (activeCheckpointAnswer && activeCheckpointAnswer.considerations) {
// If considerations already exist in the answer, use them
setLocalConsiderations(activeCheckpointAnswer.considerations);
} else {
// Otherwise, initialize with the current checkpoint's considerations
setLocalConsiderations(getInitialConsiderations());
}
}, [activeCheckpoint, activeCheckpointAnswer]);

const debouncedDispatch = useCallback(
debounce((updatedConsiderations) => {
Expand All @@ -27,13 +39,6 @@ export default function CheckpointConsiderations() {
[dispatch, activeCheckpointAnswer]
);

// Remove the effect that updates the local state when the activeCheckpointAnswer changes
// This ensures that the UI updates immediately without waiting for state sync
// If you still need to reset localConsiderations when a new checkpoint is loaded, consider a different approach to avoid the delay

if (!activeCheckpoint || !activeCheckpoint.considerations) return null;
if (!activeCheckpointAnswer || !activeCheckpointAnswer.option) return null;

const handleCheckboxChange = (index) => {
// Update local state immediately for UI update
const updatedConsiderations = localConsiderations.map((consideration, i) => (
Expand All @@ -46,6 +51,9 @@ export default function CheckpointConsiderations() {
debouncedDispatch(updatedConsiderations);
};

if (!activeCheckpoint || !activeCheckpoint.considerations) return null;
if (!activeCheckpointAnswer || !activeCheckpointAnswer.option) return null;

return (
<div className="considerations">
<div className="title">{activeCheckpoint.considerations.title}</div>
Expand All @@ -66,4 +74,4 @@ export default function CheckpointConsiderations() {
</ul>
</div>
);
}
}
8 changes: 5 additions & 3 deletions client/src/CheckpointOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ export default function CheckpointOptions() {

const handleOptionClick = (option) => {
try {
// Initialize considerations if they are not already in the activeCheckpointAnswer
const initialConsiderations = activeCheckpoint.considerations?.items.map((item) => ({
// Initialize considerations specific to the current checkpoint
const initialConsiderations = activeCheckpoint?.considerations?.items.map((item) => ({
text: item,
answer: false,
})) || [];

// Preserve existing considerations or initialize them
const considerations = activeCheckpointAnswer?.considerations || initialConsiderations;
const considerations = activeCheckpointAnswer?.considerations?.length
? activeCheckpointAnswer.considerations
: initialConsiderations;

const answer = {
id: checkpointID,
Expand Down
Loading

0 comments on commit 3795962

Please sign in to comment.