Skip to content
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
1 change: 0 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ function App() {
return (
<PetDetail
pet={selectedPet}
petRecords={myRecords.filter(r => (r.petId || r.pet?.id) === selectedPet?.id)}
onBack={goBackToDashboard}
onRegisterCase={(pet) => { setSelectedPet(pet); setCurrentView('create-case'); }}
onCaseClick={handleCaseClick}
Expand Down
28 changes: 25 additions & 3 deletions frontend/src/pages/PetDetail.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import { STATUS_MAP } from '../utils/statusHelper';
import { medicalRecordService } from '../services/api';

const PetDetail = ({ pet, petRecords = [], onBack, onRegisterCase, onCaseClick }) => {
const PetDetail = ({ pet, onBack, onRegisterCase, onCaseClick }) => {
const [petRecords, setPetRecords] = useState([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
if (!pet?.id) {
setLoading(false);
return;
}
let cancelled = false;
setLoading(true);
Comment thread
TatjanaTrajkovic marked this conversation as resolved.
medicalRecordService.getRecordsByPet(pet.id)
.then(res => { if (!cancelled) setPetRecords(res.data); })
.catch(() => { if (!cancelled) setPetRecords([]); })
.finally(() => { if (!cancelled) setLoading(false); });
return () => { cancelled = true; };
}, [pet?.id]);
Comment thread
TatjanaTrajkovic marked this conversation as resolved.

if (!pet) {
return <div className="p-10 text-center italic text-slate-400">Ingen djurdata hittades.</div>;
Expand Down Expand Up @@ -66,7 +83,12 @@ const PetDetail = ({ pet, petRecords = [], onBack, onRegisterCase, onCaseClick }
</h2>

<div className="space-y-4">
{Array.isArray(petRecords) && petRecords.length > 0 ? (
{loading ? (
<div className="flex items-center gap-2 text-slate-400 py-4">
<div className="w-4 h-4 border-2 border-slate-200 border-t-blue-400 rounded-full animate-spin"></div>
<span className="text-[10px] font-bold uppercase tracking-widest italic">Laddar...</span>
</div>
) : Array.isArray(petRecords) && petRecords.length > 0 ? (
petRecords.map(record => {
const statusKey = record?.status;
const statusConfig = (STATUS_MAP && STATUS_MAP[statusKey]) || {
Expand Down