Skip to content

Commit d79e996

Browse files
committed
fix : remove unread importations
1 parent da0d6f4 commit d79e996

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

components/BlockPreview.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ const SMSIZE = 30
3030
const MDSIZE = 62
3131
const LGSIZE = 82
3232

33-
// Add this key function to generate cache keys
3433
const getCacheKey = (src: string) => `iframe-cache-${src}`
3534

3635
export const BlockPreview: React.FC<BlockPreviewProps> = ({ code, preview, title, category, previewOnly }) => {
3736
const [width, setWidth] = useState(DEFAULTSIZE)
3837
const [mode, setMode] = useState<'preview' | 'code'>('preview')
3938
const [iframeHeight, setIframeHeight] = useState(0)
40-
const [isLoading, setIsLoading] = useState(true)
4139
const [shouldLoadIframe, setShouldLoadIframe] = useState(false)
4240
const [cachedHeight, setCachedHeight] = useState<number | null>(null)
4341
const [isIframeCached, setIsIframeCached] = useState(false)
@@ -54,7 +52,6 @@ export const BlockPreview: React.FC<BlockPreviewProps> = ({ code, preview, title
5452
const observer = useRef<IntersectionObserver | null>(null)
5553
const blockRef = useRef<HTMLDivElement>(null)
5654

57-
// Set up Intersection Observer to load iframe when it comes into view
5855
useEffect(() => {
5956
observer.current = new IntersectionObserver(
6057
(entries) => {
@@ -75,15 +72,12 @@ export const BlockPreview: React.FC<BlockPreviewProps> = ({ code, preview, title
7572
}
7673
}, [])
7774

78-
// Check if the iframe content is already cached
7975
useEffect(() => {
80-
// Check if the iframe content is already cached by service worker
8176
const checkCache = async () => {
8277
try {
8378
const isCached = await isUrlCached(preview)
8479
setIsIframeCached(isCached)
8580
if (isCached) {
86-
// If cached by service worker, we can load it immediately
8781
setShouldLoadIframe(true)
8882
}
8983
} catch (error) {
@@ -93,38 +87,31 @@ export const BlockPreview: React.FC<BlockPreviewProps> = ({ code, preview, title
9387

9488
checkCache()
9589

96-
// Also check localStorage for cached height
9790
try {
9891
const cacheKey = getCacheKey(preview)
9992
const cached = localStorage.getItem(cacheKey)
10093
if (cached) {
10194
const { height, timestamp } = JSON.parse(cached)
102-
// Use cached height if it's less than 24 hours old
10395
const now = Date.now()
10496
if (now - timestamp < 24 * 60 * 60 * 1000) {
10597
setCachedHeight(height)
10698
setIframeHeight(height)
107-
// Still load the iframe, but we can show the correct height immediately
10899
}
109100
}
110101
} catch (error) {
111102
console.error('Error retrieving cache:', error)
112103
}
113104
}, [preview])
114105

115-
// Setup iframe load handler and height caching
116106
useEffect(() => {
117107
const iframe = iframeRef.current
118108
if (!iframe || !shouldLoadIframe) return
119109

120110
const handleLoad = () => {
121-
setIsLoading(false)
122-
123111
try {
124112
const contentHeight = iframe.contentWindow!.document.body.scrollHeight
125113
setIframeHeight(contentHeight)
126114

127-
// Cache the height in localStorage
128115
const cacheKey = getCacheKey(preview)
129116
const cacheValue = JSON.stringify({
130117
height: contentHeight,
@@ -142,23 +129,19 @@ export const BlockPreview: React.FC<BlockPreviewProps> = ({ code, preview, title
142129
}
143130
}, [shouldLoadIframe, preview])
144131

145-
// Add preload link for the iframe source when it's likely to be needed soon
146132
useEffect(() => {
147133
if (!blockRef.current || shouldLoadIframe) return
148134

149-
// Create a preload link for the iframe content
150135
const linkElement = document.createElement('link')
151136
linkElement.rel = 'preload'
152137
linkElement.href = preview
153138
linkElement.as = 'document'
154139

155-
// Only add if not already in the document
156140
if (!document.head.querySelector(`link[rel="preload"][href="${preview}"]`)) {
157141
document.head.appendChild(linkElement)
158142
}
159143

160144
return () => {
161-
// Clean up the preload link when component unmounts or iframe loads
162145
const existingLink = document.head.querySelector(`link[rel="preload"][href="${preview}"]`)
163146
if (existingLink) {
164147
document.head.removeChild(existingLink)

components/logo.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { cn } from '@/lib/utils'
2-
import { motion } from 'motion/react'
32

43
export const Logo = ({ className }: { className?: string }) => {
54
return (

lib/serviceWorker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export function registerServiceWorker() {
1919
}
2020

2121
// Send a message to the service worker
22-
export function sendMessageToSW(message: any) {
22+
type SWMessage = {
23+
type: string;
24+
url?: string;
25+
};
26+
27+
export function sendMessageToSW(message: SWMessage) {
2328
if (typeof window !== 'undefined' && 'serviceWorker' in navigator && navigator.serviceWorker.controller) {
2429
navigator.serviceWorker.controller.postMessage(message);
2530
}

0 commit comments

Comments
 (0)