Skip to content

Commit 461463a

Browse files
committed
more clean up
1 parent 586874d commit 461463a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+340
-352
lines changed

src/src/app/pages/[slug]/page.tsx

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
11
'use client'
2-
import React from 'react'
32
import { VoloCmsKitContentsPageDto } from '@/client'
43
import { PageView } from '@/components/page/PageView'
4+
import { Alert, AlertDescription } from '@/components/ui/alert'
55
import { Button } from '@/components/ui/button'
66
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
7-
import { Alert, AlertDescription } from '@/components/ui/alert'
87
import Error from '@/components/ui/Error'
98
import Loader from '@/components/ui/Loader'
109
import { usePageBySlug } from '@/lib/hooks/usePages'
1110
import { AlertTriangle, Home, RefreshCw, Search } from 'lucide-react'
1211
import Link from 'next/link'
1312
import { useParams, useRouter } from 'next/navigation'
14-
import { useEffect, useState } from 'react'
13+
import React, { useEffect, useState } from 'react'
1514

1615
export default function PageViewPage() {
1716
const params = useParams()
1817
const router = useRouter()
1918
const slug = params.slug as string
2019
const [retryCount, setRetryCount] = useState(0)
2120

22-
const {
23-
data: page,
24-
isLoading,
25-
isError,
26-
error,
27-
refetch
28-
} = usePageBySlug(slug)
21+
const { data: page, isLoading, isError, error, refetch } = usePageBySlug(slug)
2922

3023
// Handle retry logic
3124
const handleRetry = () => {
32-
setRetryCount(prev => prev + 1)
25+
setRetryCount((prev) => prev + 1)
3326
refetch()
3427
}
3528

@@ -52,12 +45,17 @@ export default function PageViewPage() {
5245

5346
// Handle different types of errors gracefully
5447
if (isError) {
55-
const errorMessage = error && typeof error === 'object' && 'message' in error
56-
? String(error.message)
57-
: 'An unexpected error occurred'
58-
48+
const errorMessage =
49+
error && typeof error === 'object' && 'message' in error
50+
? String(error.message)
51+
: 'An unexpected error occurred'
52+
5953
// Network or server errors
60-
if (errorMessage.includes('fetch') || errorMessage.includes('network') || errorMessage.includes('timeout')) {
54+
if (
55+
errorMessage.includes('fetch') ||
56+
errorMessage.includes('network') ||
57+
errorMessage.includes('timeout')
58+
) {
6159
return (
6260
<div className="min-h-screen bg-background flex items-center justify-center p-4">
6361
<Card className="w-full max-w-md">
@@ -67,17 +65,16 @@ export default function PageViewPage() {
6765
</div>
6866
<CardTitle>Connection Error</CardTitle>
6967
<CardDescription>
70-
We're having trouble connecting to our servers. This might be a temporary issue.
68+
We&apos;re having trouble connecting to our servers. This might be a temporary issue.
7169
</CardDescription>
7270
</CardHeader>
7371
<CardContent className="space-y-4">
7472
<Alert>
7573
<AlertTriangle className="h-4 w-4" />
7674
<AlertDescription>
77-
{retryCount > 0
75+
{retryCount > 0
7876
? `Attempt ${retryCount + 1} failed. Please try again.`
79-
: 'Please check your internet connection and try again.'
80-
}
77+
: 'Please check your internet connection and try again.'}
8178
</AlertDescription>
8279
</Alert>
8380
<div className="flex gap-2">
@@ -107,12 +104,14 @@ export default function PageViewPage() {
107104
</div>
108105
<CardTitle>Page Not Found</CardTitle>
109106
<CardDescription>
110-
The page you're looking for doesn't exist or may have been moved.
107+
The page you&apos;re looking for doesn&apos;t exist or may have been moved.
111108
</CardDescription>
112109
</CardHeader>
113110
<CardContent className="space-y-4">
114111
<div className="text-sm text-muted-foreground">
115-
<p>Slug: <code className="bg-muted px-1 rounded">{slug}</code></p>
112+
<p>
113+
Slug: <code className="bg-muted px-1 rounded">{slug}</code>
114+
</p>
116115
</div>
117116
<div className="flex gap-2">
118117
<Button asChild className="flex-1">
@@ -147,9 +146,7 @@ export default function PageViewPage() {
147146
<CardContent className="space-y-4">
148147
<Alert>
149148
<AlertTriangle className="h-4 w-4" />
150-
<AlertDescription>
151-
{errorMessage}
152-
</AlertDescription>
149+
<AlertDescription>{errorMessage}</AlertDescription>
153150
</Alert>
154151
<div className="flex gap-2">
155152
<Button onClick={handleRetry} className="flex-1">
@@ -220,9 +217,10 @@ class ErrorBoundary extends React.Component<
220217
}
221218

222219
static getDerivedStateFromError(error: unknown) {
223-
const errorObj = error && typeof error === 'object' && 'message' in error
224-
? error as Error
225-
: { message: String(error), name: 'Error' } as Error
220+
const errorObj =
221+
error && typeof error === 'object' && 'message' in error
222+
? (error as Error)
223+
: ({ message: String(error), name: 'Error' } as Error)
226224
return { hasError: true, error: errorObj }
227225
}
228226

@@ -237,4 +235,4 @@ class ErrorBoundary extends React.Component<
237235

238236
return this.props.children
239237
}
240-
}
238+
}

src/src/app/pages/layout.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ import TopNavBar from '@/components/navbar/top-nav-bar'
22
import { VersionDisplay } from '@/components/version-display'
33
import Link from 'next/link'
44

5-
export default function PagesLayout({
6-
children,
7-
}: {
8-
children: React.ReactNode
9-
}) {
5+
export default function PagesLayout({ children }: { children: React.ReactNode }) {
106
return (
117
<div className="flex flex-col min-h-dvh">
128
<TopNavBar />
13-
<main className="flex-1">
14-
{children}
15-
</main>
9+
<main className="flex-1">{children}</main>
1610
<footer className="flex flex-col gap-2 sm:flex-row py-6 w-full shrink-0 items-center px-4 md:px-6 border-t">
1711
<p className="text-xs text-muted-foreground">&copy; 2024 Acme Inc. All rights reserved.</p>
1812
<nav className="sm:ml-auto flex gap-4 sm:gap-6">
@@ -27,4 +21,4 @@ export default function PagesLayout({
2721
</footer>
2822
</div>
2923
)
30-
}
24+
}

src/src/components/comment/AddComment.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ export const AddComment = ({ entityType, entityId }: AddCommentProps) => {
2020
const { toast } = useToast()
2121
const queryClient = useQueryClient()
2222
const { handleSubmit, register, reset, watch, setValue } = useForm()
23-
23+
2424
const commentText = watch('text', '')
2525
const hasText = commentText.trim().length > 0
2626

2727
const onSubmit = async (data: any) => {
2828
if (!hasText) return
29-
29+
3030
setIsSubmitting(true)
3131
console.log('AddComment - form data:', data)
3232

@@ -64,21 +64,22 @@ export const AddComment = ({ entityType, entityId }: AddCommentProps) => {
6464
} catch (err: unknown) {
6565
console.error('Comment creation error:', err)
6666
let errorMessage = "Comment creation wasn't successful."
67-
67+
6868
if (err instanceof Error) {
6969
if (err.message.includes('network') || err.message.includes('fetch')) {
7070
errorMessage = 'Network error. Please check your connection and try again.'
7171
} else if (err.message.includes('timeout')) {
7272
errorMessage = 'Request timed out. Please try again.'
7373
} else if (err.message.includes('unauthorized') || err.message.includes('401')) {
74-
errorMessage = 'You need to be logged in to comment. Please refresh the page and try again.'
74+
errorMessage =
75+
'You need to be logged in to comment. Please refresh the page and try again.'
7576
} else if (err.message.includes('forbidden') || err.message.includes('403')) {
7677
errorMessage = 'You do not have permission to comment on this page.'
7778
} else {
7879
errorMessage = err.message || errorMessage
7980
}
8081
}
81-
82+
8283
toast({
8384
title: 'Failed',
8485
description: errorMessage,
@@ -104,7 +105,7 @@ export const AddComment = ({ entityType, entityId }: AddCommentProps) => {
104105
<MessageCircle className="w-5 h-5 text-muted-foreground" />
105106
<h3 className="text-lg font-semibold">Add a Comment</h3>
106107
</div>
107-
108+
108109
<form onSubmit={handleSubmit(onSubmit)} className="space-y-3">
109110
<div className="relative">
110111
<Textarea
@@ -115,7 +116,7 @@ export const AddComment = ({ entityType, entityId }: AddCommentProps) => {
115116
onFocus={handleFocus}
116117
disabled={isSubmitting}
117118
/>
118-
119+
119120
{isExpanded && (
120121
<div className="absolute top-2 right-2">
121122
<Button
@@ -131,7 +132,7 @@ export const AddComment = ({ entityType, entityId }: AddCommentProps) => {
131132
</div>
132133
)}
133134
</div>
134-
135+
135136
{isExpanded && (
136137
<div className="flex items-center justify-between">
137138
<div className="text-xs text-muted-foreground">

src/src/components/comment/PageComments.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ export const PageComments = ({ pageId, pageTitle }: PageCommentsProps) => {
6767
</div>
6868
<h3 className="text-lg font-semibold mb-2">Comments Unavailable</h3>
6969
<p className="text-muted-foreground mb-4">
70-
We're having trouble loading comments right now. This might be a temporary issue.
70+
We&apos;re having trouble loading comments right now. This might be a temporary issue.
7171
</p>
72-
<Button
73-
variant="outline"
74-
onClick={() => window.location.reload()}
75-
size="sm"
76-
>
72+
<Button variant="outline" onClick={() => window.location.reload()} size="sm">
7773
Try Again
7874
</Button>
7975
</div>
@@ -239,9 +235,7 @@ const CommentItem = ({ comment, isAuthenticated, pageId }: CommentItemProps) =>
239235
/>
240236
</div>
241237
<div className="flex items-center justify-between">
242-
<div className="text-xs text-muted-foreground">
243-
{replyText.length}/500 characters
244-
</div>
238+
<div className="text-xs text-muted-foreground">{replyText.length}/500 characters</div>
245239
<div className="flex gap-2">
246240
<Button
247241
size="sm"
@@ -253,9 +247,9 @@ const CommentItem = ({ comment, isAuthenticated, pageId }: CommentItemProps) =>
253247
>
254248
Cancel
255249
</Button>
256-
<Button
257-
size="sm"
258-
onClick={handleReply}
250+
<Button
251+
size="sm"
252+
onClick={handleReply}
259253
disabled={!replyText.trim()}
260254
className="min-w-[80px]"
261255
>

src/src/components/page/PageView.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { config } from '@/components/puck/config'
1414
import { Alert, AlertDescription } from '@/components/ui/alert'
1515
import { Button } from '@/components/ui/button'
1616
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
17-
import { AlertTriangle, FileText, RefreshCw } from 'lucide-react'
1817
import { Render } from '@measured/puck'
18+
import { AlertTriangle, FileText, RefreshCw } from 'lucide-react'
1919
import React, { useEffect, useState } from 'react'
2020

2121
export type PageViewProps = {
@@ -44,7 +44,9 @@ export const PageView = ({ page }: PageViewProps) => {
4444
// Cleanup: remove the style element when component unmounts
4545
// This prevents styles from persisting after leaving the page
4646
return () => {
47-
const existingStyle = document.querySelector(`[data-page-style="${page.id || 'unknown'}"]`)
47+
const existingStyle = document.querySelector(
48+
`[data-page-style="${page.id || 'unknown'}"]`
49+
)
4850
if (existingStyle) {
4951
document.head.removeChild(existingStyle)
5052
}
@@ -64,7 +66,10 @@ export const PageView = ({ page }: PageViewProps) => {
6466
if (page.script && typeof page.script === 'string' && page.script.trim().length > 0) {
6567
try {
6668
// Log the script content for debugging purposes
67-
console.log('Page script detected (execution disabled for security):', page.script.substring(0, 100) + '...')
69+
console.log(
70+
'Page script detected (execution disabled for security):',
71+
page.script.substring(0, 100) + '...'
72+
)
6873

6974
// TODO: Implement proper script sandboxing for security
7075
// Script execution is temporarily disabled to prevent security vulnerabilities
@@ -242,8 +247,8 @@ export const PageView = ({ page }: PageViewProps) => {
242247
</CardDescription>
243248
</CardHeader>
244249
<CardContent className="text-center">
245-
<Button
246-
variant="outline"
250+
<Button
251+
variant="outline"
247252
onClick={() => window.location.reload()}
248253
className="mx-auto"
249254
>
@@ -279,17 +284,19 @@ class ErrorBoundary extends React.Component<
279284
}
280285

281286
static getDerivedStateFromError(error: unknown) {
282-
const errorObj = error && typeof error === 'object' && 'message' in error
283-
? error as Error
284-
: { message: String(error), name: 'Error' } as Error
287+
const errorObj =
288+
error && typeof error === 'object' && 'message' in error
289+
? (error as Error)
290+
: ({ message: String(error), name: 'Error' } as Error)
285291
return { hasError: true, error: errorObj }
286292
}
287293

288294
componentDidCatch(error: unknown, errorInfo: React.ErrorInfo) {
289295
console.error('Error Boundary caught an error:', error, errorInfo)
290-
const errorObj = error && typeof error === 'object' && 'message' in error
291-
? error as Error
292-
: { message: String(error), name: 'Error' } as Error
296+
const errorObj =
297+
error && typeof error === 'object' && 'message' in error
298+
? (error as Error)
299+
: ({ message: String(error), name: 'Error' } as Error)
293300
this.props.onError?.(errorObj)
294301
}
295302

@@ -303,13 +310,11 @@ class ErrorBoundary extends React.Component<
303310
<AlertTriangle className="h-6 w-6 text-red-600" />
304311
</div>
305312
<CardTitle>Rendering Error</CardTitle>
306-
<CardDescription>
307-
There was an error rendering this content.
308-
</CardDescription>
313+
<CardDescription>There was an error rendering this content.</CardDescription>
309314
</CardHeader>
310315
<CardContent className="text-center">
311-
<Button
312-
variant="outline"
316+
<Button
317+
variant="outline"
313318
onClick={() => this.setState({ hasError: false, error: undefined })}
314319
className="mx-auto"
315320
>

src/src/components/puck/components/CardBlock/CardBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ export const CardBlock = ({
9494
)}
9595
</div>
9696
)
97-
}
97+
}

src/src/components/puck/components/CardBlock/CardBlockDefaults.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export const CardBlockDefaults = {
1010
backgroundColor: '#ffffff',
1111
borderColor: '#e5e7eb',
1212
padding: '24px',
13-
borderRadius: '8px'
14-
}
13+
borderRadius: '8px',
14+
}

0 commit comments

Comments
 (0)