Skip to content

Commit

Permalink
Re-enable action buttons after errors and show error alert
Browse files Browse the repository at this point in the history
This is a temporary solution, we'll be switching to Apollo 3 and
mutation hooks
  • Loading branch information
alse committed Sep 22, 2022
1 parent 1b1af55 commit 17c39b7
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 111 deletions.
12 changes: 7 additions & 5 deletions src/components/Arguments/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,20 @@ export const ActionButton: React.FC<InteractionButtonProps> = ({
active = true,
onClick,
}) => {
const { project, active: activeEditor, getActiveCode } = useProject();
const {
project,
active: activeEditor,
getActiveCode,
showSavingMessage,
} = useProject();
const label = getLabel(type, project, activeEditor);
const { isSavingCode } = useProject();
const sendingTransaction = false;
const code = getActiveCode()[0].trim();
return (
<Controls>
<Button
onClick={onClick}
Icon={FaArrowCircleRight}
disabled={isSavingCode || !active || code.length === 0}
isLoading={sendingTransaction}
disabled={showSavingMessage || !active || code.length === 0}
>
{label}
</Button>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Arguments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ type ProcessingArgs = {
};

const useTemplateType = (): ProcessingArgs => {
const { isSavingCode } = useProject();
const { showSavingMessage } = useProject();
const {
createScriptExecution,
createTransactionExecution,
updateAccountDeployedCode,
} = useProject();

return {
disabled: isSavingCode,
disabled: showSavingMessage,
scriptFactory: createScriptExecution,
transactionFactory: createTransactionExecution,
contractDeployment: updateAccountDeployedCode,
Expand Down Expand Up @@ -218,7 +218,7 @@ const Arguments: React.FC<ArgumentsProps> = (props) => {
const {
project,
active,
isSavingCode,
showSavingMessage,
lastSigners,
// updateAccountDeployedCode
} = useProject();
Expand Down Expand Up @@ -356,7 +356,7 @@ const Arguments: React.FC<ArgumentsProps> = (props) => {
let statusIcon = isOk ? <FaRegCheckCircle /> : <FaRegTimesCircle />;
let statusMessage = isOk ? 'Ready' : 'Fix errors';

const progress = isSavingCode || processingStatus;
const progress = showSavingMessage || processingStatus;

if (progress) {
statusIcon = <FaSpinner className="spin" />;
Expand Down
4 changes: 2 additions & 2 deletions src/components/CadenceEditor/ControlPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ControlPanel: React.FC<ControlPanelProps> = (props) => {
// ===========================================================================
// GLOBAL HOOKS
const { languageClient } = useContext(CadenceCheckerContext);
const { project, active, isSavingCode } = useProject();
const { project, active, showSavingMessage } = useProject();

// HOOKS -------------------------------------------------------------------
const [executionArguments, setExecutionArguments] = useState({});
Expand Down Expand Up @@ -366,7 +366,7 @@ const ControlPanel: React.FC<ControlPanelProps> = (props) => {
break;
}

const progress = isSavingCode || processingStatus;
const progress = showSavingMessage || processingStatus;
if (progress) {
statusIcon = <FaSpinner className="spin" />;
statusMessage = 'Please, wait...';
Expand Down
4 changes: 2 additions & 2 deletions src/components/CadenceEditor/ControlPanel/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ export const getLabel = (
};

export const useTemplateType = (): ProcessingArgs => {
const { isSavingCode } = useProject();
const { showSavingMessage } = useProject();
const {
createScriptExecution,
createTransactionExecution,
updateAccountDeployedCode,
} = useProject();

return {
disabled: isSavingCode,
disabled: showSavingMessage,
scriptFactory: createScriptExecution,
transactionFactory: createTransactionExecution,
contractDeployment: updateAccountDeployedCode,
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Editor/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ const ShareSaveButton = ({
onSave,
icon,
}: ShareSaveButtonProps) => {
const { isSavingCode } = useProject();
const { showSavingMessage } = useProject();
return (
<Box sx={{ marginRight: '0.5rem' }}>
{showShare ? (
<ShareButton url={url} />
) : (
<FlowButton
onClick={() => onSave()}
disabled={isSavingCode}
disabled={showSavingMessage}
Icon={icon}
>
{saveText}
Expand Down
6 changes: 3 additions & 3 deletions src/containers/Editor/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const EditorLayout: React.FC = () => {
const {
project,
updateProject,
isSavingCode,
showSavingMessage,
isLoading,
active,
setSelectedResourceAccount,
Expand Down Expand Up @@ -197,7 +197,7 @@ const EditorLayout: React.FC = () => {
}}
>
<AnimatePresence exitBeforeEnter>
{project && project.persist && isSavingCode && (
{project && project.persist && showSavingMessage && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
Expand All @@ -209,7 +209,7 @@ const EditorLayout: React.FC = () => {
Autosaving...
</motion.div>
)}
{project && project.persist && !isSavingCode && (
{project && project.persist && !showSavingMessage && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
Expand Down
Loading

0 comments on commit 17c39b7

Please sign in to comment.