Typescript support
This commit is contained in:
parent
354175ff2f
commit
0712a629a9
5 changed files with 40 additions and 7 deletions
|
|
@ -1,10 +1,19 @@
|
||||||
|
export interface PicsumData {
|
||||||
|
id: number,
|
||||||
|
author: string,
|
||||||
|
width: number,
|
||||||
|
height: number,
|
||||||
|
url: string,
|
||||||
|
download_url: string
|
||||||
|
}
|
||||||
|
|
||||||
export async function getPicsumData() {
|
export async function getPicsumData() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('https://picsum.photos/v2/list');
|
const response = await fetch('https://picsum.photos/v2/list');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Picsum API unavailable.');
|
throw new Error('Picsum API unavailable.');
|
||||||
}
|
}
|
||||||
const data = await response.json();
|
const data: PicsumData[] = await response.json();
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Could not fetch data:", error);
|
console.error("Could not fetch data:", error);
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
import { useState } from 'react';
|
import type { MouseEvent } from "react";
|
||||||
|
|
||||||
export function ControlBar({ isGallery, handleClick }) {
|
export interface ControlBarProps {
|
||||||
|
isGallery: boolean;
|
||||||
|
handleClick: React.MouseEventHandler<HTMLButtonElement>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ControlBar({ isGallery, handleClick }: ControlBarProps ) {
|
||||||
return(
|
return(
|
||||||
<div className="hidden md:flex ml-auto">
|
<div className="hidden md:flex ml-auto">
|
||||||
<button className="hover:bg-[#839b39] bg-[#789031] text-white p-2 rounded-lg mr-20 xl:mr-50 min-w-[130px]"
|
<button className="hover:bg-[#839b39] bg-[#789031] text-white p-2 rounded-lg mr-20 xl:mr-50 min-w-[130px]"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { Logo } from "./logo";
|
import { Logo } from "./logo";
|
||||||
import { ControlBar } from "./control_bar"
|
import { ControlBar } from "./control_bar"
|
||||||
|
|
||||||
export function Header({ isGallery, handleClick }) {
|
import type { ControlBarProps } from "./control_bar"
|
||||||
|
|
||||||
|
export function Header({ isGallery, handleClick }: ControlBarProps) {
|
||||||
return (
|
return (
|
||||||
<div className="header flex flex-row m-5 mr-10 md:mr-0 ml-10 md:ml-20 xl:ml-50 gap-5 items-center">
|
<div className="header flex flex-row m-5 mr-10 md:mr-0 ml-10 md:ml-20 xl:ml-50 gap-5 items-center">
|
||||||
<a href="https://www.ligonier.org">
|
<a href="https://www.ligonier.org">
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
import type { PicsumData } from '../api/picsum';
|
||||||
|
|
||||||
// A Card, rendering an image and toggling photographer information when clicked
|
// A Card, rendering an image and toggling photographer information when clicked
|
||||||
export function PhotoCard({ data }) {
|
export function PhotoCard({ data }: {data: PicsumData}) {
|
||||||
const [infoToggled, setInfoToggled] = useState(false);
|
const [infoToggled, setInfoToggled] = useState(false);
|
||||||
|
|
||||||
function handleClick() {
|
function handleClick() {
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,17 @@ import { useState } from 'react';
|
||||||
import { Header } from './header';
|
import { Header } from './header';
|
||||||
import { Footer } from './footer';
|
import { Footer } from './footer';
|
||||||
import { PhotoCard } from './photo_card';
|
import { PhotoCard } from './photo_card';
|
||||||
|
import type { PicsumData } from '../api/picsum';
|
||||||
|
|
||||||
|
interface PhotosProps {
|
||||||
|
imageData: PicsumData[];
|
||||||
|
isGallery: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export function PhotoGallery() {
|
export function PhotoGallery() {
|
||||||
const imageData = useLoaderData();
|
const imageData: PicsumData[] = useLoaderData();
|
||||||
const [isGallery, setGallery] = useState(false);
|
const [isGallery, setGallery] = useState(false);
|
||||||
|
const [favorites, setFavorites] = useState();
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Header isGallery={isGallery} handleClick={()=> setGallery(!isGallery)} />
|
<Header isGallery={isGallery} handleClick={()=> setGallery(!isGallery)} />
|
||||||
|
|
@ -19,7 +26,15 @@ export function PhotoGallery() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Photos({ imageData, isGallery}) {
|
function favorites() {
|
||||||
|
return (
|
||||||
|
<button onClick={() => {}
|
||||||
|
}>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Photos({ imageData, isGallery }: PhotosProps) {
|
||||||
const listClassNames = "flex flex-wrap"
|
const listClassNames = "flex flex-wrap"
|
||||||
const galleryClassNames = "grid md:grid-cols-2 xl:grid-cols-3"
|
const galleryClassNames = "grid md:grid-cols-2 xl:grid-cols-3"
|
||||||
const photoCards = imageData.map(image =>
|
const photoCards = imageData.map(image =>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue