Skip to content

Commit

Permalink
✨ dynamically update conference sessions closes #14
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Mar 27, 2024
1 parent d5df1f6 commit 273ab45
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/main/java/swiss/fihlon/apus/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
package swiss.fihlon.apus;

import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.component.page.Push;
import com.vaadin.flow.server.PWA;
import com.vaadin.flow.theme.Theme;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
* The entry point of the Spring Boot application.
Expand All @@ -32,6 +33,8 @@
*
*/
@SpringBootApplication
@EnableScheduling
@Push
@PWA(name = "Apus", shortName = "Apus")
@Theme("apus")
@SuppressWarnings({"FinalClass", "HideUtilityClassConstructor"})
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/swiss/fihlon/apus/ui/view/ConferenceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,40 @@
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H2;
import org.jetbrains.annotations.NotNull;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import swiss.fihlon.apus.conference.Session;
import swiss.fihlon.apus.service.ConferenceService;

import java.util.concurrent.atomic.AtomicInteger;

@Component
@CssImport(value = "./themes/apus/views/conference-view.css")
public final class ConferenceView extends Div {

private static final int MAX_SESSIONS_IN_VIEW = 15;

private final transient ConferenceService conferenceService;
private final Div sessionContainer = new Div();

public ConferenceView(@NotNull final ConferenceService conferenceService) {
this.conferenceService = conferenceService;
setId("conference-view");
final var sessionContainer = new Div();
add(new H2("Agenda"));
add(sessionContainer);
updateConferenceSessions();
}

@Scheduled(fixedRate = 60_000)
private void scheduler() {
getUI().ifPresent(ui -> ui.access(this::updateConferenceSessions));
}

private void updateConferenceSessions() {
sessionContainer.removeAll();
var sessionCounter = new AtomicInteger(0);

final var runningSessions = conferenceService.getRunningSessions();
add(new H2("Agenda"));
for (final Session session : runningSessions) {
final var sessionView = new SessionView(session);
sessionView.addClassName("running-session");
Expand All @@ -60,8 +77,5 @@ public ConferenceView(@NotNull final ConferenceService conferenceService) {
}
}
}

add(sessionContainer);
}

}
5 changes: 2 additions & 3 deletions src/main/java/swiss/fihlon/apus/ui/view/SocialWallView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;
import org.jetbrains.annotations.NotNull;
import swiss.fihlon.apus.service.ConferenceService;
import swiss.fihlon.apus.service.SocialService;

@Route("")
@CssImport(value = "./themes/apus/views/social-wall-view.css")
public final class SocialWallView extends Div {

public SocialWallView(@NotNull final ConferenceService conferenceService,
public SocialWallView(@NotNull final ConferenceView conferenceview,
@NotNull final SocialService socialService) {
setId("social-wall-view");
add(new ConferenceView(conferenceService), new SocialView(socialService));
add(conferenceview, new SocialView(socialService));
}

}

0 comments on commit 273ab45

Please sign in to comment.