kal
kal
Explore posts from servers
TTCTheo's Typesafe Cult
Created by kal on 7/23/2024 in #questions
Vertical scroll on element with dynamic height
This is the element in question.
3 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
I have it hosted on github still, but its not deployed anywhere. You can host it yourself locally, but it requires a set of google oauth credentials to work properly & a postgres db url. I dont think you'll be able to access that page without doing some finicky stuff without that.
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
No description
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
Thanks mate, appreciate it.
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
hey bro - long time I know. Finally back to normal - you still able to lend a helping hand in getting this resolved? < 3
39 replies
DTDrizzle Team
Created by Acro on 3/21/2024 in #help
Examples for Error Handling?
Did you figure this out in the end
2 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
🙏 will do. Thanks. I finish in just over a week.
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
I've got exams in a couple of days so cant really spare the time to play around with the code myself right now. I do really appreciate you taking the time to help me out.
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
also - wow ok that is strange.
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
Thanks for taking a look man. Appreciate it. The Panel component is stored at src/app/(dynamic)/(protected)/play/(panel)/_components/Panel.tsx. https://github.com/FlynnHillier/chessalyze/blob/main/src/app/(dynamic)/(protected)/play/(panel)/_components/Panel.tsx
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
if you want to try if it 'fixes' it for you trying yarn remove @flynnhillier/chessboard-image-gen and then re-add it. After installing all other things.
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
I've had that error a couple of times - I usually have to resolve it by removing and reinstalling a certain dependency after adding another dependency. I'm pretty sure its an error in a the node-canvas module which one of my dependencies depends on. I'll look into fixing it tommorow, or atleast within the next couple of days, and get back to you;
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
Very true. Here's the repo in question. It does have a tiny bit of setup required with a couple of env variables, but you may just be able to delete the env.js file and omit this, although I think if you do this things might play up a bit. Nonetheless, if you dont fancy filling the env variables, you can simply extract the jsx as it is the very top level layout.tsx in question. https://github.com/FlynnHillier/chessalyze layout.tsx https://github.com/FlynnHillier/chessalyze/blob/main/src/app/layout.tsx
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
No description
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
I see I see, that makes sense. I’ve just this second powered down my computer for the night - but I’ll implement this change tommorow and get back to you. Hopefully it results in the behaviour I’m after. Appreciate your time!
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
yeah it looks to me that this is the case. Is there anything you could suggest to maybe fix the issue?
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/17/2024 in #questions
Include padding bottom when overflow-y-scroll
39 replies
TTCTheo's Typesafe Cult
Created by kal on 5/4/2024 in #questions
next 14 Showing image fallback on public folder image 404
Thank you once again. I see what you mean now with using the ref, I was confused as in my head i was adiment with using the activeSrc state and passing that to the react element as the src prop - hence I thought we'd just encounter the original issue of onError firing after src starts loading. In regards to the event typing mismatch I've found that apparently React wraps native events in a wrapper so they behave the same way in all browsers https://legacy.reactjs.org/docs/events.html . I'm not entirely sure if there is a way to convert from a DOM event to this wrapper, (https://stackoverflow.com/questions/65889954/how-to-convert-a-raw-dom-event-to-a-react-syntheticevent) hence I think for now I'm just going to omit the onLoad and onError props from the component. In regards to the image flashing, again, It is not ideal - however, I think it is bearable. I am also not familiar with requestAnimationFrame so I wouldn't be able to do much using this right now. I also can't think of any other means of solving the issue.
14 replies
TTCTheo's Typesafe Cult
Created by kal on 5/4/2024 in #questions
next 14 Showing image fallback on public folder image 404
i've come up with this updated component:
"use client";

import { useEffect, useRef, useState } from "react";

type Props = Omit<React.ImgHTMLAttributes<HTMLImageElement>, "onError"> & {
src: string;
fallbackSrc?: string;
};

export default function ImageWithFallback({
fallbackSrc,
src,
...restProps
}: Props) {
const [activeSrc, setActiveSrc] = useState<string | undefined>(src);
const [hasLoaded, setHasLoaded] = useState<boolean>(false);

useEffect(() => {
const dummy = new Image();

dummy.onerror = () => {
if (fallbackSrc) setActiveSrc(fallbackSrc);
};

dummy.onload = () => {
setHasLoaded(true);
};

dummy.src = src;
}, [src]);

useEffect(() => {
if (activeSrc && activeSrc === src) return;

setActiveSrc(fallbackSrc);
}, [fallbackSrc]);

return (
<img
{...restProps}
style={{
visibility:
!hasLoaded && activeSrc !== fallbackSrc
? "hidden"
: restProps.style?.visibility,
...restProps.style,
}}
src={activeSrc}
onLoad={() => {
setHasLoaded(true);
}}
/>
);
}
"use client";

import { useEffect, useRef, useState } from "react";

type Props = Omit<React.ImgHTMLAttributes<HTMLImageElement>, "onError"> & {
src: string;
fallbackSrc?: string;
};

export default function ImageWithFallback({
fallbackSrc,
src,
...restProps
}: Props) {
const [activeSrc, setActiveSrc] = useState<string | undefined>(src);
const [hasLoaded, setHasLoaded] = useState<boolean>(false);

useEffect(() => {
const dummy = new Image();

dummy.onerror = () => {
if (fallbackSrc) setActiveSrc(fallbackSrc);
};

dummy.onload = () => {
setHasLoaded(true);
};

dummy.src = src;
}, [src]);

useEffect(() => {
if (activeSrc && activeSrc === src) return;

setActiveSrc(fallbackSrc);
}, [fallbackSrc]);

return (
<img
{...restProps}
style={{
visibility:
!hasLoaded && activeSrc !== fallbackSrc
? "hidden"
: restProps.style?.visibility,
...restProps.style,
}}
src={activeSrc}
onLoad={() => {
setHasLoaded(true);
}}
/>
);
}
I believe it makes use of most of the suggested improvements you provided. However - I'm not sure I've implemented the ref part you suggested. Also, I am currently omitting the onError prop as it expected an event argument. I would rather like to not omit this and instead call the provided callback in addition to the component required behaviour, however when I attempted to give dummy.onerror an argument e typescript didn't seem to know what type this argument would be. I wonder if this is because I am redefining the callback and if I should specify that e is of type image event (or whatever the correct type is).
14 replies
TTCTheo's Typesafe Cult
Created by kal on 5/4/2024 in #questions
next 14 Showing image fallback on public folder image 404
I like the visibility hidden suggestion, thanks. However I am not sure how you suggest we could 'use only a single <img /> via a ref'. I asumme you mean to use the useRef hook like so const imageRef = useRef<HTMLImageElement>(null); and then bind it to the returned img. Would you then suggest somehow mutating the imageRef.current to use the desired onError callbacks? If this is the case, does this not also fall into the pitfall that the onError callback is only bound after the image has already tried to fetch the image source?
14 replies