Skip to content

Commit

Permalink
work in process
Browse files Browse the repository at this point in the history
  • Loading branch information
loopy-dev committed Jul 15, 2023
1 parent 7f16df0 commit 8b75f7c
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/components/NavigationBar/NavigationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import classNames from 'classnames';
import dynamic from 'next/dynamic';
import { Noto_Sans_KR } from 'next/font/google';
Expand Down Expand Up @@ -105,6 +105,33 @@ const Right = () => {
};

const Middle = () => {
const router = useRouter();
const [isShowing, setIsShowing] = useState(false);
const [postTitle, setPostTitle] = useState('');

useEffect(() => {
const isPostPath = getSubDomain(router.pathname) === 'posts';
setIsShowing(isPostPath);
}, [router.pathname]);

useEffect(() => {
const handler = () => {
const title = document.querySelector('.post-title');

if (!title) return;

setPostTitle(title.textContent || '');
};

handler();

router.events.on('routeChangeComplete', handler);

return () => {
router.events.off('routeChangeComplete', handler);
};
}, [router.events]);

return (
<div
className={classNames(
Expand All @@ -117,7 +144,7 @@ const Middle = () => {
'text-center'
)}
>
Test
{postTitle}
</div>
);
};
Expand Down

0 comments on commit 8b75f7c

Please sign in to comment.