Skip to content

Commit

Permalink
Merge pull request #637 from danactive/view-by-age
Browse files Browse the repository at this point in the history
View by age
  • Loading branch information
danactive authored Nov 30, 2024
2 parents 4b4a2bd + a3987b4 commit cc41c0d
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 122 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "jest --watch",
"test:ci": "jest --ci",
"test:e2e": "npx playwright test",
"typecheck": "tsc",
"typecheck": "echo 'Typecheck...' && tsc",
"release": "standard-version"
},
"dependencies": {
Expand Down
43 changes: 7 additions & 36 deletions pages/[gallery].tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
import type { GetStaticPaths, GetStaticProps } from 'next'
import Head from 'next/head'
import { type ParsedUrlQuery } from 'node:querystring'

import GalleryPageComponent from '../src/components/GalleryPage'
import getAlbums from '../src/lib/albums'
import getGalleries from '../src/lib/galleries'
import indexKeywords from '../src/lib/search'
import type { ServerSideAlbumItem } from '../src/types/common'
import { Gallery } from '../src/types/pages'

import Galleries from '../src/components/Albums'
import Link from '../src/components/Link'
import useSearch from '../src/hooks/useSearch'
import type { AlbumMeta, IndexedKeywords, ServerSideAlbumItem } from '../src/types/common'

type ComponentProps = {
gallery: NonNullable<AlbumMeta['gallery']>;
albums: ServerSideAlbumItem[];
indexedKeywords: IndexedKeywords[];
}

interface Params extends ParsedUrlQuery {
gallery: NonNullable<AlbumMeta['gallery']>
}

export const getStaticProps: GetStaticProps<ComponentProps, Params> = async (context) => {
export const getStaticProps: GetStaticProps<Gallery.ComponentProps, Gallery.Params> = async (context) => {
const params = context.params!
const { albums } = await getAlbums(params.gallery)
const preparedAlbums = albums.map((album): ServerSideAlbumItem => ({
Expand All @@ -43,25 +29,10 @@ export const getStaticPaths: GetStaticPaths = async () => {
}
}

function AlbumsPage({ gallery, albums, indexedKeywords }: ComponentProps) {
const {
filtered,
searchBox,
} = useSearch({ items: albums, indexedKeywords })

function GalleryPage({ gallery, albums, indexedKeywords }: Gallery.ComponentProps) {
return (
<div>
<Head>
<title>History App - List Albums</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<div>{searchBox}</div>
<h1>Links</h1>
<ul><li><Link href={`/${gallery}/all`}>All</Link></li></ul>
<ul><li><Link href={`/${gallery}/today`}>Today</Link></li></ul>
<Galleries items={filtered} gallery={gallery} />
</div>
<GalleryPageComponent albums={albums} gallery={gallery} indexedKeywords={indexedKeywords} />
)
}

export default AlbumsPage
export default GalleryPage
21 changes: 3 additions & 18 deletions pages/[gallery]/[album].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getAlbum from '../../src/lib/album'
import getAlbums from '../../src/lib/albums'
import getGalleries from '../../src/lib/galleries'
import indexKeywords, { addGeographyToSearch } from '../../src/lib/search'
import type { AlbumMeta, IndexedKeywords, Item } from '../../src/types/common'
import type { Album } from '../../src/types/pages'

async function buildStaticPaths() {
const { galleries } = await getGalleries()
Expand All @@ -17,22 +17,7 @@ async function buildStaticPaths() {
return groups.flat()
}

interface ServerSideAlbumItem extends Item {
corpus: string;
}

type ComponentProps = {
items?: ServerSideAlbumItem[];
meta: AlbumMeta;
indexedKeywords: IndexedKeywords[];
}

interface Params extends ParsedUrlQuery {
gallery: NonNullable<AlbumMeta['gallery']>
album: NonNullable<AlbumMeta['albumName']>
}

export const getStaticProps: GetStaticProps<ComponentProps, Params> = async (context) => {
export const getStaticProps: GetStaticProps<Album.ComponentProps, Album.Params> = async (context) => {
const params = context.params!
const { album: { items, meta } } = await getAlbum(params.gallery, params.album)
const preparedItems = items.map((item) => ({
Expand All @@ -54,7 +39,7 @@ export const getStaticPaths: GetStaticPaths = async () => (
}
)

function AlbumPage({ items = [], meta, indexedKeywords }: ComponentProps) {
function AlbumPage({ items = [], meta, indexedKeywords }: Album.ComponentProps) {
return <AlbumPageComponent items={items} meta={meta} indexedKeywords={indexedKeywords} />
}

Expand Down
15 changes: 0 additions & 15 deletions pages/[gallery]/[album]/nearby.tsx

This file was deleted.

Loading

0 comments on commit cc41c0d

Please sign in to comment.