Skip to content

Commit

Permalink
Go To Top button
Browse files Browse the repository at this point in the history
  • Loading branch information
Darguima committed Nov 24, 2023
1 parent 07bc116 commit 25fc0bc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/trello.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on:
jobs:
build:
runs-on: ubuntu-latest
steps:
# Link PR to Trello
steps:
# Link PR to Trello
- name: Link to Trello
uses: rematocorp/[email protected]
with:
Expand Down
14 changes: 7 additions & 7 deletions components/Badge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import Link from "next/link";
import { ReactEventHandler } from "react";

interface BadgeProps {
name: string
id: string | number
avatar: string
tokens: string | number
owned: boolean
name: string;
id: string | number;
avatar: string;
tokens: string | number;
owned: boolean;
}

export default function Badge({ name, id, avatar, tokens, owned }: BadgeProps) {
const imageOnError: ReactEventHandler<HTMLImageElement> = (e) => {
e.currentTarget.src='/images/badges/badge-template.png'
}
e.currentTarget.src = "/images/badges/badge-template.png";
};

return (
<Link
Expand Down
33 changes: 33 additions & 0 deletions components/GoToTop/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { faArrowCircleUp } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useEffect, useState } from "react";

export default function GoToTop() {
const [showButton, setShowButton] = useState(false);

useEffect(() => {
window.addEventListener("scroll", () => {
if (window.scrollY > 400) {
setShowButton(true);
} else {
setShowButton(false);
}
});
}, []);

const goToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};

return (
<FontAwesomeIcon
icon={faArrowCircleUp}
className={"fixed right-5 bottom-5 cursor-pointer text-3xl"}
visibility={showButton ? "visible" : "hidden"}
onClick={goToTop}
/>
);
}
24 changes: 13 additions & 11 deletions layout/Attendee/Badgedex/Badgedex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ import Layout from "@components/Layout";
import ErrorMessage from "@components/ErrorMessage";
import Badge from "@components/Badge";
import BadgeFilter from "@components/BadgeFilter";
import GoToTop from "@components/GoToTop";

export interface Badges {
avatar: string
begin: string
description: string
end: string
id: number
name: string
tokens: number
type: number
avatar: string;
begin: string;
description: string;
end: string;
id: number;
name: string;
tokens: number;
type: number;
}

interface UserWithBadges {
user: {
badges: Badges[]
}
badges: Badges[];
};
}

function Badgedex() {
const { user }: UserWithBadges = useAuth();
const { user }: UserWithBadges = useAuth();
const [allBadges, updateAllBadges] = useState<Badges[]>([]);
const [all, updateAll] = useState(true);
const [filter, updateFilter] = useState(null);
Expand Down Expand Up @@ -91,6 +92,7 @@ function Badgedex() {
</div>

{error && <ErrorMessage />}
<GoToTop />
</Layout>
);
}
Expand Down

0 comments on commit 25fc0bc

Please sign in to comment.