From 4f2bca73d94321f2ed7fedd3f86f0d17d61edaf5 Mon Sep 17 00:00:00 2001 From: mithandir Date: Sun, 30 Jun 2024 10:30:13 +0200 Subject: [PATCH] Fix homepage indexing --- .../ch/climbd/newsfeed/views/LatestView.java | 2 +- .../ch/climbd/newsfeed/views/MainView.java | 21 ----- .../components/CommonSessionComponents.java | 2 +- .../views/components/NewsItemComponent.java | 76 +++++++++---------- 4 files changed, 40 insertions(+), 61 deletions(-) delete mode 100644 src/main/java/ch/climbd/newsfeed/views/MainView.java diff --git a/src/main/java/ch/climbd/newsfeed/views/LatestView.java b/src/main/java/ch/climbd/newsfeed/views/LatestView.java index 9f05091..9a385d2 100644 --- a/src/main/java/ch/climbd/newsfeed/views/LatestView.java +++ b/src/main/java/ch/climbd/newsfeed/views/LatestView.java @@ -21,7 +21,7 @@ import java.util.LinkedList; -@Route("latest") +@Route("") @PageTitle("Climbd Cycling News - Latest News") public class LatestView extends VerticalLayout { diff --git a/src/main/java/ch/climbd/newsfeed/views/MainView.java b/src/main/java/ch/climbd/newsfeed/views/MainView.java deleted file mode 100644 index 6842749..0000000 --- a/src/main/java/ch/climbd/newsfeed/views/MainView.java +++ /dev/null @@ -1,21 +0,0 @@ -package ch.climbd.newsfeed.views; - -import com.vaadin.flow.component.html.Div; -import com.vaadin.flow.router.BeforeEnterEvent; -import com.vaadin.flow.router.BeforeEnterObserver; -import com.vaadin.flow.router.PageTitle; -import com.vaadin.flow.router.Route; - -@Route -@PageTitle("Climbd Cycling News - Latest News") -public class MainView extends Div implements BeforeEnterObserver { - - public MainView() { - add("Nothing here"); - } - - @Override - public void beforeEnter(BeforeEnterEvent beforeEnterEvent) { - beforeEnterEvent.rerouteTo(LatestView.class); - } -} \ No newline at end of file diff --git a/src/main/java/ch/climbd/newsfeed/views/components/CommonSessionComponents.java b/src/main/java/ch/climbd/newsfeed/views/components/CommonSessionComponents.java index e58fc88..879f665 100644 --- a/src/main/java/ch/climbd/newsfeed/views/components/CommonSessionComponents.java +++ b/src/main/java/ch/climbd/newsfeed/views/components/CommonSessionComponents.java @@ -104,7 +104,7 @@ public void checkIsAdmin(boolean forceReload) { private final ComponentEventListener> listenerViews = e -> e.getSource().getUI().ifPresent(ui -> ui.navigate("views")); private final ComponentEventListener> listenerNewest = e -> e.getSource().getUI().ifPresent(ui -> - ui.navigate("latest")); + ui.navigate("")); private final ComponentEventListener> listenerAddNews = e -> e.getSource().getUI().ifPresent(ui -> ui.navigate("add-news")); diff --git a/src/main/java/ch/climbd/newsfeed/views/components/NewsItemComponent.java b/src/main/java/ch/climbd/newsfeed/views/components/NewsItemComponent.java index 3524b43..a91454d 100644 --- a/src/main/java/ch/climbd/newsfeed/views/components/NewsItemComponent.java +++ b/src/main/java/ch/climbd/newsfeed/views/components/NewsItemComponent.java @@ -79,44 +79,6 @@ public VerticalLayout createNewsItem(List items) { return verticalLayout; } - private void handleKeyEvents(VerticalLayout verticalLayout, boolean goDown) { - commonSessionComponents.setFocusCurrentIndex(0); - - if (!goDown) { - if (commonSessionComponents.getFocusKeyIndex() == 0) { - return; - } - commonSessionComponents.setFocusKeyIndex(commonSessionComponents.getFocusKeyIndex() - 1); - } - - verticalLayout.getChildren().forEach(component -> { - if (component instanceof Details) { - if (!((Details) component).isOpened()) { - ((Details) component).setOpened(true); - } - } - - if (component instanceof HorizontalLayout) { - if (commonSessionComponents.getFocusCurrentIndex() == commonSessionComponents.getFocusKeyIndex()) { - var row = (HorizontalLayout) component; - component.scrollIntoView(); - } - commonSessionComponents.setFocusCurrentIndex(commonSessionComponents.getFocusCurrentIndex() + 1); - } - }); - - if (goDown) { - var sizeHorizontalLayouts = verticalLayout.getChildren() - .filter(component -> component instanceof HorizontalLayout) - .count(); - - if (commonSessionComponents.getFocusKeyIndex() == sizeHorizontalLayouts) { - return; - } - commonSessionComponents.setFocusKeyIndex(commonSessionComponents.getFocusKeyIndex() + 1); - } - } - public HorizontalLayout buildNewsItem(int index, NewsEntry item, VerticalLayout sourceLayout) { if (filter.isSpam(item.getTitle())) { return null; @@ -236,4 +198,42 @@ private Html createHtmlElement(String str) { return html; } + + private void handleKeyEvents(VerticalLayout verticalLayout, boolean goDown) { + commonSessionComponents.setFocusCurrentIndex(0); + + if (!goDown) { + if (commonSessionComponents.getFocusKeyIndex() == 0) { + return; + } + commonSessionComponents.setFocusKeyIndex(commonSessionComponents.getFocusKeyIndex() - 1); + } + + verticalLayout.getChildren().forEach(component -> { + if (component instanceof Details) { + if (!((Details) component).isOpened()) { + ((Details) component).setOpened(true); + } + } + + if (component instanceof HorizontalLayout) { + if (commonSessionComponents.getFocusCurrentIndex() == commonSessionComponents.getFocusKeyIndex()) { + var row = (HorizontalLayout) component; + component.scrollIntoView(); + } + commonSessionComponents.setFocusCurrentIndex(commonSessionComponents.getFocusCurrentIndex() + 1); + } + }); + + if (goDown) { + var sizeHorizontalLayouts = verticalLayout.getChildren() + .filter(component -> component instanceof HorizontalLayout) + .count(); + + if (commonSessionComponents.getFocusKeyIndex() == sizeHorizontalLayouts) { + return; + } + commonSessionComponents.setFocusKeyIndex(commonSessionComponents.getFocusKeyIndex() + 1); + } + } }