mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-21 18:55:16 +02:00
refactor: replace button elements with Button component
This commit is contained in:
parent
da55c75e5e
commit
13b2e874f6
7 changed files with 38 additions and 16 deletions
|
|
@ -372,7 +372,7 @@ test("mock iframe response", async ({ page }) => {
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<h1>Mocked Widget</h1>
|
<h1>Mocked Widget</h1>
|
||||||
<button>Mocked Button</button>
|
<p>Mocked widget content</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`,
|
`,
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ use: {
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// HTML: <button data-testid="submit-btn">Submit</button>
|
// React: <Button data-testid="submit-btn">Submit</Button>
|
||||||
page.getByTestId("submit-btn");
|
page.getByTestId("submit-btn");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -549,6 +549,8 @@ Preload heavy bundles before they're needed to reduce perceived latency.
|
||||||
**Example: preload on hover/focus**
|
**Example: preload on hover/focus**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
function EditorButton({ onClick }: { onClick: () => void }) {
|
function EditorButton({ onClick }: { onClick: () => void }) {
|
||||||
const preload = () => {
|
const preload = () => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
|
@ -557,13 +559,13 @@ function EditorButton({ onClick }: { onClick: () => void }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<Button
|
||||||
onMouseEnter={preload}
|
onMouseEnter={preload}
|
||||||
onFocus={preload}
|
onFocus={preload}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
Open Editor
|
Open Editor
|
||||||
</button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
@ -1239,11 +1241,12 @@ function StaticContent() {
|
||||||
**For mutations:**
|
**For mutations:**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
import { useSWRMutation } from 'swr/mutation'
|
import { useSWRMutation } from 'swr/mutation'
|
||||||
|
|
||||||
function UpdateButton() {
|
function UpdateButton() {
|
||||||
const { trigger } = useSWRMutation('/api/user', updateUser)
|
const { trigger } = useSWRMutation('/api/user', updateUser)
|
||||||
return <button onClick={() => trigger()}>Update</button>
|
return <Button onClick={() => trigger()}>Update</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -1369,6 +1372,8 @@ Don't subscribe to dynamic state (searchParams, localStorage) if you only read i
|
||||||
**Incorrect: subscribes to all searchParams changes**
|
**Incorrect: subscribes to all searchParams changes**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
function ShareButton({ chatId }: { chatId: string }) {
|
function ShareButton({ chatId }: { chatId: string }) {
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
|
|
||||||
|
|
@ -1377,13 +1382,15 @@ function ShareButton({ chatId }: { chatId: string }) {
|
||||||
shareChat(chatId, { ref })
|
shareChat(chatId, { ref })
|
||||||
}
|
}
|
||||||
|
|
||||||
return <button onClick={handleShare}>Share</button>
|
return <Button onClick={handleShare}>Share</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Correct: reads on demand, no subscription**
|
**Correct: reads on demand, no subscription**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
function ShareButton({ chatId }: { chatId: string }) {
|
function ShareButton({ chatId }: { chatId: string }) {
|
||||||
const handleShare = () => {
|
const handleShare = () => {
|
||||||
const params = new URLSearchParams(window.location.search)
|
const params = new URLSearchParams(window.location.search)
|
||||||
|
|
@ -1391,7 +1398,7 @@ function ShareButton({ chatId }: { chatId: string }) {
|
||||||
shareChat(chatId, { ref })
|
shareChat(chatId, { ref })
|
||||||
}
|
}
|
||||||
|
|
||||||
return <button onClick={handleShare}>Share</button>
|
return <Button onClick={handleShare}>Share</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -1549,6 +1556,8 @@ If a side effect is triggered by a specific user action (submit, click, drag), r
|
||||||
**Incorrect: event modeled as state + effect**
|
**Incorrect: event modeled as state + effect**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
function Form() {
|
function Form() {
|
||||||
const [submitted, setSubmitted] = useState(false)
|
const [submitted, setSubmitted] = useState(false)
|
||||||
const theme = useContext(ThemeContext)
|
const theme = useContext(ThemeContext)
|
||||||
|
|
@ -1560,13 +1569,15 @@ function Form() {
|
||||||
}
|
}
|
||||||
}, [submitted, theme])
|
}, [submitted, theme])
|
||||||
|
|
||||||
return <button onClick={() => setSubmitted(true)}>Submit</button>
|
return <Button onClick={() => setSubmitted(true)}>Submit</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Correct: do it in the handler**
|
**Correct: do it in the handler**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
function Form() {
|
function Form() {
|
||||||
const theme = useContext(ThemeContext)
|
const theme = useContext(ThemeContext)
|
||||||
|
|
||||||
|
|
@ -1575,7 +1586,7 @@ function Form() {
|
||||||
showToast('Registered', theme)
|
showToast('Registered', theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
return <button onClick={handleSubmit}>Submit</button>
|
return <Button onClick={handleSubmit}>Submit</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ Preload heavy bundles before they're needed to reduce perceived latency.
|
||||||
**Example (preload on hover/focus):**
|
**Example (preload on hover/focus):**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
||||||
function EditorButton({ onClick }: { onClick: () => void }) {
|
function EditorButton({ onClick }: { onClick: () => void }) {
|
||||||
const preload = () => {
|
const preload = () => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
|
@ -20,13 +22,13 @@ function EditorButton({ onClick }: { onClick: () => void }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<Button
|
||||||
onMouseEnter={preload}
|
onMouseEnter={preload}
|
||||||
onFocus={preload}
|
onFocus={preload}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
Open Editor
|
Open Editor
|
||||||
</button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,12 @@ function StaticContent() {
|
||||||
**For mutations:**
|
**For mutations:**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
import { useSWRMutation } from 'swr/mutation'
|
import { useSWRMutation } from 'swr/mutation'
|
||||||
|
|
||||||
function UpdateButton() {
|
function UpdateButton() {
|
||||||
const { trigger } = useSWRMutation('/api/user', updateUser)
|
const { trigger } = useSWRMutation('/api/user', updateUser)
|
||||||
return <button onClick={() => trigger()}>Update</button>
|
return <Button onClick={() => trigger()}>Update</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ Don't subscribe to dynamic state (searchParams, localStorage) if you only read i
|
||||||
**Incorrect (subscribes to all searchParams changes):**
|
**Incorrect (subscribes to all searchParams changes):**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
function ShareButton({ chatId }: { chatId: string }) {
|
function ShareButton({ chatId }: { chatId: string }) {
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
|
|
||||||
|
|
@ -20,13 +22,15 @@ function ShareButton({ chatId }: { chatId: string }) {
|
||||||
shareChat(chatId, { ref })
|
shareChat(chatId, { ref })
|
||||||
}
|
}
|
||||||
|
|
||||||
return <button onClick={handleShare}>Share</button>
|
return <Button onClick={handleShare}>Share</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Correct (reads on demand, no subscription):**
|
**Correct (reads on demand, no subscription):**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
function ShareButton({ chatId }: { chatId: string }) {
|
function ShareButton({ chatId }: { chatId: string }) {
|
||||||
const handleShare = () => {
|
const handleShare = () => {
|
||||||
const params = new URLSearchParams(window.location.search)
|
const params = new URLSearchParams(window.location.search)
|
||||||
|
|
@ -34,6 +38,6 @@ function ShareButton({ chatId }: { chatId: string }) {
|
||||||
shareChat(chatId, { ref })
|
shareChat(chatId, { ref })
|
||||||
}
|
}
|
||||||
|
|
||||||
return <button onClick={handleShare}>Share</button>
|
return <Button onClick={handleShare}>Share</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ If a side effect is triggered by a specific user action (submit, click, drag), r
|
||||||
**Incorrect (event modeled as state + effect):**
|
**Incorrect (event modeled as state + effect):**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
function Form() {
|
function Form() {
|
||||||
const [submitted, setSubmitted] = useState(false)
|
const [submitted, setSubmitted] = useState(false)
|
||||||
const theme = useContext(ThemeContext)
|
const theme = useContext(ThemeContext)
|
||||||
|
|
@ -23,13 +25,15 @@ function Form() {
|
||||||
}
|
}
|
||||||
}, [submitted, theme])
|
}, [submitted, theme])
|
||||||
|
|
||||||
return <button onClick={() => setSubmitted(true)}>Submit</button>
|
return <Button onClick={() => setSubmitted(true)}>Submit</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Correct (do it in the handler):**
|
**Correct (do it in the handler):**
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
function Form() {
|
function Form() {
|
||||||
const theme = useContext(ThemeContext)
|
const theme = useContext(ThemeContext)
|
||||||
|
|
||||||
|
|
@ -38,7 +42,7 @@ function Form() {
|
||||||
showToast('Registered', theme)
|
showToast('Registered', theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
return <button onClick={handleSubmit}>Submit</button>
|
return <Button onClick={handleSubmit}>Submit</Button>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue