From: abias Date: Fri, 16 Jun 2023 22:12:14 +0000 (-0400) Subject: Fix first loads not working X-Git-Url: http://these/git/%22https:/lemmy.ml/u/Liwott/%7BpictshareAvatarThumbnail%28?a=commitdiff_plain;h=71336002e7276698088d3fa1c6b3e9808983cbc8;p=lemmy-ui.git Fix first loads not working --- diff --git a/package.json b/package.json index 2298d9e..df264eb 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,16 @@ "start": "yarn build:dev --watch" }, "lint-staged": { - "*.{ts,tsx,js}": ["prettier --write", "eslint --fix"], - "*.{css, scss}": ["prettier --write"], - "package.json": ["sortpack"] + "*.{ts,tsx,js}": [ + "prettier --write", + "eslint --fix" + ], + "*.{css, scss}": [ + "prettier --write" + ], + "package.json": [ + "sortpack" + ] }, "dependencies": { "@babel/plugin-proposal-decorators": "^7.21.0", diff --git a/src/server/index.tsx b/src/server/index.tsx index 783845f..4cff98b 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -17,13 +17,10 @@ import { ILemmyConfig, InitialFetchRequest, IsoDataOptionalSite, + RouteData, } from "../shared/interfaces"; import { routes } from "../shared/routes"; -import { - FailedRequestState, - RequestState, - wrapClient, -} from "../shared/services/HttpService"; +import { FailedRequestState, wrapClient } from "../shared/services/HttpService"; import { ErrorPageData, favIconPngUrl, @@ -140,7 +137,7 @@ server.get("/*", async (req, res) => { // This bypasses errors, so that the client can hit the error on its own, // in order to remove the jwt on the browser. Necessary for wrong jwts let site: GetSiteResponse | undefined = undefined; - let routeData: Record> = {}; + let routeData: RouteData = {}; let errorPageData: ErrorPageData | undefined = undefined; let try_site = await client.getSite(getSiteForm); if (try_site.state === "failed" && try_site.msg == "not_logged_in") { @@ -164,7 +161,7 @@ server.get("/*", async (req, res) => { return res.redirect("/setup"); } - if (site) { + if (site && activeRoute?.fetchInitialData) { const initialFetchReq: InitialFetchRequest = { client, auth, @@ -173,19 +170,7 @@ server.get("/*", async (req, res) => { site, }; - if (activeRoute?.fetchInitialData) { - const routeDataKeysAndVals = await Promise.all( - Object.entries(activeRoute.fetchInitialData(initialFetchReq)).map( - async ([key, val]) => [key, await val] - ) - ); - - routeData = routeDataKeysAndVals.reduce((acc, [key, val]) => { - acc[key] = val; - - return acc; - }, {}); - } + routeData = await activeRoute.fetchInitialData(initialFetchReq); } } else if (try_site.state === "failed") { errorPageData = getErrorPageData(new Error(try_site.msg), site); diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 4dc797c..ed379b8 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -124,6 +124,39 @@ type HomeData = RouteDataResponse<{ trendingCommunitiesRes: ListCommunitiesResponse; }>; +function getRss(listingType: ListingType) { + const { sort } = getHomeQueryParams(); + const auth = myAuth(); + + let rss: string | undefined = undefined; + + switch (listingType) { + case "All": { + rss = `/feeds/all.xml?sort=${sort}`; + break; + } + case "Local": { + rss = `/feeds/local.xml?sort=${sort}`; + break; + } + case "Subscribed": { + rss = auth ? `/feeds/front/${auth}.xml?sort=${sort}` : undefined; + break; + } + } + + return ( + rss && ( + <> + + + + + + ) + ); +} + function getDataTypeFromQuery(type?: string): DataType { return type ? DataType[type] : DataType.Post; } @@ -235,11 +268,8 @@ export class Home extends Component { // Only fetch the data if coming from another route if (FirstLoadService.isFirstLoad) { - const { - trendingCommunitiesRes: trendingCommunitiesRes, - commentsRes: commentsRes, - postsRes: postsRes, - } = this.isoData.routeData; + const { trendingCommunitiesRes, commentsRes, postsRes } = + this.isoData.routeData; this.state = { ...this.state, @@ -360,7 +390,7 @@ export class Home extends Component { > )}
{this.mobileView}
- {this.posts()} + {this.posts}