Skip to content

Commit

Permalink
Merge pull request #765 from npocccties/fix-book-not-found
Browse files Browse the repository at this point in the history
fix: 一瞬だけ「ブックがありません」が見えてしまう問題を修正
  • Loading branch information
ties-makimura authored Jun 16, 2022
2 parents fbd1abb + a92f906 commit afce184
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pages/book/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect } from "react";
import { useState, useCallback, useEffect } from "react";
import { useRouter } from "next/router";
import type { BookSchema } from "$server/models/book";
import {
Expand All @@ -23,6 +23,7 @@ import logger from "$utils/eventLogger/logger";
export type Query = { bookId: BookSchema["id"]; token?: string; zoom?: number };

function Show(query: Query) {
const [redirectError, setRedirectError] = useState(false);
const router = useRouter();
if (query.zoom) {
void getBookIdByZoom(query.zoom)
Expand All @@ -33,7 +34,7 @@ function Show(query: Query) {
);
})
.catch((_) => {
// nop
setRedirectError(true);
});
}

Expand Down Expand Up @@ -111,7 +112,16 @@ function Show(query: Query) {
onTopicEditClick: handleTopicEditClick,
};

if (error) return <BookNotFoundProblem />;
// 読み込み直後はクエリがなにもないか判断できないので、少し待ってから判断する
const [timedout, setTimedout] = useState(false);
if (!timedout) setTimeout(() => setTimedout(true), 5000);
const queryError =
timedout &&
!Number.isFinite(query.bookId) &&
!query.token &&
!Number.isFinite(query.zoom);

if (error || redirectError || queryError) return <BookNotFoundProblem />;
if (!book) return <Placeholder />;

return <Book book={book} index={itemIndex} {...handlers} />;
Expand All @@ -125,9 +135,6 @@ function Router() {
: router.query.token;
const zoom = Number(router.query.zoom);

if (!Number.isFinite(bookId) && !token && !Number.isFinite(zoom))
return <BookNotFoundProblem />;

return <Show bookId={bookId} token={token} zoom={zoom} />;
}

Expand Down

1 comment on commit afce184

@vercel
Copy link

@vercel vercel bot commented on afce184 Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

chibi-ch-i-lo – ./

chibi-ch-i-lo-git-master-ties-makimura.vercel.app
f-omega.vercel.app
chibi-ch-i-lo-ties-makimura.vercel.app

Please sign in to comment.