From 3ca24607fbf5c08f83243fc259dcd159bb0a24f2 Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Sat, 17 Jun 2023 09:37:03 +0100 Subject: [PATCH 01/10] add hours as sorting options --- src/shared/components/common/sort-select.tsx | 3 +++ src/shared/utils.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/shared/components/common/sort-select.tsx b/src/shared/components/common/sort-select.tsx index dac6e20d..1fd32076 100644 --- a/src/shared/components/common/sort-select.tsx +++ b/src/shared/components/common/sort-select.tsx @@ -66,6 +66,9 @@ export class SortSelect extends Component { + + + diff --git a/src/shared/utils.ts b/src/shared/utils.ts index c7fbca6b..abb30629 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -986,6 +986,9 @@ export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] { export function convertCommentSortType(sort: SortType): CommentSortType { if ( sort == "TopAll" || + sort == "TopHour" || + sort == "TopSixHour" || + sort == "TopTwelveHour" || sort == "TopDay" || sort == "TopWeek" || sort == "TopMonth" || From 5e9a414dfcbde436d803953871bbe3ada464d90a Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Sun, 18 Jun 2023 00:51:32 +0100 Subject: [PATCH 02/10] clean code --- src/shared/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/utils.ts b/src/shared/utils.ts index abb30629..86a32d16 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -986,9 +986,9 @@ export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] { export function convertCommentSortType(sort: SortType): CommentSortType { if ( sort == "TopAll" || - sort == "TopHour" || - sort == "TopSixHour" || - sort == "TopTwelveHour" || + sort == "TopHour" || + sort == "TopSixHour" || + sort == "TopTwelveHour" || sort == "TopDay" || sort == "TopWeek" || sort == "TopMonth" || From 747bc943a966d45bb2547287a630f1714991e860 Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Wed, 21 Jun 2023 01:21:14 +0100 Subject: [PATCH 03/10] refactor if into switch case --- src/shared/utils.ts | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/shared/utils.ts b/src/shared/utils.ts index be7b11b0..d6946cce 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -853,24 +853,28 @@ export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] { } export function convertCommentSortType(sort: SortType): CommentSortType { - if ( - sort == "TopAll" || - sort == "TopHour" || - sort == "TopSixHour" || - sort == "TopTwelveHour" || - sort == "TopDay" || - sort == "TopWeek" || - sort == "TopMonth" || - sort == "TopYear" - ) { - return "Top"; - } else if (sort == "New") { - return "New"; - } else if (sort == "Hot" || sort == "Active") { - return "Hot"; - } else { - return "Hot"; - } + switch(sort) { + case "TopAll": + case "TopHour": + case "TopSixHour": + case "TopTwelveHour": + case "TopDay": + case "TopWeek": + case "TopMonth": + case "TopYear": { + return "Top"; + } + case "New": { + return "New"; + } + case "Hot": + case "Active": { + return "Hot"; + } + default: { + return "Hot"; + } + } } export function buildCommentsTree( From ad54a2f0f55bdf5d6ad583d4cad2c317efa284b6 Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Thu, 22 Jun 2023 02:53:44 +0100 Subject: [PATCH 04/10] woodpecker trigger From 52bbfb6ba8da429ee2c0557a4a0873cf95b2c296 Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Thu, 22 Jun 2023 04:27:35 +0100 Subject: [PATCH 05/10] woodpecker trigger From 7b81c3c65c2b78ba8bbccd81a15b241a1058485d Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Thu, 22 Jun 2023 04:34:23 +0100 Subject: [PATCH 06/10] woodpecker trigger From c06d38633766f466d8b744aa44c7418765ad57de Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Thu, 22 Jun 2023 04:52:04 +0100 Subject: [PATCH 07/10] prettier --- src/shared/components/common/sort-select.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/shared/components/common/sort-select.tsx b/src/shared/components/common/sort-select.tsx index 33c5c85f..4d03ab5d 100644 --- a/src/shared/components/common/sort-select.tsx +++ b/src/shared/components/common/sort-select.tsx @@ -68,11 +68,17 @@ export class SortSelect extends Component { ───── - - + + - + From 5512ee205ad1b6ee40b99c66af3472db5acc019e Mon Sep 17 00:00:00 2001 From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Thu, 22 Jun 2023 10:32:39 -0400 Subject: [PATCH 08/10] add fallback style tag --- src/server/utils/create-ssr-html.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/server/utils/create-ssr-html.tsx b/src/server/utils/create-ssr-html.tsx index ae766b3a..a7a87ac9 100644 --- a/src/server/utils/create-ssr-html.tsx +++ b/src/server/utils/create-ssr-html.tsx @@ -8,6 +8,8 @@ import { fetchIconPng } from "./fetch-icon-png"; const customHtmlHeader = process.env["LEMMY_UI_CUSTOM_HTML_HEADER"] || ""; +const fallbackStyleTag = ``; + let appleTouchIcon: string | undefined = undefined; export async function createSsrHtml( @@ -85,7 +87,7 @@ export async function createSsrHtml( - ${helmet.link.toString()} + ${helmet.link.toString() || fallbackStyleTag} From a1d935991b04e491eab392e2115bda3c3442e830 Mon Sep 17 00:00:00 2001 From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Thu, 22 Jun 2023 10:43:03 -0400 Subject: [PATCH 09/10] rethink it a bit --- src/server/utils/create-ssr-html.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/server/utils/create-ssr-html.tsx b/src/server/utils/create-ssr-html.tsx index a7a87ac9..39725fa5 100644 --- a/src/server/utils/create-ssr-html.tsx +++ b/src/server/utils/create-ssr-html.tsx @@ -4,12 +4,11 @@ import serialize from "serialize-javascript"; import sharp from "sharp"; import { favIconPngUrl, favIconUrl } from "../../shared/config"; import { ILemmyConfig, IsoDataOptionalSite } from "../../shared/interfaces"; +import { buildThemeList } from "./build-themes-list"; import { fetchIconPng } from "./fetch-icon-png"; const customHtmlHeader = process.env["LEMMY_UI_CUSTOM_HTML_HEADER"] || ""; -const fallbackStyleTag = ``; - let appleTouchIcon: string | undefined = undefined; export async function createSsrHtml( @@ -18,6 +17,10 @@ export async function createSsrHtml( ) { const site = isoData.site_res; + const fallbackTheme = ``; + if (!appleTouchIcon) { appleTouchIcon = site?.site_view.site.icon ? `data:image/png;base64,${sharp( @@ -87,7 +90,7 @@ export async function createSsrHtml( - ${helmet.link.toString() || fallbackStyleTag} + ${helmet.link.toString() || fallbackTheme} From 63b14accec80de9e440266f3e7d92235a85f24dd Mon Sep 17 00:00:00 2001 From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:22:36 -0400 Subject: [PATCH 10/10] rethink it a bit --- src/shared/components/community/community.tsx | 6 ------ src/shared/components/home/home.tsx | 6 ------ src/shared/utils/browser/restore-scroll-position.ts | 1 + src/shared/utils/browser/save-scroll-position.ts | 1 + 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 7eefe0eb..111b47cd 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -15,7 +15,6 @@ import { updateCommunityBlock, updatePersonBlock, } from "@utils/app"; -import { restoreScrollPosition, saveScrollPosition } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -229,10 +228,6 @@ export class Community extends Component< setupTippy(); } - componentWillUnmount() { - saveScrollPosition(this.context); - } - static async fetchInitialData({ client, path, @@ -609,7 +604,6 @@ export class Community extends Component< }); } - restoreScrollPosition(this.context); setupTippy(); } diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 0d91bdbc..4a84664b 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -13,7 +13,6 @@ import { showLocal, updatePersonBlock, } from "@utils/app"; -import { restoreScrollPosition, saveScrollPosition } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -293,10 +292,6 @@ export class Home extends Component { setupTippy(); } - componentWillUnmount() { - saveScrollPosition(this.context); - } - static async fetchInitialData({ client, auth, @@ -800,7 +795,6 @@ export class Home extends Component { }); } - restoreScrollPosition(this.context); setupTippy(); } diff --git a/src/shared/utils/browser/restore-scroll-position.ts b/src/shared/utils/browser/restore-scroll-position.ts index f1534644..6986ae59 100644 --- a/src/shared/utils/browser/restore-scroll-position.ts +++ b/src/shared/utils/browser/restore-scroll-position.ts @@ -1,5 +1,6 @@ export default function restoreScrollPosition(context: any) { const path: string = context.router.route.location.pathname; const y = Number(sessionStorage.getItem(`scrollPosition_${path}`)); + window.scrollTo(0, y); } diff --git a/src/shared/utils/browser/save-scroll-position.ts b/src/shared/utils/browser/save-scroll-position.ts index 48353287..596d5d9f 100644 --- a/src/shared/utils/browser/save-scroll-position.ts +++ b/src/shared/utils/browser/save-scroll-position.ts @@ -1,5 +1,6 @@ export default function saveScrollPosition(context: any) { const path: string = context.router.route.location.pathname; const y = window.scrollY; + sessionStorage.setItem(`scrollPosition_${path}`, y.toString()); }