Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Finish user feedback

Tomas Valenta11611cfb88e7
diff --git a/components/Feedback/FeedbackButton.tsx b/components/Feedback/FeedbackButton.tsx
index 5ad44aec1..2b34a684e 100644
--- a/components/Feedback/FeedbackButton.tsx
+++ b/components/Feedback/FeedbackButton.tsx
@@ -1,5 +1,6 @@
import { MouseEvent } from 'react'
import {
+ Check,
MessageCircle,
} from 'lucide-react'
import clsx from 'clsx'
@@ -7,19 +8,31 @@ import clsx from 'clsx'
export interface Props {
onClick: (e: MouseEvent<HTMLButtonElement>) => void
isOpen: boolean
+ isFinished: boolean
}
function FeedbackButton({
onClick,
isOpen,
+ isFinished,
}: Props) {
return (
<button
className={clsx({ 'border-white/10 text-gray-100': isOpen, 'border-white/5 text-gray-400': !isOpen }, 'group ml-auto flex items-center space-x-1 cursor-pointer py-1 px-2 rounded-md bg-gray-900 border border-white/5 hover:border-white/10 transition-all')}
onMouseDown={onClick}
>
- <MessageCircle size={14} className="" />
- <span className="text-sm">Send feedback to CEO</span>
+ {isFinished &&
+ <>
+ <Check size={14} className="" />
+ <span className="text-sm">Thank you!</span>
+ </>
+ }
+ {!isFinished &&
+ <>
+ <MessageCircle size={14} className="" />
+ <span className="text-sm">Send feedback to CEO</span>
+ </>
+ }
</button>
)
}
diff --git a/components/Feedback/FeedbackModal.tsx b/components/Feedback/FeedbackModal.tsx
index 7a67ebcb3..458bfc8b4 100644
--- a/components/Feedback/FeedbackModal.tsx
+++ b/components/Feedback/FeedbackModal.tsx
@@ -1,25 +1,25 @@
import { useUser } from '@supabase/auth-helpers-react'
import { FormEvent, MouseEvent, useRef, useState } from 'react'
import { useOnClickOutside } from 'usehooks-ts'
+import { Send } from 'lucide-react'
import Textarea from 'components/Textarea'
import SpinnerIcon from 'components/Spinner'
import { useAddFeedback } from 'hooks/useAddFeedback'
-import clsx from 'clsx'
export interface Props {
isOpen: boolean
onClose: () => any
+ onSend?: () => void
}
-function FeedbackModal({ isOpen, onClose }: Props) {
+function FeedbackModal({ isOpen, onClose, onSend }: Props) {
const [feedback, setFeedback] = useState('')
const [isSavingFeedback, setIsSavingFeedback] = useState(false)
const user = useUser()
const ref = useRef<HTMLFormElement>(null)
useOnClickOutside(ref, onClose, 'mousedown')
-
const addFeedback = useAddFeedback()
async function saveFeedback(
@@ -33,9 +33,10 @@ function FeedbackModal({ isOpen, onClose }: Props) {
setIsSavingFeedback(true)
await addFeedback(feedback)
-
setIsSavingFeedback(false)
onClose()
+ setFeedback('')
+ onSend?.()
}
return (
@@ -43,15 +44,18 @@ function FeedbackModal({ isOpen, onClose }: Props) {
{isOpen &&
<form
ref={ref}
- autoComplete="of"
+ autoCapitalize="off"
+ autoCorrect="on"
+ autoComplete="off"
className="
flex
p-3
border
z-50
bg-gray-900
- border-gray-600
+ border-gray-800
w-[400px]
+ shadow-lg
rounded
absolute
flex-col
@@ -63,16 +67,23 @@ function FeedbackModal({ isOpen, onClose }: Props) {
>
<Textarea
value={feedback}
+ placeholder="What should we improve?"
onChange={e => setFeedback(e.target.value)}
isOpen={isOpen}
/>
<button
- className={clsx({ 'border-white/10 text-gray-100': isOpen, 'border-white/5 text-gray-400': !isOpen }, 'group ml-auto flex items-center space-x-1 cursor-pointer py-1 px-2 rounded-md bg-gray-900 border border-white/5 hover:border-white/10 transition-all')}
- onMouseDown={saveFeedback}
+ className="flex items-center space-x-2 rounded-md bg-gray-200 py-1 px-2 text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white cursor-pointer transition-all disabled:bg-gray-400 disabled:cursor-not-allowed"
+ onClick={saveFeedback}
disabled={isSavingFeedback || feedback.trim() === ''}
>
- {isSavingFeedback ? <SpinnerIcon className="text-white" /> : null}
- {!isSavingFeedback && <span className="text-sm">Send</span>}
+ {isSavingFeedback &&
+ <SpinnerIcon />
+ }
+
+ {!isSavingFeedback &&
+ <Send size="14px" />
+ }
+ <span className="text-sm">Send</span>
</button>
</form>
}
diff --git a/components/Feedback/index.tsx b/components/Feedback/index.tsx
index 6bfe22ef4..15fff702b 100644
--- a/components/Feedback/index.tsx
+++ b/components/Feedback/index.tsx
@@ -1,3 +1,4 @@
+import useExpiringState from 'hooks/useExpiringState'
import { useState } from 'react'
import FeedbackButton from './FeedbackButton'
@@ -5,19 +6,22 @@ import FeedbackModal from './FeedbackModal'
function Feedback() {
const [isFeedbackVisible, setIsFeedbackVisible] = useState(false)
+ const [isFinished, setIsFinished] = useExpiringState({ defaultValue: false, timeout: 4000 })
return (
<div className="flex flex-col items-end flex-1">
<div>
<FeedbackButton
- isOpen={isFeedbackVisible}
+ isOpen={isFeedbackVisible || isFinished}
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
setIsFeedbackVisible(f => !f)
}}
+ isFinished={isFinished}
/>
<FeedbackModal
+ onSend={() => setIsFinished(true)}
isOpen={isFeedbackVisible}
onClose={() => setIsFeedbackVisible(f => !f)}
/>
diff --git a/components/Textarea.tsx b/components/Textarea.tsx
index 8865b22ec..5cbd708c4 100644
--- a/components/Textarea.tsx
+++ b/components/Textarea.tsx
@@ -24,6 +24,9 @@ function Textarea({ value = '', className, placeholder, onChange, isOpen }: Prop
ref={ref}
placeholder={placeholder}
value={value}
+ autoCapitalize="off"
+ autoCorrect="on"
+ autoComplete="off"
className={clsx(
'w-full',
'px-2.5',
@@ -33,13 +36,15 @@ function Textarea({ value = '', className, placeholder, onChange, isOpen }: Prop
'min-h-[200px]',
'focus:outline-none',
'font-sans',
- 'border-transparent',
- 'bg-gray-950/40',
+ 'border-gray-700',
+ 'focus:border-gray-500',
+ 'bg-gray-800/40',
'outline-none',
+ 'ring-0',
'transition-colors',
'text-sm',
'text-white',
- 'placeholder:text-gray-100',
+ 'placeholder:text-gray-600',
className,
)}
onChange={onChange}
diff --git a/hooks/useExpiringState.ts b/hooks/useExpiringState.ts
new file mode 100644
index 000000000..49a531880
--- /dev/null
+++ b/hooks/useExpiringState.ts
@@ -0,0 +1,30 @@
+import debounce from 'lodash.debounce'
+import { useCallback, useMemo, useState } from 'react'
+
+export interface Props<T> {
+ defaultValue: T
+ timeout: number // in ms
+}
+
+function useExpiringState<T>({
+ defaultValue,
+ timeout,
+}: Props<T>): [T, (value: T) => void] {
+ const [value, setValue] = useState(defaultValue)
+
+ const enqueExpiration = useMemo(() => debounce(() => {
+ setValue(defaultValue)
+ }, timeout, {
+ leading: false,
+ trailing: true,
+ }), [timeout, defaultValue])
+
+ const set = useCallback((newValue: T) => {
+ setValue(newValue)
+ enqueExpiration()
+ }, [enqueExpiration])
+
+ return [value, set]
+}
+
+export default useExpiringState
diff --git a/package-lock.json b/package-lock.json
index a03507c82..2aa4e668e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -34,6 +34,7 @@
"http-proxy-middleware": "^3.0.0-beta.1",
"immer": "^9.0.19",
"jsonpath-plus": "^7.2.0",
+ "lodash.debounce": "^4.0.8",
"lucide-react": "^0.240.0",
"micro-cors": "^0.1.1",
"nanoid": "^4.0.1",
@@ -61,6 +62,7 @@
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.9",
+ "@types/lodash.debounce": "^4.0.7",
"@types/micro-cors": "^0.1.3",
"@types/node": "^18.14.6",
"@types/react": "^18.0.28",
@@ -1807,6 +1809,21 @@
"resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.2.tgz",
"integrity": "sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA=="
},
+ "node_modules/@types/lodash": {
+ "version": "4.14.195",
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.195.tgz",
+ "integrity": "sha512-Hwx9EUgdwf2GLarOjQp5ZH8ZmblzcbTBC2wtQWNKARBSxM9ezRIAUpeDTgoQRAFB0+8CNWXVA9+MaSOzOF3nPg==",
+ "dev": true
+ },
+ "node_modules/@types/lodash.debounce": {
+ "version": "4.0.7",
+ "resolved": "https://registry.npmjs.org/@types/lodash.debounce/-/lodash.debounce-4.0.7.tgz",
+ "integrity": "sha512-X1T4wMZ+gT000M2/91SYj0d/7JfeNZ9PeeOldSNoE/lunLeQXKvkmIumI29IaKMotU/ln/McOIvgzZcQ/3TrSA==",
+ "dev": true,
+ "dependencies": {
+ "@types/lodash": "*"
+ }
+ },
"node_modules/@types/markdown-it": {
"version": "12.2.3",
"resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-12.2.3.tgz",
@@ -5535,6 +5552,11 @@
"resolved": "https://registry.npmjs.org/lodash.curry/-/lodash.curry-4.1.1.tgz",
"integrity": "sha512-/u14pXGviLaweY5JI0IUzgzF2J6Ne8INyzAZjImcryjgkZ+ebruBxy2/JaOOkTqScddcYtakjhSaeemV8lR0tA=="
},
+ "node_modules/lodash.debounce": {
+ "version": "4.0.8",
+ "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
+ "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow=="
+ },
"node_modules/lodash.flow": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/lodash.flow/-/lodash.flow-3.5.0.tgz",
diff --git a/package.json b/package.json
index b649a15c5..f6414a72c 100644
--- a/package.json
+++ b/package.json
@@ -66,6 +66,7 @@
"http-proxy-middleware": "^3.0.0-beta.1",
"immer": "^9.0.19",
"jsonpath-plus": "^7.2.0",
+ "lodash.debounce": "^4.0.8",
"lucide-react": "^0.240.0",
"micro-cors": "^0.1.1",
"nanoid": "^4.0.1",
@@ -79,6 +80,7 @@
"prosemirror-view": "^1.30.2",
"react": "18.2.0",
"react-dom": "18.2.0",
+ "react-json-view": "^1.21.3",
"react-markdown": "^8.0.5",
"react-textarea-autosize": "^8.4.0",
"rpc-websocket-client": "^1.1.4",
@@ -88,11 +90,11 @@
"tippy.js": "^6.3.7",
"tiptap-markdown": "^0.7.2",
"usehooks-ts": "^2.9.1",
- "zustand": "^4.3.5",
- "react-json-view": "^1.21.3"
+ "zustand": "^4.3.5"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.9",
+ "@types/lodash.debounce": "^4.0.7",
"@types/micro-cors": "^0.1.3",
"@types/node": "^18.14.6",
"@types/react": "^18.0.28",
@@ -119,4 +121,4 @@
"react-dom": "$react-dom"
}
}
-}
\ No newline at end of file
+}
diff --git a/pages/sign.tsx b/pages/sign.tsx
index 1b756e762..a2dc941f1 100644
--- a/pages/sign.tsx
+++ b/pages/sign.tsx
@@ -52,7 +52,7 @@ function SignIn() {
</h2>
<div className="sm:mx-auto sm:w-full sm:max-w-sm justify-center flex">
<button
- className="flex items-center space-x-2 rounded-md bg-white px-3.5 py-2.5 text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
+ className="flex items-center space-x-2 rounded-md bg-gray-200 px-3.5 py-2.5 text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white transition-all"
onClick={signInWithGitHub}
disabled={isLoading}
>
@@ -62,7 +62,7 @@ function SignIn() {
{!isLoading &&
<Github size={16} />
}
- <span>Continue with GitHub</span>
+ <span className="">Continue with GitHub</span>
</button>
</div>
</div>