diff --git a/frontend/src/components/Avatar.tsx b/frontend/src/components/Avatar.tsx new file mode 100644 index 0000000..112841c --- /dev/null +++ b/frontend/src/components/Avatar.tsx @@ -0,0 +1,49 @@ +import { useMemo, useState } from "react"; + +const defaultClasses = ["w-16", "h-16", "object-cover"]; +export const Avatar = ({ + id, + size, + className, +}: { + id: string; + size: number; + className?: string; +}) => { + const classes = useMemo( + () => + Array.from( + new Set( + (className + ? defaultClasses.concat(className.split(" ")) + : defaultClasses + ).concat([`w-${size}`, `h-${size}`]) + ) + ).join(" "), + [className, size] + ); + + const [showBroken, setShowBroken] = useState(false); + + const handleError = () => { + setShowBroken(true); + setTimeout( + () => setShowBroken(false), + Math.floor(Math.random() * (1000 - 250 + 1)) + 250 // Random time between 250 and 1500 ms + ); + }; + + if (showBroken) { + return
; + } + + return ( + Avatar + ); +}; diff --git a/frontend/src/pages/Neighbors.tsx b/frontend/src/pages/Neighbors.tsx index 348ba6f..81ed8e9 100644 --- a/frontend/src/pages/Neighbors.tsx +++ b/frontend/src/pages/Neighbors.tsx @@ -1,6 +1,7 @@ import { formatDuration, formatISO, intervalToDuration } from "date-fns"; import { useMemo } from "react"; +import { Avatar } from "../components/Avatar"; import { HeardBy } from "../components/HeardBy"; import { useGetNodesQuery } from "../slices/apiSlice"; import { convertNodeIdFromIntToHex } from "../utils/convertNodeId"; @@ -76,11 +77,7 @@ export const Neighbors = () => { valign="middle" > - Avatar + {
- {node.shortname} +

{`${node.shortname} - ${node.longname}`}

diff --git a/frontend/src/pages/Nodes.tsx b/frontend/src/pages/Nodes.tsx index 65df4c9..dbf7d90 100644 --- a/frontend/src/pages/Nodes.tsx +++ b/frontend/src/pages/Nodes.tsx @@ -1,6 +1,7 @@ import { useEffect, useMemo, useState } from "react"; import { Link } from "react-router-dom"; +import { Avatar } from "../components/Avatar"; import { DateToSince } from "../components/DateSince"; import { HardwareImg } from "../components/HardwareImg"; import { HeardBy } from "../components/HeardBy"; @@ -138,7 +139,7 @@ export const Nodes = () => { - + Hex - +