Skip to content

Commit

Permalink
Fix homepage indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
mithandir committed Jun 30, 2024
1 parent 40edcb0 commit 4f2bca7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ch/climbd/newsfeed/views/LatestView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.util.LinkedList;

@Route("latest")
@Route("")
@PageTitle("Climbd Cycling News - Latest News")
public class LatestView extends VerticalLayout {

Expand Down
21 changes: 0 additions & 21 deletions src/main/java/ch/climbd/newsfeed/views/MainView.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void checkIsAdmin(boolean forceReload) {
private final ComponentEventListener<ClickEvent<MenuItem>> listenerViews = e -> e.getSource().getUI().ifPresent(ui ->
ui.navigate("views"));
private final ComponentEventListener<ClickEvent<MenuItem>> listenerNewest = e -> e.getSource().getUI().ifPresent(ui ->
ui.navigate("latest"));
ui.navigate(""));
private final ComponentEventListener<ClickEvent<MenuItem>> listenerAddNews = e -> e.getSource().getUI().ifPresent(ui ->
ui.navigate("add-news"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,44 +79,6 @@ public VerticalLayout createNewsItem(List<NewsEntry> 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;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 4f2bca7

Please sign in to comment.