Skip to content

Commit

Permalink
Better error popups
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanger2000 committed Mar 29, 2023
1 parent 5defeb7 commit a0c53e5
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 223 deletions.
113 changes: 1 addition & 112 deletions src/appComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { WelcomeScreen } from './components/welcomeScreen'
import { TitleBar } from './components/titlebar'
import { BottomTerminal } from './components/terminal'
import { throttleCallback } from './components/componentUtils'
import { ErrorPopup } from './components/errors'

const customStyles = {
overlay: {
Expand All @@ -57,116 +58,6 @@ const customStyles = {
},
}

function ErrorPopup() {
const showError = useAppSelector(gsel.getShowErrors)
const dispatch = useAppDispatch()

return (
<Modal
isOpen={showError}
onRequestClose={() => {
dispatch(gs.closeError())
}}
style={customStyles}
>
<div className="errorPopup">
<div className="errorPopup__title">
<div className="errorPopup__title_text">
We ran into a problem
</div>
<div
className="errorPopup__title_close"
onClick={() => dispatch(gs.closeError())}
>
<FontAwesomeIcon icon={faClose} />
</div>
</div>
<div className="errorPopup__body">
Something unexpected happened. Please try again later. If
this continues, please contact [email protected].
<br />
</div>
</div>
</Modal>
)
}

function RateLimitPopup() {
const showError = useAppSelector(gsel.getShowRateLimit)
const dispatch = useAppDispatch()

return (
<Modal
isOpen={showError}
onRequestClose={() => {
dispatch(gs.closeRateLimit())
}}
style={customStyles}
>
<div className="errorPopup">
<div className="errorPopup__title">
<div className="errorPopup__title_text">
You're going a bit fast...
</div>
<div
className="errorPopup__title_close"
onClick={() => dispatch(gs.closeError())}
>
<FontAwesomeIcon icon={faClose} />
</div>
</div>
<div className="errorPopup__body">
It seems like you're making a high rate of requests. Please
slow down and try again in a minute or so. If you believe
this is an error, contact us at [email protected]
<br />
</div>
</div>
</Modal>
)
}

function NoAuthRateLimitPopup() {
const showError = useAppSelector(gsel.getShowNoAuthRateLimit)
const dispatch = useAppDispatch()

return (
<Modal
isOpen={showError}
onRequestClose={() => {
dispatch(gs.closeNoAuthRateLimit())
}}
style={customStyles}
>
<div className="errorPopup">
<div className="errorPopup__title">
<div className="errorPopup__title_text">
Maximum Capacity
</div>
<div
className="errorPopup__title_close"
onClick={() => dispatch(gs.closeNoAuthRateLimit())}
>
<FontAwesomeIcon icon={faClose} />
</div>
</div>
<div className="errorPopup__body">
We're getting more traffic than we can handle right now.
Please try again in one minute. To avoid these limits, you
can optionally upgrade to{' '}
<a
className="pay-link"
onClick={() => dispatch(ts.upgradeCursor(null))}
>
pro
</a>
.
</div>
</div>
</Modal>
)
}

function SSHPopup() {
const showRemotePopup = useAppSelector(gsel.getShowRemotePopup)
const remoteCommand = useAppSelector(gsel.getRemoteCommand)
Expand Down Expand Up @@ -438,8 +329,6 @@ export function App() {
</div>
<ChatPopup />
<ErrorPopup />
<RateLimitPopup />
<NoAuthRateLimitPopup />
<SettingsPopup />
<FeedbackArea />
<SSHPopup />
Expand Down
129 changes: 129 additions & 0 deletions src/components/errors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { useAppDispatch, useAppSelector } from '../app/hooks';
import {closeError} from '../features/globalSlice'
import {getShowErrors, getError} from '../features/selectors';
import { faClose } from '@fortawesome/pro-regular-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import Modal from 'react-modal'
import { NoAuthRateLimitError, NotLoggedInError, OpenAIError } from '../utils';
import { CursorLogin, OpenAIPanel } from './settingsPane';

const customStyles = {
overlay: {
backgroundColor: 'rgba(0, 0, 0, 0.1)',
display: 'flex',
alignItems: 'center',
zIndex: 10000,
},
content: {
padding: 'none',
top: '150px',
bottom: 'none',
background: 'none',
border: 'none',
width: 'auto',
height: 'auto',
marginLeft: 'auto',
marginRight: 'auto',
maxWidth: '700px',
},
}

export function ErrorPopup() {
const showError = useAppSelector(getShowErrors)
const error = useAppSelector(getError)
const dispatch = useAppDispatch()

if (error == null) {
return (
<Modal
isOpen={showError}
onRequestClose={() => {
dispatch(closeError())
}}
style={customStyles}
>
<div className="errorPopup">
<div className="errorPopup__title">
<div className="errorPopup__title_text">
We ran into a problem
</div>
<div
className="errorPopup__title_close"
onClick={() => dispatch(closeError())}
>
<FontAwesomeIcon icon={faClose} />
</div>
</div>
<div className="errorPopup__body">
Something unexpected happened. Please try again later. If
this continues, please contact [email protected].
<br />
</div>
</div>
</Modal>
)
} else if (error instanceof NotLoggedInError) {
return (
<Modal
isOpen={showError}
onRequestClose={() => {
dispatch(closeError())
}}
style={customStyles}
>
<div className="errorPopup">
<div className="errorPopup__title">
<div className="errorPopup__title_text">
{error.title}
</div>
<div
className="errorPopup__title_close"
onClick={() => dispatch(closeError())}
>
<FontAwesomeIcon icon={faClose} />
</div>
</div>
<div className="errorPopup__body">
{error.message}
<br />
Try logging in here:
<CursorLogin showSettings={false}/>
<br/>
Or try using an OpenAI key:
<OpenAIPanel />
</div>
</div>
</Modal>
)
} else {
return (
<Modal
isOpen={showError}
onRequestClose={() => {
dispatch(closeError())
}}
style={customStyles}
>
<div className="errorPopup">
<div className="errorPopup__title">
<div className="errorPopup__title_text">
{error.title}
</div>
<div
className="errorPopup__title_close"
onClick={() => dispatch(closeError())}
>
<FontAwesomeIcon icon={faClose} />
</div>
</div>
<div className="errorPopup__body">
{error.message}
<br />
</div>
</div>
</Modal>
)
}


}
Loading

0 comments on commit a0c53e5

Please sign in to comment.