Using auto-generated types from ts-rs. (#1003)

* Using auto-generated types from ts-rs.

- Fixes #998
- Added support for new `GetFederatedInstances`
- Fixed a few bugs in the process.

* Update imports to use SleeplessOne1917's fix.
This commit is contained in:
Dessalines 2023-05-11 14:32:32 -04:00 committed by GitHub
parent 06bfb7eadf
commit c5fd084577
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 753 additions and 750 deletions

View file

@ -14,7 +14,6 @@ import {
GetCommunityResponse,
GetPosts,
GetPostsResponse,
ListingType,
PostReportResponse,
PostResponse,
PostView,
@ -54,8 +53,6 @@ import {
postToCommentSortType,
relTags,
restoreScrollPosition,
routeDataTypeToEnum,
routeSortTypeToEnum,
saveCommentRes,
saveScrollPosition,
setIsoData,
@ -91,7 +88,7 @@ interface State {
interface CommunityProps {
dataType: DataType;
sort: SortType;
page: number;
page: bigint;
}
function getCommunityQueryParams() {
@ -102,18 +99,16 @@ function getCommunityQueryParams() {
});
}
const getDataTypeFromQuery = (type?: string): DataType =>
routeDataTypeToEnum(type ?? "", DataType.Post);
function getDataTypeFromQuery(type?: string): DataType {
return type ? DataType[type] : DataType.Post;
}
function getSortTypeFromQuery(type?: string): SortType {
const mySortType =
UserService.Instance.myUserInfo?.local_user_view.local_user
.default_sort_type;
return routeSortTypeToEnum(
type ?? "",
mySortType ? Object.values(SortType)[mySortType] : SortType.Active
);
return type ? (type as SortType) : mySortType ?? "Active";
}
export class Community extends Component<
@ -217,7 +212,7 @@ export class Community extends Component<
page,
limit: fetchLimit,
sort,
type_: ListingType.All,
type_: "All",
saved_only: false,
auth,
};
@ -229,7 +224,7 @@ export class Community extends Component<
page,
limit: fetchLimit,
sort: postToCommentSortType(sort),
type_: ListingType.All,
type_: "All",
saved_only: false,
auth,
};
@ -432,18 +427,18 @@ export class Community extends Component<
);
}
handlePageChange(page: number) {
handlePageChange(page: bigint) {
this.updateUrl({ page });
window.scrollTo(0, 0);
}
handleSortChange(sort: SortType) {
this.updateUrl({ sort, page: 1 });
this.updateUrl({ sort, page: 1n });
window.scrollTo(0, 0);
}
handleDataTypeChange(dataType: DataType) {
this.updateUrl({ dataType, page: 1 });
this.updateUrl({ dataType, page: 1n });
window.scrollTo(0, 0);
}
@ -489,7 +484,7 @@ export class Community extends Component<
page,
limit: fetchLimit,
sort,
type_: ListingType.All,
type_: "All",
community_name: name,
saved_only: false,
auth: myAuth(false),
@ -500,7 +495,7 @@ export class Community extends Component<
page,
limit: fetchLimit,
sort: postToCommentSortType(sort),
type_: ListingType.All,
type_: "All",
community_name: name,
saved_only: false,
auth: myAuth(false),
@ -611,7 +606,11 @@ export class Community extends Component<
.show_new_post_notifs;
// Only push these if you're on the first page, you pass the nsfw check, and it isn't blocked
if (page === 1 && nsfwCheck(post_view) && !isPostBlocked(post_view)) {
if (
page === 1n &&
nsfwCheck(post_view) &&
!isPostBlocked(post_view)
) {
this.state.posts.unshift(post_view);
if (showPostNotifs) {
notifyPost(post_view, this.context.router);