feat: fetch and pass previous weather entries through component tree

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 17:00:12 +01:00
parent 9b8c9efbd6
commit 3b212d6dda
3 changed files with 35 additions and 6 deletions

View File

@@ -2,7 +2,7 @@ import { notFound } from 'next/navigation';
import Link from 'next/link'; import Link from 'next/link';
import { auth } from '@/lib/auth'; import { auth } from '@/lib/auth';
import { getWorkshop, getSessionsTabUrl } from '@/lib/workshops'; import { getWorkshop, getSessionsTabUrl } from '@/lib/workshops';
import { getWeatherSessionById } from '@/services/weather'; import { getWeatherSessionById, getPreviousWeatherEntriesForUsers } from '@/services/weather';
import { getUserTeams } from '@/services/teams'; import { getUserTeams } from '@/services/teams';
import { WeatherBoard, WeatherLiveWrapper, WeatherInfoPanel, WeatherAverageBar } from '@/components/weather'; import { WeatherBoard, WeatherLiveWrapper, WeatherInfoPanel, WeatherAverageBar } from '@/components/weather';
import { Badge } from '@/components/ui'; import { Badge } from '@/components/ui';
@@ -20,15 +20,22 @@ export default async function WeatherSessionPage({ params }: WeatherSessionPageP
return null; return null;
} }
const [session, userTeams] = await Promise.all([ const session = await getWeatherSessionById(id, authSession.user.id);
getWeatherSessionById(id, authSession.user.id),
getUserTeams(authSession.user.id),
]);
if (!session) { if (!session) {
notFound(); notFound();
} }
const allUserIds = [
session.user.id,
...session.shares.map((s: { userId: string }) => s.userId),
];
const [previousEntries, userTeams] = await Promise.all([
getPreviousWeatherEntriesForUsers(session.id, session.date, allUserIds),
getUserTeams(authSession.user.id),
]);
return ( return (
<main className="mx-auto max-w-7xl px-4 py-8"> <main className="mx-auto max-w-7xl px-4 py-8">
{/* Header */} {/* Header */}
@@ -99,6 +106,7 @@ export default async function WeatherSessionPage({ params }: WeatherSessionPageP
email: session.user.email ?? '', email: session.user.email ?? '',
}} }}
canEdit={session.canEdit} canEdit={session.canEdit}
previousEntries={previousEntries}
/> />
</WeatherLiveWrapper> </WeatherLiveWrapper>
</main> </main>

View File

@@ -28,6 +28,13 @@ interface Share {
}; };
} }
type PreviousEntry = {
performanceEmoji: string | null;
moralEmoji: string | null;
fluxEmoji: string | null;
valueCreationEmoji: string | null;
};
interface WeatherBoardProps { interface WeatherBoardProps {
sessionId: string; sessionId: string;
currentUserId: string; currentUserId: string;
@@ -44,6 +51,7 @@ interface WeatherBoardProps {
email: string; email: string;
}; };
canEdit: boolean; canEdit: boolean;
previousEntries: Map<string, PreviousEntry>;
} }
export function WeatherBoard({ export function WeatherBoard({
@@ -53,6 +61,7 @@ export function WeatherBoard({
shares, shares,
owner, owner,
canEdit, canEdit,
previousEntries,
}: WeatherBoardProps) { }: WeatherBoardProps) {
// Get all users who have access: owner + shared users // Get all users who have access: owner + shared users
const allUsers = useMemo(() => { const allUsers = useMemo(() => {
@@ -137,6 +146,7 @@ export function WeatherBoard({
currentUserId={currentUserId} currentUserId={currentUserId}
entry={entry} entry={entry}
canEdit={canEdit} canEdit={canEdit}
previousEntry={previousEntries.get(entry.userId) ?? null}
/> />
))} ))}
</tbody> </tbody>

View File

@@ -22,14 +22,22 @@ interface WeatherEntry {
}; };
} }
type PreviousEntry = {
performanceEmoji: string | null;
moralEmoji: string | null;
fluxEmoji: string | null;
valueCreationEmoji: string | null;
};
interface WeatherCardProps { interface WeatherCardProps {
sessionId: string; sessionId: string;
currentUserId: string; currentUserId: string;
entry: WeatherEntry; entry: WeatherEntry;
canEdit: boolean; canEdit: boolean;
previousEntry?: PreviousEntry | null;
} }
export function WeatherCard({ sessionId, currentUserId, entry, canEdit }: WeatherCardProps) { export function WeatherCard({ sessionId, currentUserId, entry, canEdit, previousEntry }: WeatherCardProps) {
const [isPending, startTransition] = useTransition(); const [isPending, startTransition] = useTransition();
const [notes, setNotes] = useState(entry.notes || ''); const [notes, setNotes] = useState(entry.notes || '');
const [performanceEmoji, setPerformanceEmoji] = useState(entry.performanceEmoji || null); const [performanceEmoji, setPerformanceEmoji] = useState(entry.performanceEmoji || null);
@@ -104,6 +112,9 @@ export function WeatherCard({ sessionId, currentUserId, entry, canEdit }: Weathe
// For now, we'll use a placeholder - in real app, you'd pass user info as prop // For now, we'll use a placeholder - in real app, you'd pass user info as prop
const user = entry.user; const user = entry.user;
// previousEntry is available for future use in Task 6
void previousEntry;
return ( return (
<tr className={`border-b border-border ${isPending ? 'opacity-50' : ''}`}> <tr className={`border-b border-border ${isPending ? 'opacity-50' : ''}`}>
{/* User column */} {/* User column */}