Fix active source detection by including team names in lookup

- Update streams API to join with teams table and return StreamWithTeam data
- Modify stream lookup maps to generate proper stream group names with team prefixes
- Format: {team_name}_{stream_name}_stream to match obsClient.js logic
- Update type signatures throughout to support team_name and group_name fields
- Now properly matches text file contents with database streams for dropdown selection

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Decobus 2025-07-22 15:06:21 -04:00
parent 5dd9707f13
commit f9363eac20
3 changed files with 20 additions and 14 deletions

View file

@ -1,13 +1,20 @@
import { NextResponse } from 'next/server';
import { getDatabase } from '../../../lib/database';
import { Stream } from '@/types';
import { StreamWithTeam } from '@/types';
import { TABLE_NAMES } from '../../../lib/constants';
import { createSuccessResponse, createDatabaseError, withErrorHandling } from '../../../lib/apiHelpers';
async function getStreamsHandler() {
try {
const db = await getDatabase();
const streams: Stream[] = await db.all(`SELECT * FROM ${TABLE_NAMES.STREAMS}`);
const streams: StreamWithTeam[] = await db.all(`
SELECT
s.*,
t.team_name,
t.group_name
FROM ${TABLE_NAMES.STREAMS} s
LEFT JOIN ${TABLE_NAMES.TEAMS} t ON s.team_id = t.team_id
`);
return createSuccessResponse(streams);
} catch (error) {
return createDatabaseError('fetch streams', error);

View file

@ -7,17 +7,12 @@ import { useToast } from '@/lib/useToast';
import { ToastContainer } from '@/components/Toast';
import { useActiveSourceLookup, useDebounce, PerformanceMonitor } from '@/lib/performance';
type Stream = {
id: number;
name: string;
obs_source_name: string;
url: string;
};
import { StreamWithTeam } from '@/types';
type ScreenType = 'large' | 'left' | 'right' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
export default function Home() {
const [streams, setStreams] = useState<Stream[]>([]);
const [streams, setStreams] = useState<StreamWithTeam[]>([]);
const [activeSources, setActiveSources] = useState<Record<ScreenType, string | null>>({
large: null,
left: null,