Skip to content

Commit

Permalink
fix: solved errors and conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Sep 11, 2024
1 parent 1f579c5 commit 0f2d040
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 204 deletions.
7 changes: 3 additions & 4 deletions src/api/ateliereLive/pipelines/multiviews/multiviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ export async function createMultiviewForPipeline(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
productionSettings.pipelines[multiviewIndex].pipeline_id!;
const sources = await getSourcesByIds(
sourceRefs.map((ref) => ref._id.toString())
sourceRefs.map((ref) => (ref._id ? ref._id.toString() : ''))
);
const sourceRefsWithLabels = sourceRefs.map((ref) => {
const refId = ref._id ? ref._id.toString() : '';
if (!ref.label) {
const source = sources.find(
(source) => source._id.toString() === ref._id.toString()
);
const source = sources.find((source) => source._id.toString() === refId);
ref.label = source?.name || '';
}
return ref;
Expand Down
2 changes: 2 additions & 0 deletions src/api/manager/productions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export async function putProduction(
name: production.name,
isActive: production.isActive,
sources: sources,
html: [],
mediaplayers: [],
production_settings: production.production_settings
};
}
Expand Down
1 change: 0 additions & 1 deletion src/api/manager/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export async function getSourcesByIds(
const db = await getDatabase().catch(() => {
throw new Error("Can't connect to Database");
});

const objectIds = _ids.map((id: string) => new ObjectId(id));

const sources = await db
Expand Down
3 changes: 1 addition & 2 deletions src/app/production/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export default function ProductionConfiguration({ params }: PageProps) {

if (!productionSetup) return;
addSource(input, productionSetup).then((updatedSetup) => {

if (!updatedSetup) return;
setSourceReferenceToAdd(updatedSetup.sources[0]);
setProductionSetup(updatedSetup);
Expand Down Expand Up @@ -720,7 +719,7 @@ export default function ProductionConfiguration({ params }: PageProps) {
{productionSetup?.sources && sources.size > 0 && (
<DndProvider backend={HTML5Backend}>
<SourceCards
sourceRef={sourceReferenceToAdd}
// sourceRef={sourceReferenceToAdd}
productionSetup={productionSetup}
updateProduction={(updated) => {
updateProduction(productionSetup._id, updated);
Expand Down
2 changes: 1 addition & 1 deletion src/components/inventory/Inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function Inventory() {
<ul
className={`flex flex-col border-t border-gray-600 overflow-scroll h-[95%] ${styles.no_scrollbar}`}
>
{loading ? '' : getSourcesToDisplay(filteredSources)}
{getSourcesToDisplay(filteredSources)}
</ul>
</div>
</div>
Expand Down
123 changes: 38 additions & 85 deletions src/components/sourceCard/SourceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import { useTranslate } from '../../i18n/useTranslate';
import { ISource } from '../../hooks/useDragableItems';

type SourceCardProps = {
source?: ISource;
source: ISource;
label: string;
onSourceUpdate: (source: SourceReference) => void;
onSourceUpdate: (source: SourceReference, sourceItem: ISource) => void;
onSourceRemoval: (source: SourceReference) => void;
onSelectingText: (bool: boolean) => void;
forwardedRef?: React.LegacyRef<HTMLDivElement>;
style?: object;
src?: string;
sourceRef?: SourceReference;
type: Type;
src: string;
};

export default function SourceCard({
Expand All @@ -28,13 +26,9 @@ export default function SourceCard({
onSelectingText,
forwardedRef,
src,
style,
sourceRef,
type
style
}: SourceCardProps) {
const [sourceLabel, setSourceLabel] = useState(
sourceRef?.label || source?.name
);
const [sourceLabel, setSourceLabel] = useState(label ? label : source.name);

const t = useTranslate();

Expand All @@ -43,29 +37,21 @@ export default function SourceCard({
};
const saveText = () => {
onSelectingText(false);
if (sourceLabel?.length === 0) {
if (source) {
setSourceLabel(source.name);
} else if (sourceRef) {
setSourceLabel(sourceRef.label);
}
// if (source.name === label) {
// return;
// }
if (sourceLabel.length === 0) {
setSourceLabel(source.name);
}

if (source) {
onSourceUpdate({
onSourceUpdate(
{
_id: source._id.toString(),
type: 'ingest_source',
label: sourceLabel || source.name,
label: sourceLabel,
type: source.ingest_type as Type,
input_slot: source.input_slot
});
} else if (sourceRef) {
onSourceUpdate({
_id: sourceRef._id,
type: sourceRef.type,
label: sourceLabel || sourceRef.label,
input_slot: sourceRef.input_slot
});
}
},
source
);
};

const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
Expand All @@ -83,7 +69,7 @@ export default function SourceCard({
<div className="relative">
<input
className={`absolute bg-zinc-900 text-center hover:border focus:hover:border-none w-full text-p bg-opacity-90 focus:bg-opacity-100`}
value={source ? source.label : sourceRef?.label}
value={sourceLabel}
onChange={updateText}
onKeyDown={handleKeyDown}
onSelect={() => {
Expand All @@ -92,59 +78,26 @@ export default function SourceCard({
onBlur={saveText}
/>
</div>
{source && source.src && (
<SourceThumbnail source={source} src={src} type={type} />
)}
{!source && sourceRef && <SourceThumbnail type={sourceRef.type} />}
{(sourceRef || source) && (
<h2
className={`${
source && 'absolute bottom-4'
} p-1 text-p text-xs bg-zinc-900 w-full bg-opacity-90 ${
sourceRef && !source && 'absolute bottom-0'
}`}
>
{t('source.input_slot', {
input_slot:
sourceRef?.input_slot?.toString() ||
source?.input_slot?.toString() ||
''
})}
</h2>
)}

{source && (
<h2 className="absolute bottom-0 text-p text-xs bg-zinc-900 w-full bg-opacity-90">
{t('source.ingest', {
ingest: source.ingest_name
})}
</h2>
)}
{(source || sourceRef) && (
<button
className="absolute bottom-0 right-0 text-p hover:border-l hover:border-t bg-red-700 hover:bg-red-600 min-w-fit p-1 rounded-tl-lg"
onClick={() => {
if (source) {
onSourceRemoval({
_id: source._id.toString(),
type: 'ingest_source',
label: sourceLabel || source.name,
input_slot: source.input_slot,
stream_uuids: source.stream_uuids
});
} else if (sourceRef && !source) {
onSourceRemoval({
_id: sourceRef._id,
type: sourceRef.type,
label: sourceRef.label,
input_slot: sourceRef.input_slot
});
}
}}
>
<IconTrash className="text-p w-4 h-4" />
</button>
)}
<SourceThumbnail source={source} src={src} />
<h2 className="absolute bottom-0 text-p text-xs bg-zinc-900 w-full bg-opacity-90">
{t('source.ingest', {
ingest: source.ingest_name
})}
</h2>
<button
className="absolute bottom-0 right-0 text-p hover:border-l hover:border-t bg-red-700 hover:bg-red-600 min-w-fit p-1 rounded-tl-lg"
onClick={() => {
onSourceRemoval({
_id: source._id.toString(),
label: source.label,
type: source.ingest_type as Type,
input_slot: source.input_slot,
stream_uuids: source.stream_uuids
});
}}
>
<IconTrash className="text-p w-4 h-4" />
</button>
</div>
);
}
143 changes: 88 additions & 55 deletions src/components/sourceCards/SourceCards.tsx
Original file line number Diff line number Diff line change
@@ -1,80 +1,113 @@
'use client';

import React, { useState } from 'react';
import { SourceReference } from '../../interfaces/Source';
import { SourceReference, Type } from '../../interfaces/Source';
import { Production } from '../../interfaces/production';
import DragItem from '../dragElement/DragItem';
import SourceCard from '../sourceCard/SourceCard';
import { EmptySlotCard } from '../emptySlotCard/EmptySlotCard';
import { ISource, useDragableItems } from '../../hooks/useDragableItems';

export default function SourceCards({
productionSetup,
sourceRef,
updateProduction,
onSourceUpdate,
onSourceRemoval
}: {
productionSetup: Production;
sourceRef?: SourceReference;
updateProduction: (updated: Production) => void;
onSourceUpdate: (source: SourceReference) => void;
onSourceUpdate: (source: SourceReference, sourceItem: ISource) => void;
onSourceRemoval: (source: SourceReference) => void;
}) {
const [items, moveItem, loading] = useDragableItems(productionSetup.sources);
const [selectingText, setSelectingText] = useState(false);
const currentOrder: SourceReference[] = items.map((source) => {
return {
_id: source._id.toString(),
label: source.label,
type: source.ingest_type as Type,
input_slot: source.input_slot,
stream_uuids: source.stream_uuids
};
});

if (loading || !items) return null;

// Filter SourceReference and ISource objects correctly
const sourceReferences = items.filter(
(item): item is SourceReference => item.type !== 'ingest_source'
);

const isISource = (source: SourceReference | ISource): source is ISource => {
// Use properties unique to ISource to check the type
return 'src' in source;
};

const gridItems = items.map((source) => {
const isSource = isISource(source);

if (!source._id) return;
const gridItems: React.JSX.Element[] = [];
let tempItems = [...items];
let firstEmptySlot = items.length + 1;

return (
<DragItem
key={source._id.toString()}
id={source._id.toString()}
onMoveItem={moveItem}
previousOrder={productionSetup.sources}
currentOrder={sourceReferences}
productionSetup={productionSetup}
updateProduction={updateProduction}
selectingText={selectingText}
>
{isSource ? (
<SourceCard
source={source}
sourceRef={sourceRef}
label={source.label}
src={source.src}
onSourceUpdate={onSourceUpdate}
onSourceRemoval={onSourceRemoval}
onSelectingText={(isSelecting) => setSelectingText(isSelecting)}
type={'ingest_source'}
/>
) : (
<SourceCard
sourceRef={source}
label={source.label}
onSourceUpdate={onSourceUpdate}
onSourceRemoval={onSourceRemoval}
onSelectingText={(isSelecting) => setSelectingText(isSelecting)}
type={source.type}
/>
)}
</DragItem>
);
});
if (!items || items.length === 0) return null;
for (let i = 0; i < items[items.length - 1].input_slot; i++) {
if (!items.some((source) => source.input_slot === i + 1)) {
firstEmptySlot = i + 1;
break;
}
}
for (let i = 0; i < items[items.length - 1].input_slot; i++) {
// console.log(`On input slot: ${i + 1}`);
// console.log(`Checking sources:`);
// console.log(tempItems);
tempItems.every((source) => {
if (source.input_slot === i + 1) {
// console.log(`Found source on input slot: ${i + 1}`);
// console.log(`Removing source "${source.name}" from sources list`);
tempItems = tempItems.filter((i) => i._id !== source._id);
// console.log(`Adding source "${source.name}" to grid`);
if (!productionSetup.isActive) {
gridItems.push(
<DragItem
key={`${source.ingest_source_name}-${source.input_slot}-key`}
id={source._id}
onMoveItem={moveItem}
previousOrder={productionSetup.sources}
currentOrder={currentOrder}
productionSetup={productionSetup}
updateProduction={updateProduction}
selectingText={selectingText}
>
<SourceCard
source={source}
label={source.label}
src={source.src}
onSourceUpdate={onSourceUpdate}
onSourceRemoval={onSourceRemoval}
onSelectingText={(isSelecting: boolean) =>
setSelectingText(isSelecting)
}
/>
</DragItem>
);
} else {
gridItems.push(
<SourceCard
key={`${source.ingest_source_name}-${source.input_slot}-key`}
source={source}
label={source.label}
src={source.src}
onSourceUpdate={onSourceUpdate}
onSourceRemoval={onSourceRemoval}
onSelectingText={(isSelecting: boolean) =>
setSelectingText(isSelecting)
}
/>
);
}
return false;
} else {
// console.log(`No source found on input slot: ${i + 1}`);
// console.log(`Adding empty slot to grid`);
if (productionSetup.isActive) {
gridItems.push(
<EmptySlotCard
key={i}
inputSlot={i + 1}
isFirstEmptySlot={firstEmptySlot === i + 1}
/>
);
}

return false;
}
});
}
return <>{gridItems}</>;
}
Loading

0 comments on commit 0f2d040

Please sign in to comment.