Skip to content

Commit e998b5a

Browse files
committed
Sort by time or weather
Cleanup to sorting as well
1 parent f216562 commit e998b5a

File tree

9 files changed

+72
-55
lines changed

9 files changed

+72
-55
lines changed

app/home-client.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { useState } from 'react';
55
import Header from './ui/header';
66
import SkyboxGrid from './ui/skyboxgrid';
77

8-
type SortOption = 'alpha' | 'alpha-desc' | 'published-date-desc' | 'published-date-asc';
8+
import { SortOption } from './ui/sort-types';
99

1010
interface HomeClientProps {
1111
slugs: string[];
1212
meta: Record<string, any>;
1313
}
1414

1515
export default function HomeClient({ slugs, meta }: HomeClientProps) {
16-
const [sort, setSort] = useState<SortOption>('published-date-desc');
16+
const [sort, setSort] = useState<SortOption>('time-of-day');
1717
const [query, setQuery] = useState('');
1818

1919
return (

app/ui/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { profileLinks } from './profile-links';
99

1010
import SortSelect from './sort-select';
1111

12-
type SortOption = 'alpha' | 'alpha-desc' | 'published-date-desc' | 'published-date-asc';
12+
import { SortOption } from './sort-types';
1313

1414
/* ------------------ main header ------------------ */
1515
interface HeaderProps {

app/ui/moremenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import type { Dispatch, SetStateAction } from 'react';
55
import { useState } from 'react';
66
import IconLink from './iconlink';
7-
import SortSelect from './sort-select'; // Import SortSelect
7+
import SortSelect from './sort-select';
88

99
// Types matching those in Header/Page
10-
type SortOption = 'alpha' | 'alpha-desc' | 'published-date-desc' | 'published-date-asc';
10+
import { SortOption } from './sort-types';
1111
interface ProfileLink {
1212
href: string;
1313
label: string;

app/ui/skyboxgrid.tsx

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,82 @@ import { useMemo } from 'react';
33
import SkyboxCard from './skyboxcard';
44

55
// Define the SortOption type matching the one in header.tsx / page.tsx
6-
type SortOption = 'alpha' | 'alpha-desc' | 'published-date-desc' | 'published-date-asc';
6+
import { SortOption } from './sort-types';
7+
8+
const TIME_OF_DAY_ORDER = ['Morning', 'Afternoon', 'Evening', 'Night', 'Other'];
9+
const WEATHER_CONDITIONS_ORDER = ['Clear', 'Cloudy', 'Hazy', 'Overcast', 'Other'];
710

811
export default function SkyboxGrid({
912
slugs,
1013
meta,
11-
sort,
14+
sort = 'time-of-day',
1215
query,
1316
}: {
1417
slugs: string[];
1518
meta: Record<string, any>;
16-
sort: SortOption;
19+
sort?: SortOption;
1720
query: string;
1821
}) {
19-
2022
const visible = useMemo(() => {
2123
let list = [...slugs];
2224
// Filter based on query prop
2325
if (query) {
2426
const q = query.toLowerCase();
2527
list = list.filter((s) => s.includes(q) || meta[s]?.title?.toLowerCase().includes(q));
2628
}
27-
// Sort based on sort prop
28-
switch (sort) {
29-
case 'alpha-desc':
30-
list.sort().reverse(); // Z-A
31-
break;
32-
case 'published-date-desc': // Newest to Oldest
33-
list.sort((a, b) => {
34-
const dateA = meta[a]?.publishDate ? new Date(meta[a].publishDate).getTime() : 0;
35-
const dateB = meta[b]?.publishDate ? new Date(meta[b].publishDate).getTime() : 0;
36-
return dateB - dateA; // Sorts undefined/null dates to the end (as oldest)
37-
});
38-
break;
39-
case 'published-date-asc': // Oldest to Newest
40-
list.sort((a, b) => {
41-
const dateA = meta[a]?.publishDate ? new Date(meta[a].publishDate).getTime() : Number.MAX_SAFE_INTEGER;
42-
const dateB = meta[b]?.publishDate ? new Date(meta[b].publishDate).getTime() : Number.MAX_SAFE_INTEGER;
43-
return dateA - dateB; // Sorts undefined/null dates to the end (as newest)
44-
});
45-
break;
46-
case 'alpha': // A-Z
47-
default:
48-
list.sort();
49-
break;
50-
}
29+
return list;
30+
}, [slugs, meta, query]);
31+
32+
// Group skyboxes by time of day or weather conditions
33+
const groupedSkyboxes = useMemo(() => {
34+
console.log(sort);
35+
if (sort === 'time-of-day') {
36+
const groups: Record<string, string[]> = {};
5137

52-
return list; // Add this line back
53-
}, [slugs, meta, query, sort]); // Update dependencies
38+
visible.forEach((slug) => {
39+
const timeOfDay = meta[slug]?.timeOfDay || 'Other';
40+
if (!groups[timeOfDay]) {
41+
groups[timeOfDay] = [];
42+
}
43+
groups[timeOfDay].push(slug);
44+
});
45+
46+
// Sort groups by predefined time of day order
47+
return TIME_OF_DAY_ORDER
48+
.filter(time => groups[time])
49+
.map(time => ({ title: time, slugs: groups[time] }));
50+
} else {
51+
const groups: Record<string, string[]> = {};
52+
53+
visible.forEach((slug) => {
54+
const weatherCondition = meta[slug]?.weatherCondition || 'Other';
55+
if (!groups[weatherCondition]) {
56+
groups[weatherCondition] = [];
57+
}
58+
groups[weatherCondition].push(slug);
59+
});
60+
61+
// Sort groups by predefined weather conditions order
62+
return WEATHER_CONDITIONS_ORDER
63+
.filter(weather => groups[weather])
64+
.map(weather => ({ title: weather, slugs: groups[weather] }));
65+
}
66+
}, [visible, meta, sort]);
5467

5568
return (
56-
// Correctly render only the grid section
57-
<section
58-
className="
59-
grid gap-4 pt-6
60-
grid-cols-[repeat(auto-fill,minmax(16rem,1fr))]
61-
sm:grid-cols-[repeat(auto-fill,minmax(18rem,1fr))]
62-
lg:grid-cols-[repeat(auto-fill,minmax(22rem,1fr))]
63-
2xl:grid-cols-[repeat(auto-fill,minmax(26rem,1fr))]
64-
px-4 sm:px-6 lg:px-8
65-
"
66-
>
67-
{visible.map((slug) => (
68-
<SkyboxCard key={slug} slug={slug} meta={meta[slug]} />
69+
<div className="space-y-8 mx-auto px-4 py-8">
70+
{groupedSkyboxes.map(({ title, slugs }) => (
71+
<div key={title}>
72+
<div className="flex items-center justify-between mb-4">
73+
<h2 className="text-2xl font-bold text-neutral-200">{title} Skies</h2>
74+
</div>
75+
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">
76+
{slugs.map((slug) => (
77+
<SkyboxCard key={slug} slug={slug} meta={meta[slug]} />
78+
))}
79+
</div>
80+
</div>
6981
))}
70-
</section>
82+
</div>
7183
);
7284
}

app/ui/sort-select.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/* app/ui/sort-select.tsx */
21
'use client';
32

4-
type SortOption = 'alpha' | 'alpha-desc' | 'published-date-desc' | 'published-date-asc';
3+
import { SortOption } from './sort-types';
54

65
interface SortSelectProps {
76
value: SortOption;
@@ -19,10 +18,8 @@ export default function SortSelect({ value, onChange }: SortSelectProps) {
1918
focus:outline-none focus:ring-2 focus:ring-amber-500
2019
"
2120
>
22-
<option value="published-date-desc">Newest</option>
23-
<option value="alpha">Name A → Z</option>
24-
<option value="alpha-desc">Name Z → A</option>
25-
<option value="published-date-asc">Oldest</option>
21+
<option value="time-of-day">Time of Day</option>
22+
<option value="weather-conditions">Weather Conditions</option>
2623
</select>
2724
);
2825
}

app/ui/sort-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Centralized type definition for sort options
2+
export type SortOption = 'time-of-day' | 'weather-conditions';

public/data/sky_fracture01_hdr.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"categories": [
77
"Misc"
88
],
9+
"timeOfDay": "Unknown",
10+
"weatherCondition": "Unknown",
911
"sunParameters": {
1012
"sunAngle": "0 210 0",
1113
"pitch": "-40",

public/data/sky_lab_hdr.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"categories": [
77
"Misc"
88
],
9+
"timeOfDay": "Unknown",
10+
"weatherCondition": "Unknown",
911
"sunParameters": {
1012
"sunAngle": "0 61.5 0",
1113
"pitch": "-17",

public/data/sky_serene_glow_hdr.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"categories": [
77
"Misc"
88
],
9+
"timeOfDay": "Unknown",
10+
"weatherCondition": "Unknown",
911
"sunParameters": {
1012
"sunAngle": "0 128 0",
1113
"pitch": "-44",

0 commit comments

Comments
 (0)