Skip to content

Commit

Permalink
remove date, use startTime as benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan authored and ryan committed Oct 26, 2023
1 parent 2887c5e commit fe917d8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
12 changes: 0 additions & 12 deletions contracts/EventManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ contract EventManager {
address creator;
string name;
string location;
uint date;
uint startTime;
uint endTime;
string description;
Expand All @@ -26,7 +25,6 @@ contract EventManager {
uint indexed eventId,
address indexed creator,
string indexed location,
uint date,
uint startTime,
uint endTime,
uint price
Expand All @@ -37,7 +35,6 @@ contract EventManager {
uint indexed eventId,
address indexed creator,
string indexed location,
uint date,
uint startTime,
uint endTime,
uint price
Expand All @@ -51,7 +48,6 @@ contract EventManager {
function createEvent(
string memory name,
string memory location,
uint date,
uint startTime,
uint endTime,
string memory description,
Expand All @@ -65,7 +61,6 @@ contract EventManager {
creator: msg.sender,
name: name,
location: location,
date: date,
startTime: startTime,
endTime: endTime,
description: description,
Expand All @@ -79,7 +74,6 @@ contract EventManager {
currentEventId,
msg.sender,
location,
date,
startTime,
endTime,
price
Expand All @@ -90,7 +84,6 @@ contract EventManager {
uint eventId,
string memory name,
string memory location,
uint date,
uint startTime,
uint endTime,
string memory description,
Expand All @@ -112,10 +105,6 @@ contract EventManager {
eventToUpdate.location = location;
}

if (date != eventToUpdate.date) {
eventToUpdate.date = date;
}

if (startTime != eventToUpdate.startTime) {
eventToUpdate.startTime = startTime;
}
Expand Down Expand Up @@ -144,7 +133,6 @@ contract EventManager {
eventId,
msg.sender,
eventToUpdate.location,
eventToUpdate.date,
eventToUpdate.startTime,
eventToUpdate.endTime,
eventToUpdate.price
Expand Down
57 changes: 41 additions & 16 deletions src/pages/CreateEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import "react-datepicker/dist/react-datepicker.css";
export default function CreateEvent(){
const [name, setName] = useState()
const [location, setLocation] = useState()
const [startDate, setStartDate] = useState(new Date())
const [unixStartDate, setUnixStartDate] = useState()
const [startTime, setStartTime] = useState(new Date())
const [unixStartTime, setUnixStartTime] = useState()
const [endTime, setEndTime] = useState(new Date())
const [unixEndTime, setUnixEndTime] = useState()
const [description, setDescription] = useState()
const [price, setPrice] = useState()
const [totalTickets, setTotalTickets] = useState()

useEffect(() => {
console.log({ name, location, startDate, description, price, totalTickets });
}, [name, location, startDate, description, price, totalTickets]);
console.log({ name, location, startTime, description, price, totalTickets });
}, [name, location, startTime, description, price, totalTickets]);

let signer = null;
let provider;
Expand All @@ -37,10 +39,10 @@ export default function CreateEvent(){

const eventManagerContract = new ethers.Contract(eventManagerAddress, eventManagerAbi, provider);

async function createEvent(name, location, startDate, startTime, endTime, description, eventType, price, totalTickets) {
async function createEvent(name, location, startTime, endTime, description, eventType, price, totalTickets) {
const signer = await provider.getSigner();
const contractWithSigner = eventManagerContract.connect(signer);
const tx = await contractWithSigner.createEvent(name, location, startDate, startTime, endTime, description, eventType, price, totalTickets);
const tx = await contractWithSigner.createEvent(name, location, startTime, endTime, description, eventType, price, totalTickets);
const txResponse = await tx.wait();
console.log('Transaction sent!', txResponse.hash);
}
Expand Down Expand Up @@ -74,9 +76,9 @@ export default function CreateEvent(){
const createEventBtnHandler = async (e) => {
e.preventDefault();

const endTime = unixStartDate + 7200;
const endTime = unixStartTime + 7200;
const eventType = 1;
createEvent(name, location, unixStartDate, unixStartDate, endTime, description, eventType, price, totalTickets);
createEvent(name, location, unixStartTime, endTime, description, eventType, price, totalTickets);

uploadIpfsFile();

Expand All @@ -86,10 +88,21 @@ export default function CreateEvent(){
return Math.floor(date.getTime() / 1000);
}

const startDateHandler = date => {
setStartDate(date);
const startTimeHandler = date => {
setStartTime(date);
let unixDate = dateToUnixTimestamp(date)
setUnixStartTime(unixDate);

if (date > endTime) {
setEndTime(date);
setUnixEndTime(unixDate);
}
}

const endTimeHandler = date => {
setEndTime(date);
let unixDate = dateToUnixTimestamp(date)
setUnixStartDate(unixDate);
setUnixEndTime(unixDate);
}

return (
Expand Down Expand Up @@ -120,13 +133,26 @@ export default function CreateEvent(){
</li>
<br />
<li id="event_start_date">
Event Start Date
Event Start Time
<br />
<DatePicker
// showIcon
selected={startDate}
onChange={(startDate) => startDateHandler(startDate)}
showTimeSelect
selected={startTime}
onChange={(startTime) => startTimeHandler(startTime)}
minDate={new Date()}
dateFormat="MMMM d, yyyy h:mm aa"
/>
</li>
<br />
<li id="event_end_date">
Event End Time
<br />
<DatePicker
// showTimeSelect
selected={endTime}
onChange={(endTime) => endTimeHandler(endTime)}
minDate={startTime}
dateFormat="MMMM d, yyyy h:mm aa"
/>
</li>
<br />
Expand Down Expand Up @@ -165,7 +191,6 @@ export default function CreateEvent(){
<br />
<li>
<p>Event Image</p>
{/* <button class="upload-file"><img src="./bg-image-input.webp"/> */}
<input
id="upload-button-extend"
type="file"
Expand Down
10 changes: 0 additions & 10 deletions test/testEventManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ contract testEventManager is Test {
eventManager.createEvent({
name: "F1",
location: "Japan Suzuka",
date: 100,
startTime: 200,
endTime: 1000,
description: "Max wins the championship",
Expand All @@ -40,7 +39,6 @@ contract testEventManager is Test {
assertEq(currentEvent.creator, address(this));
assertEq(currentEvent.name, "F1");
assertEq(currentEvent.location, "Japan Suzuka");
assertEq(currentEvent.date, 100);
assertEq(currentEvent.startTime, 200);
assertEq(currentEvent.endTime, 1000);
assertEq(currentEvent.description, "Max wins the championship");
Expand Down Expand Up @@ -78,14 +76,6 @@ contract testEventManager is Test {
assertEq(currentEvent.location, "Singapore GP");
}

function testEventDateIsEditedCorrectly() public {
testCreateEvent();
eventManager.editEvent(1, "F1", "Japan Suzuka", 150, 200, 1000, "Max wins the championship", 1, 10**17, 50000);
uint256 currentEventId = eventManager.getCurrentEventId();
EventManager.Event memory currentEvent = eventManager.getEvent(currentEventId);
assertEq(currentEvent.date, 150);
}

function testEventStartTimeIsEditedCorrectly() public {
testCreateEvent();
eventManager.editEvent(1, "F1", "Japan Suzuka", 100, 250, 1000, "Max wins the championship", 1, 10**17, 50000);
Expand Down
1 change: 0 additions & 1 deletion test/testTicketManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ contract testTicketManager is Test {
ticketManager.createEvent({
name: "F1",
location: "Japan Suzuka",
date: 100,
startTime: 200,
endTime: 1000,
description: "Max wins the championship",
Expand Down

0 comments on commit fe917d8

Please sign in to comment.