Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/components/Section.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.section {
margin-bottom: 3rem;
}

.section > h2 {
margin: 0 0 1rem;
}

.section-skeleton {
border-radius: 0.5rem;
background: linear-gradient(90deg, #1a1a1a 25%, #2a2a2a 50%, #1a1a1a 75%);
Expand Down
5 changes: 3 additions & 2 deletions src/components/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// denne filen eier overskrift + laster/feil-håndtering, tar innholdet som 'children':

import './Section.css';
import type { ReactNode } from 'react';

type SectionProps = {
Expand All @@ -13,8 +14,8 @@ type SectionProps = {

export function Section({ id, title, isLoading, error, children, skeletonHeight="300px"}: SectionProps) {
return (
<section id={id}>
<h2>{title}</h2>
<section id={id} className = "section">
{title && <h2>{title}</h2>}
{isLoading && <div className="section-skeleton" style={{height: skeletonHeight}}/>}
{error && <p>Noe gikk galt: {error.message}</p>}
{!isLoading && !error && children}
Expand Down
9 changes: 3 additions & 6 deletions src/layout/MainLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MovieList } from "../components/MovieList";
import { PersonList } from "../components/PersonList";

import { Section } from "../components/Section";
import { TrendingPreview } from "../components/TrendingPreview";
import { useCurMovies, usePopMovies } from "../hooks/useMovies";
import { usePopularPeople } from "../hooks/usePeople";

import type { Movie } from "../types/tmdb";
import { sortAndFilterMovies, type SortOption } from "../utils/sortAndFilterMovies";

Expand All @@ -19,7 +19,7 @@ type MainLayoutProps = {
export function MainLayout({ sortBy, minRating, isFavorite, toggleFavorite, onSelectMovie }: MainLayoutProps) {
const popular = usePopMovies();
const current = useCurMovies();
const people = usePopularPeople();


return (
<>
Expand All @@ -32,9 +32,6 @@ export function MainLayout({ sortBy, minRating, isFavorite, toggleFavorite, onSe
<Section id="nye-filmer" title="Nye filmer" isLoading={current.isLoading} error={current.error}>
{current.data && <MovieList movies={sortAndFilterMovies(current.data, sortBy, minRating)} isFavorite={isFavorite} onToggleFavorite={toggleFavorite} onSelectMovie={onSelectMovie} />}
</Section>
<Section id="skuespillere" title="Skuespillere" isLoading={people.isLoading} error={people.error}>
{people.data && <PersonList people={people.data.results} />}
</Section>
</>
);
}