Skip to content

Commit

Permalink
Merge branch 'LemmyNet:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Nov 14, 2023
2 parents 402613f + 795dcdb commit 8f46059
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 130 deletions.
13 changes: 0 additions & 13 deletions src/shared/components/common/paginator-cursor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ import { I18NextService } from "../../services";
import { PaginationCursor } from "lemmy-js-client";

interface PaginatorCursorProps {
prevPage?: PaginationCursor;
nextPage?: PaginationCursor;
onNext(val: PaginationCursor): void;
onPrev(): void;
}

function handlePrev(i: PaginatorCursor) {
i.props.onPrev();
}

function handleNext(i: PaginatorCursor) {
Expand All @@ -26,13 +20,6 @@ export class PaginatorCursor extends Component<PaginatorCursorProps, any> {
render() {
return (
<div className="paginator my-2">
<button
className="btn btn-secondary me-2"
disabled={!this.props.prevPage}
onClick={linkEvent(this, handlePrev)}
>
{I18NextService.i18n.t("prev")}
</button>
<button
className="btn btn-secondary"
onClick={linkEvent(this, handleNext)}
Expand Down
30 changes: 16 additions & 14 deletions src/shared/components/common/paginator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ export class Paginator extends Component<PaginatorProps, any> {
render() {
return (
<div className="paginator my-2">
<button
className="btn btn-secondary me-2"
disabled={this.props.page === 1}
onClick={linkEvent(this, this.handlePrev)}
>
{I18NextService.i18n.t("prev")}
</button>
<button
className="btn btn-secondary"
onClick={linkEvent(this, this.handleNext)}
disabled={this.props.nextDisabled || false}
>
{I18NextService.i18n.t("next")}
</button>
{this.props.page !== 1 && (
<button
className="btn btn-secondary me-2"
onClick={linkEvent(this, this.handlePrev)}
>
{I18NextService.i18n.t("prev")}
</button>
)}
{!this.props.nextDisabled && (
<button
className="btn btn-secondary"
onClick={linkEvent(this, this.handleNext)}
>
{I18NextService.i18n.t("next")}
</button>
)}
</div>
);
}
Expand Down
3 changes: 0 additions & 3 deletions src/shared/components/community/community.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ export class Community extends Component<
}

renderCommunity() {
const { pageCursor } = getCommunityQueryParams();
switch (this.state.communityRes.state) {
case "loading":
return (
Expand Down Expand Up @@ -341,10 +340,8 @@ export class Community extends Component<
{this.selects(res)}
{this.listings(res)}
<PaginatorCursor
prevPage={pageCursor}
nextPage={this.getNextPage}
onNext={this.handlePageNext}
onPrev={this.handlePagePrev}
/>
</main>
<aside className="d-none d-md-block col-md-4 col-lg-3">
Expand Down
49 changes: 11 additions & 38 deletions src/shared/components/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ import {
InitialFetchRequest,
} from "../../interfaces";
import { mdToHtml } from "../../markdown";
import {
FirstLoadService,
HomeCacheService,
I18NextService,
UserService,
} from "../../services";
import { FirstLoadService, I18NextService, UserService } from "../../services";
import {
EMPTY_REQUEST,
HttpService,
Expand Down Expand Up @@ -288,18 +283,12 @@ export class Home extends Component<any, HomeState> {
postsRes,
isIsomorphic: true,
};

HomeCacheService.postsRes = postsRes;
}

this.state.tagline = getRandomFromList(this.state?.siteRes?.taglines ?? [])
?.content;
}

componentWillUnmount() {
HomeCacheService.activate();
}

async componentDidMount() {
if (
!this.state.isIsomorphic ||
Expand Down Expand Up @@ -646,18 +635,14 @@ export class Home extends Component<any, HomeState> {
}

get posts() {
const { pageCursor } = getHomeQueryParams();

return (
<div className="main-content-wrapper">
<div>
{this.selects}
{this.listings}
<PaginatorCursor
prevPage={pageCursor}
nextPage={this.getNextPage}
onNext={this.handlePageNext}
onPrev={this.handlePagePrev}
/>
</div>
</div>
Expand Down Expand Up @@ -812,28 +797,16 @@ export class Home extends Component<any, HomeState> {
const { dataType, pageCursor, listingType, sort } = getHomeQueryParams();

if (dataType === DataType.Post) {
if (HomeCacheService.active) {
const { postsRes, scrollY } = HomeCacheService;
HomeCacheService.deactivate();
this.setState({ postsRes });
window.scrollTo({
left: 0,
top: scrollY,
});
} else {
this.setState({ postsRes: LOADING_REQUEST });
this.setState({
postsRes: await HttpService.client.getPosts({
page_cursor: pageCursor,
limit: fetchLimit,
sort,
saved_only: false,
type_: listingType,
}),
});

HomeCacheService.postsRes = this.state.postsRes;
}
this.setState({ postsRes: LOADING_REQUEST });
this.setState({
postsRes: await HttpService.client.getPosts({
page_cursor: pageCursor,
limit: fetchLimit,
sort,
saved_only: false,
type_: listingType,
}),
});
} else {
this.setState({ commentsRes: LOADING_REQUEST });
this.setState({
Expand Down
60 changes: 0 additions & 60 deletions src/shared/services/HomeCacheService.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/shared/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { FirstLoadService } from "./FirstLoadService";
export { HomeCacheService } from "./HomeCacheService";
export { HttpService } from "./HttpService";
export { I18NextService } from "./I18NextService";
export { UserService } from "./UserService";
Expand Down

0 comments on commit 8f46059

Please sign in to comment.