Skip to content

Commit

Permalink
♻️ refactor session speaker to be a list of speakers closes #57
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Mar 30, 2024
1 parent e2a786b commit 63c4527
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/main/java/swiss/fihlon/apus/conference/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import org.jetbrains.annotations.NotNull;

import java.time.LocalDateTime;
import java.util.List;

public record Session(String id, LocalDateTime startDate, LocalDateTime endDate, String room, String title, String speaker)
public record Session(@NotNull String id, @NotNull LocalDateTime startDate, @NotNull LocalDateTime endDate,
@NotNull String room, @NotNull String title, @NotNull List<Speaker> speakers)
implements Comparable<Session> {
@Override
public int compareTo(@NotNull final Session other) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/swiss/fihlon/apus/conference/Speaker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Apus - A social wall for conferences with additional features.
* Copyright (C) Marcus Fihlon and the individual contributors to Apus.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package swiss.fihlon.apus.conference;

import org.jetbrains.annotations.NotNull;

public record Speaker(@NotNull String fullName) { }
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.json.JSONObject;
import swiss.fihlon.apus.conference.Session;
import swiss.fihlon.apus.conference.SessionImportException;
import swiss.fihlon.apus.conference.Speaker;
import swiss.fihlon.apus.configuration.Configuration;

import java.io.IOException;
Expand Down Expand Up @@ -68,7 +69,6 @@ public List<Session> getSessions() {
final LocalDate date = LocalDate.parse(day.getString("date")).minus(daysBetween);

final JSONObject rooms = day.getJSONObject("rooms");
@SuppressWarnings("unchecked")
final Iterator<String> roomKeys = rooms.keys();
while (roomKeys.hasNext()) {
final String room = roomKeys.next();
Expand Down Expand Up @@ -100,7 +100,7 @@ public List<Session> getSessions() {
LocalDateTime.of(date, startTime).plus(duration),
room,
title,
String.join(", ", speakers));
speakers.stream().map(Speaker::new).toList());
sessions.add(session);
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/swiss/fihlon/apus/ui/view/SessionView.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,41 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import swiss.fihlon.apus.conference.Session;
import swiss.fihlon.apus.conference.Speaker;

import java.time.Duration;
import java.time.LocalTime;
import java.util.List;
import java.util.stream.Collectors;

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

public SessionView(@NotNull final String room) {
this(room, null, null, null, null);
this(room, null, List.of(), null, null);
}

public SessionView(@NotNull final Session session) {
this(
session.room(),
session.title(),
session.speaker(),
session.speakers(),
session.startDate().toLocalTime(),
session.endDate().toLocalTime()
);
}

public SessionView(@NotNull final String room,
@Nullable final String title,
@Nullable final String speaker,
@NotNull final List<Speaker> speakers,
@Nullable final LocalTime startTime,
@Nullable final LocalTime endTime) {
addClassName("session-view");
add(new H3(new Text(title == null ? "CLOSED" : title)));
add(new Div(speaker == null ? nbsp() : new Text(String.format("\uD83D\uDC64 %s", speaker))));
add(new Div(speakers.isEmpty() ? nbsp() : new Text(String.format("\uD83D\uDC64 %s",
speakers.stream()
.map(Speaker::fullName)
.collect(Collectors.joining(", "))))));
add(new Div(new Text(String.format("\uD83D\uDCCD %s", room))));

final var now = LocalTime.now();
Expand Down

0 comments on commit 63c4527

Please sign in to comment.