Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@

.topic-item {
display: flex;
width: 100%;
gap: 8px;
align-items: center;
padding: 8px;
Expand Down Expand Up @@ -156,7 +157,20 @@
margin-top: 20px;
}

button {
.modal-header button,
.navigation-buttons button {
margin: 5px;
}
}

/* TO DO: export this class for reuse */
.button-style-remover {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to make a comment about this, I intended to. I think it would be a good idea to have this as a global class in the project, since buttons have default stylings that we so often don't want. Do we have anything of the sort currently and do you think it'd be a good idea to add it? What do you think? cc: @adzhindzhi

background: none;
border: none;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
cursor: pointer;
text-align: inherit;
}
93 changes: 73 additions & 20 deletions packages/scratch-gui/src/components/debug-modal/debug-modal.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState, useCallback, useEffect} from 'react';
import {defineMessages, FormattedMessage} from 'react-intl';
import {defineMessages, FormattedMessage, useIntl} from 'react-intl';
import PropTypes from 'prop-types';
import ReactModal from 'react-modal';
import classNames from 'classnames';
Expand All @@ -12,12 +12,23 @@ import debugIconInverted from './icons/icon--debug-inverted.svg';
import closeIcon from './icons/icon--close.svg';
import prevIcon from './icons/icon--prev.svg';
import nextIcon from './icons/icon--next.svg';
import {KEY} from '../../lib/navigation-keys';

const messages = defineMessages({
title: {
id: 'gui.debugModal.title',
defaultMessage: 'Debugging | Getting Unstuck',
description: 'title for the debugging modal'
},
previous: {
id: 'gui.debugModal.previous',
defaultMessage: 'Previous',
description: 'Button to go to previous debugging topic'
},
next: {
id: 'gui.debugModal.next',
defaultMessage: 'Next',
description: 'Button to go to next debugging topic'
}
});

Expand Down Expand Up @@ -64,6 +75,36 @@ const DebugModal = ({isOpen, onClose = () => {}}) => {
onClose();
}, [onClose]);

const handleKeyDownSlides = useCallback(e => {
if ([KEY.ARROW_LEFT, KEY.ARROW_UP, KEY.ARROW_RIGHT, KEY.ARROW_DOWN].includes(e.key)) {
e.preventDefault();

setSelectedTopicIndex(prev => {
let nextIndex = prev;

if ((e.key === KEY.ARROW_LEFT || e.key === KEY.ARROW_UP) && prev > 0) {
nextIndex = prev - 1;
} else if ((e.key === KEY.ARROW_RIGHT || e.key === KEY.ARROW_DOWN) &&
prev < sections.length - 1) {
nextIndex = prev + 1;
}

if (nextIndex !== prev) {
logTopicChange(nextIndex);
Comment thread
KManolov3 marked this conversation as resolved.
}

return nextIndex;
});
}
}, []);

useEffect(() => {
if (!isOpen) return;

document.addEventListener('keydown', handleKeyDownSlides);
return () => document.removeEventListener('keydown', handleKeyDownSlides);
Comment thread
KManolov3 marked this conversation as resolved.
}, [isOpen, handleKeyDownSlides]);
Comment thread
kbangelov marked this conversation as resolved.

useEffect(() => {
if (isOpen) {
GA4.event({
Expand All @@ -75,6 +116,8 @@ const DebugModal = ({isOpen, onClose = () => {}}) => {

if (!isOpen) return null;

const intl = useIntl();

return (
<ReactModal
isOpen={isOpen}
Expand Down Expand Up @@ -105,13 +148,15 @@ const DebugModal = ({isOpen, onClose = () => {}}) => {
<div className={styles.modalContent} >
<div className={styles.topicList}>
{sections.map((section, index) => (
<div
<button
key={index}
className={classNames(styles.topicItem, {
[styles.active]: selectedTopicIndex === index
})}
className={classNames(styles.topicItem, styles.buttonStyleRemover,
{
[styles.active]: selectedTopicIndex === index
})}
// eslint-disable-next-line react/jsx-no-bind
onClick={() => handleTopicSelect(index)}
tabIndex={-1}
>
<div className={styles.debugIcon}>
<img
Expand All @@ -124,7 +169,7 @@ const DebugModal = ({isOpen, onClose = () => {}}) => {
<FormattedMessage
{...(section.sectionTitle ?? section.title)}
/>
</div>
</button>
))}
</div>
<div className={styles.infoContainer}>
Expand All @@ -143,22 +188,30 @@ const DebugModal = ({isOpen, onClose = () => {}}) => {
/>
</div>
<div className={styles.navigationButtons}>
<img
src={prevIcon}
alt="Previous"
<button
onClick={handlePrevious}
className={classNames(styles.previousIcon, {
[styles.hidden]: selectedTopicIndex === 0
})}
/>
<img
src={nextIcon}
alt="Next"
className={classNames(styles.buttonStyleRemover,
styles.previousIcon,
{[styles.hidden]: selectedTopicIndex === 0})}
>
<img
src={prevIcon}
alt={intl.formatMessage(messages.previous)}
/>
</button>
<button
onClick={handleNext}
className={classNames(styles.nextIcon, {
[styles.hidden]: selectedTopicIndex === sections.length - 1
})}
/>
className={classNames(styles.nextIcon,
styles.buttonStyleRemover,
{
[styles.hidden]: selectedTopicIndex === sections.length - 1
})}
>
<img
src={nextIcon}
alt={intl.formatMessage(messages.next)}
/>
</button>
</div>
</div>
</div>
Expand Down
Loading