Skip to content

Commit 42f95ce

Browse files
committed
fix: change size and position
1 parent 93d11b1 commit 42f95ce

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

src/components/common/Sticky.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const Sticky: React.FC<StickyProps> = ({ className, top, children }) => {
2222

2323
const onScroll = useCallback(() => {
2424
const scrollTop = getScrollTop();
25-
const nextFixed = scrollTop + 112 > y;
25+
const nextFixed = scrollTop + 80 > y;
2626
if (fixed !== nextFixed) {
2727
setFixed(nextFixed);
2828
}

src/components/post/PostLikeShareButtons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const PostLikeShareButtons: React.FC<PostLikeShareButtonsProps> = ({
146146
return (
147147
<Wrapper>
148148
<Positioner>
149-
<PostLikeShareButtonsBlock top={112}>
149+
<PostLikeShareButtonsBlock top={80}>
150150
<CircleButton
151151
data-testid="like"
152152
onClick={onLikeToggle}

src/components/post/SideAd.tsx

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const Wrapper = styled.div`
1313

1414
const Positioner = styled.div`
1515
position: absolute;
16-
top: 182px;
16+
top: 162px;
1717
`;
1818

1919
const AdBlock = styled.div<{ width: number; height: number }>`
@@ -26,7 +26,15 @@ const AdBlock = styled.div<{ width: number; height: number }>`
2626
// font-size: 14px;
2727
`;
2828

29-
function AdInsComponent() {
29+
function AdInsComponent({
30+
width,
31+
height,
32+
slot,
33+
}: {
34+
width: number;
35+
height: number;
36+
slot: string;
37+
}) {
3038
useEffect(() => {
3139
(window.adsbygoogle = window.adsbygoogle || []).push({});
3240
}, []);
@@ -36,17 +44,18 @@ function AdInsComponent() {
3644
className="adsbygoogle"
3745
style={{
3846
display: 'inline-block',
39-
width: '160px',
40-
height: '600px',
47+
width: `${width}px`,
48+
height: `${height}px`,
4149
}}
4250
data-ad-client="ca-pub-5574866530496701"
43-
data-ad-slot="1933254146"
51+
data-ad-slot={slot}
4452
></ins>
4553
);
4654
}
4755

4856
export default function SideAd() {
4957
const [isDesktop, setIsDesktop] = useState(false);
58+
const [mode, setMode] = useState<'mini' | 'regular'>('regular');
5059
const [fixed, setFixed] = useState(false);
5160
const [y, setY] = useState(0);
5261
const element = useRef<HTMLDivElement | null>(null);
@@ -59,7 +68,7 @@ export default function SideAd() {
5968

6069
const onScroll = useCallback(() => {
6170
const scrollTop = getScrollTop();
62-
const nextFixed = scrollTop + 112 + 182 > y;
71+
const nextFixed = scrollTop + 112 + 142 > y;
6372
if (fixed !== nextFixed) {
6473
setFixed(nextFixed);
6574
}
@@ -74,6 +83,10 @@ export default function SideAd() {
7483
const hasMinWidth = window.innerWidth >= 1200;
7584

7685
setIsDesktop(!isMobile && hasMinWidth);
86+
87+
// Set mode based on window height
88+
const windowHeight = window.innerHeight;
89+
setMode(windowHeight < 864 ? 'mini' : 'regular');
7790
}, []);
7891

7992
useEffect(() => {
@@ -87,7 +100,21 @@ export default function SideAd() {
87100
};
88101
}, [onScroll]);
89102

90-
const size = { width: 160, height: 600 };
103+
useEffect(() => {
104+
const handleResize = () => {
105+
const windowHeight = window.innerHeight;
106+
setMode(windowHeight < 864 ? 'mini' : 'regular');
107+
};
108+
109+
window.addEventListener('resize', handleResize);
110+
return () => {
111+
window.removeEventListener('resize', handleResize);
112+
};
113+
}, []);
114+
115+
const size =
116+
mode === 'mini' ? { width: 160, height: 500 } : { width: 160, height: 600 };
117+
const adSlot = mode === 'mini' ? '7825010541' : '1933254146';
91118
const leftPosition = '-208px';
92119

93120
return (
@@ -99,10 +126,14 @@ export default function SideAd() {
99126
height={size.height}
100127
style={{
101128
position: fixed ? 'fixed' : undefined,
102-
top: fixed ? 282 : undefined,
129+
top: fixed ? 242 : undefined,
103130
}}
104131
>
105-
<AdInsComponent />
132+
<AdInsComponent
133+
width={size.width}
134+
height={size.height}
135+
slot={adSlot}
136+
/>
106137
</AdBlock>
107138
) : null}
108139
</Positioner>

0 commit comments

Comments
 (0)