Skip to content

Commit

Permalink
profile画面のバグ修正
Browse files Browse the repository at this point in the history
  • Loading branch information
ogatakatsuya committed Jul 18, 2024
1 parent fecbff6 commit c74906c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion backend/api/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

ASYNC_DB_URL = f"mysql+aiomysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:3306/{DB_NAME}?charset=utf8"

async_engine = create_async_engine(ASYNC_DB_URL, echo=True)
async_engine = create_async_engine(ASYNC_DB_URL)
async_session = sessionmaker(
autocommit=False, autoflush=False, bind=async_engine, class_=AsyncSession
)
Expand Down
2 changes: 1 addition & 1 deletion backend/api/migrate_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
DB_NAME = os.getenv('DB_NAME')

DB_URL = f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:3306/{DB_NAME}?charset=utf8"
engine = create_engine(DB_URL, echo=True)
engine = create_engine(DB_URL)


def reset_database():
Expand Down
1 change: 1 addition & 0 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const nextConfig = {
},
],
},
reactStrictMode: false,
};

export default nextConfig;
4 changes: 0 additions & 4 deletions frontend/src/app/profile/[user_id]/_components/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ const Post = ({ user_id }) => {
console.error("Error fetching posts:", error);
}
};

useEffect(() => {
fetchPost(offset)
},[])

useEffect(() => {
if (hasMore && offset>0) {
Expand Down
38 changes: 16 additions & 22 deletions frontend/src/app/profile/me/_components/MyPost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import {
IconButton,
StackDivider,
Stack,
} from '@chakra-ui/react'
} from '@chakra-ui/react';
import { MdExpandMore } from "react-icons/md";

const MyPost = () => {
const router = useRouter();
const [post, setPost] = useState([]);
const [hasMore, setHasMore] = useState(true);
const [offset, setOffset] = useState(0);
const [initialLoad, setInitialLoad] = useState(true); // 初回ロードフラグ
const observerTarget = useRef(null);

const fetchPost = async (offset) => {
Expand All @@ -32,15 +33,13 @@ const MyPost = () => {
});
if (res.ok) {
const data = await res.json();
if (offset === 0) { //初回表示時はレンダリングが2回行われるため
if (offset === 0 && initialLoad) { // 初回表示時は上書きする
setPost(data);
setOffset(0);
console.log(data)
setInitialLoad(false); // 初回ロードを完了としてマーク
} else {
setPost((prevPosts) => [...prevPosts, ...data]);
console.log(data)
}
setHasMore( data.length === 10 )
setHasMore(data.length === 10);
} else {
console.error("Error fetching posts:", res.statusText);
}
Expand All @@ -50,12 +49,7 @@ const MyPost = () => {
};

useEffect(() => {
fetchPost(offset)
},[])

useEffect(() => {
if (hasMore && offset>0) {
console.log("fetch post")
if (hasMore && offset > 0) {
fetchPost(offset);
}
}, [offset, hasMore]);
Expand All @@ -82,7 +76,7 @@ const MyPost = () => {

const redirectToDetail = (post_id) => {
router.push(`/post/${post_id}`);
}
};

return (
<>
Expand All @@ -92,7 +86,7 @@ const MyPost = () => {
<Card width="650px" key={item.id} bgColor="gray.100">
<CardBody>
<Flex alignItems="center">
<Avatar src={item?.icon_url}/>
<Avatar src={item?.icon_url} />
<Box ml={3}>
<Text fontSize='md'>
{item.user_nickname ? item.user_nickname : item.user_name}
Expand All @@ -108,12 +102,12 @@ const MyPost = () => {
</Text>
{item.file_url &&
<Image
src={item.file_url}
width={200}
height={200}
alt="Imege"
style={{ width: 'auto', height: 'auto' }}
priority
src={item.file_url}
width={200}
height={200}
alt="Image"
style={{ width: 'auto', height: 'auto' }}
priority
/>
}
</Box>
Expand All @@ -139,6 +133,6 @@ const MyPost = () => {
</Box>
</>
);
}
};

export default MyPost;
export default MyPost;

0 comments on commit c74906c

Please sign in to comment.