Skip to content

Commit

Permalink
Remove person on display after deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
potaotototo committed Oct 29, 2024
1 parent 61d344a commit 8bb31e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/java/tuteez/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public CommandResult execute(Model model) throws CommandException {
personToDelete = getPersonToDeleteByName(model, targetName);
}

if (model.getLastViewedPerson().get().isPresent()) {
if (personToDelete.equals(model.getLastViewedPerson().get().get())) {
model.removeLastViewedPerson();
String logMessageForPerson =
String.format("Student on display is deleted, Student: %s", personToDelete);
logger.info(logMessageForPerson);
}
}

logger.info("Student deleted - " + personToDelete);
model.deletePerson(personToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)));
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/tuteez/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@ public interface Model {
ObjectProperty<Optional<Person>> getLastViewedPerson();

/**
* Updates the lastViewedPerson after a DisplayCommand is called.
* Updates the lastViewedPerson.
*/
void updateLastViewedPerson(Person personOnDisplay);

/**
* Deletes the lastViewedPerson.
*/
void removeLastViewedPerson();

/**
* Returns the {@code person} in the address book with the given name.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/tuteez/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ public void updateLastViewedPerson(Person personOnDisplay) {
logger.info("Last viewed person updated: " + personOnDisplay.getName().fullName);
}

@Override
public void removeLastViewedPerson() {
lastViewedPerson.set(Optional.empty());
logger.info("Last viewed person removed");
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down

0 comments on commit 8bb31e9

Please sign in to comment.