Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 Corrige bug de requisição infinita das imagens do tixxi #3

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,30 @@ const InfoItem = ({
export function CameraInfo({
pickingInfo,
}: {
pickingInfo: PickingInfo<Camera>
pickingInfo: PickingInfo<Camera> | undefined | null
}) {
const [isLoading, setIsLoading] = useState(true)
const { object } = pickingInfo

useEffect(() => {
setIsLoading(true)
}, [object])
}, [pickingInfo?.object])

return (
<div className={cn('h-full w-full', object ? '' : 'hidden')}>
<div className={cn('h-full w-full', pickingInfo?.object ? '' : 'hidden')}>
<h4>Câmera COR</h4>
<Separator className="mb-4 mt-1 bg-secondary" />
<div className="flex flex-col gap-4">
<InfoItem icon={Hash} label="ID" value={object?.id} />
<InfoItem icon={Hash} label="ID" value={pickingInfo?.object?.id} />

<InfoItem
icon={MapPin}
label="Localidade"
value={`${object?.name} - ${object?.zone}`}
value={`${pickingInfo?.object?.name} - ${pickingInfo?.object?.zone}`}
/>

<div className="relative flex aspect-video w-full items-center justify-center">
<img
src={object?.streamingUrl}
src={pickingInfo?.object?.streamingUrl}
alt="Streaming"
className={cn(
'aspect-video w-full rounded-lg bg-border',
Expand All @@ -72,7 +71,7 @@ export function CameraInfo({
className="absolute bottom-1 right-1 h-6 p-1"
>
<Link
href={object?.streamingUrl || ''}
href={pickingInfo?.object?.streamingUrl || ''}
className="text-xs text-muted-foreground"
target="_blank"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@ interface ContextMenuProps {
pickingInfo: PickingInfo | null
open: boolean
onOpenChange: (open: boolean) => void
setContextMenuPickingInfo: (pickingInfo: PickingInfo | null) => void
}

export function ContextMenu({
pickingInfo,
onOpenChange,
setContextMenuPickingInfo,
open,
}: ContextMenuProps) {
const [cardRef, setCardRef] = useState<HTMLDivElement | null>(null)
if (!pickingInfo || !pickingInfo.object) return null

const { top, left } = calculateTooltipAbsolutePosition(
pickingInfo,
cardRef?.clientWidth,
cardRef?.clientHeight,
)
const { top, left } = pickingInfo
? calculateTooltipAbsolutePosition(
pickingInfo,
cardRef?.clientWidth,
cardRef?.clientHeight,
)
: { top: 0, left: 0 }

const Content = ({ pickingInfo }: { pickingInfo: PickingInfo }) => {
if (pickingInfo?.layer?.id === 'cameras') {
return <CameraInfo pickingInfo={pickingInfo} />
}

if (pickingInfo?.layer?.id === 'AISP') {
return <AISPInfo pickingInfo={pickingInfo} />
}
Expand All @@ -50,12 +49,18 @@ export function ContextMenu({
}
}

function handleOnOpenChange(e: boolean) {
if (e === false) {
setContextMenuPickingInfo(null)
onOpenChange(false)
}
onOpenChange(true)
}

return (
<Popover open={open} onOpenChange={onOpenChange} modal={false}>
{pickingInfo.layer?.id &&
['cameras', 'AISP', 'CISP', 'schools'].includes(
pickingInfo.layer.id,
) && (
<Popover open={open} onOpenChange={handleOnOpenChange} modal={false}>
{pickingInfo?.layer?.id &&
['AISP', 'CISP', 'schools'].includes(pickingInfo.layer.id) && (
<PopoverContent
ref={(ref) => setCardRef(ref)}
style={{
Expand All @@ -68,6 +73,18 @@ export function ContextMenu({
<Content pickingInfo={pickingInfo} />
</PopoverContent>
)}
<PopoverContent
ref={(ref) => setCardRef(ref)}
style={{
position: 'absolute',
top,
left,
width: '400px',
display: pickingInfo ? 'block' : 'none',
}}
>
<CameraInfo pickingInfo={pickingInfo} />
</PopoverContent>
</Popover>
)
}
1 change: 1 addition & 0 deletions src/app/(app)/vision-ai/components/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default function Map({ mapboxAccessToken }: MapProps) {
<ContextMenu
open={openContextMenu}
onOpenChange={setOpenContextMenu}
setContextMenuPickingInfo={setContextMenuPickingInfo}
pickingInfo={contextMenuPickingInfo}
/>
</DeckGL>
Expand Down
3 changes: 1 addition & 2 deletions src/app/(app)/vision-ai/components/schemas/project-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export const projectFormSchema = z
yolo_default_precision: z.coerce
.number({ message: 'Obrigatório' })
.min(0, { message: 'Deve ser entre 0 e 1' })
.max(1, { message: 'Deve ser entre 0 e 1' })
.optional(),
.max(1, { message: 'Deve ser entre 0 e 1' }),
yolo_send_message: z.boolean().optional(),
yolo_crowd_count: z
.string()
Expand Down
3 changes: 0 additions & 3 deletions src/app/(app)/vision-ai/new-project/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export default function Page() {
useEffect(() => {
async function initializeData() {
getModelsAction().then((data) => {
console.log({ data })
setModels(data)
return data
})
Expand All @@ -110,8 +109,6 @@ export default function Page() {
initializeData()
}, [])

console.log({ models })

return (
<form
className="flex flex-col gap-2 h-screen max-h-screen px-4 py-2"
Expand Down
10 changes: 6 additions & 4 deletions src/app/(app)/vision-ai/project/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ export default function ProjectDetails() {
'yolo_crowd_count',
projectsResponse.model_config?.yolo_crowd_count,
)
setValue(
'yolo_default_precision',
projectsResponse.model_config?.yolo_default_precision,
)
if (projectsResponse.model_config?.yolo_default_precision) {
setValue(
'yolo_default_precision',
projectsResponse.model_config.yolo_default_precision,
)
}

if (projectsResponse.time_start) {
setValue(
Expand Down
1 change: 0 additions & 1 deletion src/server-cache/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export async function getProjectAction(id: string) {
}

const project: Project = await response.json()
console.log({ project })

return project
}
1 change: 0 additions & 1 deletion src/server-cache/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export async function getProjectsAction() {
}

const projects: Project[] = await response.json()
console.log({ projects })

return projects
}
Loading