Skip to content

Commit 2c776da

Browse files
chore: fixed review comments
1 parent 30ce4ba commit 2c776da

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

apps/sim/app/(landing)/blog/[slug]/animated-blocks.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const EXIT_DURATION_MS = 500
1212

1313
const RE_ENTER_OPACITIES = [1, 0.8, 0.6, 0.9] as const
1414

15-
1615
function setBlockOpacity(el: HTMLSpanElement | null, opacity: number, animate: boolean) {
1716
if (!el) return
1817
el.style.transition = animate ? `opacity ${ENTER_DURATION_MS}ms ease-out` : 'none'
@@ -37,7 +36,11 @@ export function AnimatedColorBlocks() {
3736

3837
if (prefersReducedMotion) {
3938
blockRefs.current.forEach((el) => setBlockOpacity(el, 1, false))
40-
return
39+
return () => {
40+
mounted.current = false
41+
timers.current.forEach(clearTimeout)
42+
timers.current = []
43+
}
4144
}
4245

4346
blockRefs.current.forEach((el) => setBlockOpacity(el, 0, false))
@@ -97,7 +100,7 @@ export function AnimatedColorBlocks() {
97100
blockRefs.current[i] = el
98101
}}
99102
className='inline-block h-3 w-3'
100-
style={{ backgroundColor: color, opacity: 0 }}
103+
style={{ backgroundColor: color, opacity: prefersReducedMotion ? 1 : 0 }}
101104
/>
102105
))}
103106
</div>
@@ -112,28 +115,37 @@ export function AnimatedColorBlocksVertical() {
112115

113116
const verticalColors = [COLORS[0], COLORS[1], COLORS[2]] as const
114117

118+
function schedule(fn: () => void, ms: number) {
119+
const id = setTimeout(fn, ms)
120+
timers.current.push(id)
121+
return id
122+
}
123+
115124
useEffect(() => {
116125
mounted.current = true
117126
timers.current = []
118127

119128
if (prefersReducedMotion) {
120129
blockRefs.current.forEach((el) => setBlockOpacity(el, 1, false))
121-
return
130+
return () => {
131+
mounted.current = false
132+
timers.current.forEach(clearTimeout)
133+
timers.current = []
134+
}
122135
}
123136

124137
blockRefs.current.forEach((el) => setBlockOpacity(el, 0, false))
125138

126139
const baseDelay = COLORS.length * ENTER_STAGGER_MS + 100
127140

128141
verticalColors.forEach((_, i) => {
129-
const id = setTimeout(
142+
schedule(
130143
() => {
131144
if (!mounted.current) return
132145
setBlockOpacity(blockRefs.current[i], 1, true)
133146
},
134147
baseDelay + i * ENTER_STAGGER_MS
135148
)
136-
timers.current.push(id)
137149
})
138150

139151
return () => {
@@ -152,7 +164,7 @@ export function AnimatedColorBlocksVertical() {
152164
blockRefs.current[i] = el
153165
}}
154166
className='inline-block h-3 w-3'
155-
style={{ backgroundColor: color, opacity: 0 }}
167+
style={{ backgroundColor: color, opacity: prefersReducedMotion ? 1 : 0 }}
156168
/>
157169
))}
158170
</div>

apps/sim/app/(landing)/blog/studio-content.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ export function StudioContent({ posts, initialTag, initialQuery }: StudioContent
109109
const lowerQ = query.trim().toLowerCase()
110110

111111
const { sorted, activeCategory } = useMemo(() => {
112+
const validTag = activeTag && CATEGORIES.some((c) => c.id === activeTag) ? activeTag : null
113+
112114
let filtered = posts
113115

114-
if (activeTag) {
115-
filtered = posts.filter((p) => getPrimaryCategory(p.tags).id === activeTag)
116+
if (validTag) {
117+
filtered = posts.filter((p) => getPrimaryCategory(p.tags).id === validTag)
116118
}
117119

118120
if (lowerQ) {
@@ -130,7 +132,7 @@ export function StudioContent({ posts, initialTag, initialQuery }: StudioContent
130132
})
131133
}
132134

133-
const cat = activeTag ? getCategoryById(activeTag) : null
135+
const cat = validTag ? getCategoryById(validTag) : null
134136
const s = [...filtered].sort((a, b) => {
135137
if (a.featured && !b.featured) return -1
136138
if (!a.featured && b.featured) return 1
@@ -438,7 +440,9 @@ function SidebarCategories({ items, activeId, onSelect }: SidebarCategoriesProps
438440
style={{
439441
transform: isActive ? 'translate(4px, -4px)' : 'translate(0px, 0px)',
440442
backgroundColor: isActive ? '#242424' : 'transparent',
441-
boxShadow: isActive ? 'inset 0 0 0 1.5px #3E3E3E' : 'inset 0 0 0 1.5px transparent',
443+
boxShadow: isActive
444+
? 'inset 0 0 0 1.5px #3E3E3E'
445+
: 'inset 0 0 0 1.5px transparent',
442446
transition: shouldReduceMotion
443447
? 'none'
444448
: isActive

0 commit comments

Comments
 (0)