Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Thumbnail inner #31

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const SearchBar = () => {
const [takesALongTime, setTakesALongTime] = useState<boolean>(false);

useEffect(() => {
console.log(loading);
let takeId;
if (loading)
takeId = setTimeout(() => {
Expand Down
22 changes: 18 additions & 4 deletions components/Thumbnail.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { useState } from "react";
import { useState, Dispatch, SetStateAction, useEffect } from "react";
import styles from "./Thumbnail.module.css";
import TrackVisibility from "react-on-screen";

const NO_THUMBNAIL_URL =
"https://nicovideo.cdn.nimg.jp/web/img/common/no_thumbnail_M.jpg";

const Inner = ({
isVisible,
setViewable,
}: {
isVisible: boolean;
setViewable: Dispatch<SetStateAction<boolean>>;
}) => {
useEffect(() => {
if (isVisible) setViewable(isVisible);
}, [isVisible]);

return <></>;
};

// TODO: https://github.com/naari3/otomad-search/issues/15
const Thumbnail = ({
thumbnailUrl,
Expand All @@ -23,9 +37,9 @@ const Thumbnail = ({
partialVisibility={true}
offset={250}
>
{({ isVisible }) => {
if (isVisible) setViewable(isVisible);
}}
{({ isVisible }) => (
<Inner isVisible={isVisible} setViewable={setViewable} />
)}
</TrackVisibility>
<img
className={styles.thumb}
Expand Down
1 change: 0 additions & 1 deletion lib/useWindowSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export function useWindowSize() {
useEffect(() => {
// Handler to call on window resize
function handleResize() {
console.log("resize");
// Set window width/height to state
setWindowSize({
width: window.innerWidth,
Expand Down