Skip to content

Commit

Permalink
Solved bug and fixed #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Meefish committed Nov 13, 2024
1 parent 234567b commit 4369904
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/pages/Experiment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import Navbar from '../components/Navbar';
import '../styles/Experiment.css';
import { getMessagesByExperimentID } from '../services/messageService';
import { Experiment as ExperimentType } from '../types/experiment';
import { updateExperiment } from '../services/experimentService'; // Import the update function

Expand Down Expand Up @@ -30,8 +29,7 @@ const Experiment: React.FC = () => {
const handleMessageOverviewClick = async () => {
if (!experiment) return;
try {
const messages = await getMessagesByExperimentID(experiment.ID);
navigate(`/messagedashboard/${experiment.ID}`, { state: { messages, experiment } });
navigate(`/messagedashboard/${experiment.ID}`);
} catch (error) {
console.error('Error fetching messages:', error);
// Optionally display an error message to the user
Expand Down
1 change: 1 addition & 0 deletions src/pages/MessageCreation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ const MessageCreation: React.FC = () => {
setSelectedSpeciesID(species.ID);
setSelectedSpeciesName(species.commonName);
setIsSpeciesDropdownOpen(false);
speciesDropdownRef.current?.setCustomValidity('');
}}
>
{species.commonName} ({species.name})
Expand Down
26 changes: 23 additions & 3 deletions src/pages/MessageDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useState, useEffect } from 'react';
import { useNavigate, useLocation, useParams } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';
import Navbar from '../components/Navbar';
import '../styles/MessageDashboard.css';
import { getMessagesByExperimentID } from '../services/messageService';

// Import types
import { Message } from '../types/message';
import { Experiment } from '../types/experiment';

interface InteractionType {
ID: string;
Expand All @@ -13,12 +15,12 @@ interface InteractionType {

const MessageDashboard: React.FC = () => {
const navigate = useNavigate();
const location = useLocation();
const { id } = useParams<{ id: string }>();

const { messages = [], experiment } = location.state || {};

const [interactionTypes, setInteractionTypes] = useState<InteractionType[]>([]);
const [messages, setMessages] = useState<Message[]>([]);
const [experiment] = useState<Experiment | null>(null);
const [filteredMessages, setFilteredMessages] = useState<Message[]>([]);
const [selectedInteractionType, setSelectedInteractionType] = useState<string>('All');
const [searchQuery, setSearchQuery] = useState<string>('');
Expand All @@ -30,6 +32,24 @@ const MessageDashboard: React.FC = () => {
// State for dropdown open/close
const [isDropdownOpen, setIsDropdownOpen] = useState(false);

// Fetch messages on component mount
useEffect(() => {
const fetchMessages = async () => {
if (!id) return;
try {
setIsLoading(true);
const fetchedMessages = await getMessagesByExperimentID(id);
setMessages(fetchedMessages);
setIsLoading(false);
} catch (error) {
console.error('Error fetching messages:', error);
setIsLoading(false);
}
};

fetchMessages();
}, [id]);

// Fetch interaction types on component mount
useEffect(() => {
const fetchData = async () => {
Expand Down

0 comments on commit 4369904

Please sign in to comment.