From: Dessalines Date: Thu, 11 May 2023 18:32:32 +0000 (-0400) Subject: Using auto-generated types from ts-rs. (#1003) X-Git-Url: http://these/git/readmes/%7B%7D/static/%7B%60https:/%24%7Bi%7D%60%7D?a=commitdiff_plain;h=c5fd084577e908f91421f94c1bd744d154deb49f;p=lemmy-ui.git 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. --- diff --git a/lemmy-translations b/lemmy-translations index 007e536..3bb45c2 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 007e53683768aeba63e9e4c179c1d240217bcee2 +Subproject commit 3bb45c26cb54325c3d8d605f4334447b9b78293a diff --git a/package.json b/package.json index 425251a..8777a4b 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "inferno-server": "^8.1.1", "isomorphic-cookie": "^1.2.4", "jwt-decode": "^3.1.2", - "lemmy-js-client": "0.17.2-rc.5", + "lemmy-js-client": "0.17.2-rc.14", "markdown-it": "^13.0.1", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^2.0.2", diff --git a/src/shared/components/app/footer.tsx b/src/shared/components/app/footer.tsx index a62a8ac..bbe4998 100644 --- a/src/shared/components/app/footer.tsx +++ b/src/shared/components/app/footer.tsx @@ -39,7 +39,7 @@ export class Footer extends Component { )} - {this.props.site.federated_instances && ( + {this.props.site.site_view.local_site.federation_enabled && (
  • {i18n.t("instances")} diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 44345cc..448e92c 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -40,9 +40,9 @@ interface NavbarProps { interface NavbarState { expanded: boolean; - unreadInboxCount: number; - unreadReportCount: number; - unreadApplicationCount: number; + unreadInboxCount: bigint; + unreadReportCount: bigint; + unreadApplicationCount: bigint; showDropdown: boolean; onSiteBanner?(url: string): any; } @@ -54,9 +54,9 @@ export class Navbar extends Component { private unreadReportCountSub: Subscription; private unreadApplicationCountSub: Subscription; state: NavbarState = { - unreadInboxCount: 0, - unreadReportCount: 0, - unreadApplicationCount: 0, + unreadInboxCount: 0n, + unreadReportCount: 0n, + unreadApplicationCount: 0n, expanded: false, showDropdown: false, }; @@ -144,7 +144,7 @@ export class Navbar extends Component { className="p-1 navbar-toggler nav-link border-0" onMouseUp={linkEvent(this, this.handleHideExpandNavbar)} title={i18n.t("unread_messages", { - count: this.state.unreadInboxCount, + count: Number(this.state.unreadInboxCount), formattedCount: numToSI(this.state.unreadInboxCount), })} > @@ -165,7 +165,7 @@ export class Navbar extends Component { className="p-1 navbar-toggler nav-link border-0" onMouseUp={linkEvent(this, this.handleHideExpandNavbar)} title={i18n.t("unread_reports", { - count: this.state.unreadReportCount, + count: Number(this.state.unreadReportCount), formattedCount: numToSI(this.state.unreadReportCount), })} > @@ -187,7 +187,7 @@ export class Navbar extends Component { className="p-1 navbar-toggler nav-link border-0" onMouseUp={linkEvent(this, this.handleHideExpandNavbar)} title={i18n.t("unread_registration_applications", { - count: this.state.unreadApplicationCount, + count: Number(this.state.unreadApplicationCount), formattedCount: numToSI( this.state.unreadApplicationCount ), @@ -305,7 +305,7 @@ export class Navbar extends Component { to="/inbox" onMouseUp={linkEvent(this, this.handleHideExpandNavbar)} title={i18n.t("unread_messages", { - count: this.state.unreadInboxCount, + count: Number(this.state.unreadInboxCount), formattedCount: numToSI(this.state.unreadInboxCount), })} > @@ -326,7 +326,7 @@ export class Navbar extends Component { to="/reports" onMouseUp={linkEvent(this, this.handleHideExpandNavbar)} title={i18n.t("unread_reports", { - count: this.state.unreadReportCount, + count: Number(this.state.unreadReportCount), formattedCount: numToSI(this.state.unreadReportCount), })} > @@ -348,7 +348,7 @@ export class Navbar extends Component { className="nav-link" onMouseUp={linkEvent(this, this.handleHideExpandNavbar)} title={i18n.t("unread_registration_applications", { - count: this.state.unreadApplicationCount, + count: Number(this.state.unreadApplicationCount), formattedCount: numToSI( this.state.unreadApplicationCount ), @@ -512,7 +512,7 @@ export class Navbar extends Component { unreadReportCount: data.post_reports + data.comment_reports + - (data.private_message_reports ?? 0), + (data.private_message_reports ?? 0n), }); this.sendReportUnread(); } else if (op == UserOperation.GetUnreadRegistrationApplicationCount) { @@ -528,7 +528,7 @@ export class Navbar extends Component { data.recipient_ids.includes(mui.local_user_view.local_user.id) ) { this.setState({ - unreadInboxCount: this.state.unreadInboxCount + 1, + unreadInboxCount: this.state.unreadInboxCount + 1n, }); this.sendUnreadCount(); notifyComment(data.comment_view, this.context.router); @@ -541,7 +541,7 @@ export class Navbar extends Component { UserService.Instance.myUserInfo?.local_user_view.person.id ) { this.setState({ - unreadInboxCount: this.state.unreadInboxCount + 1, + unreadInboxCount: this.state.unreadInboxCount + 1n, }); this.sendUnreadCount(); notifyPrivateMessage(data.private_message_view, this.context.router); diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 9c29381..c728519 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -2,7 +2,6 @@ import { Component } from "inferno"; import { T } from "inferno-i18next-dess"; import { Link } from "inferno-router"; import { - CommentNode as CommentNodeI, CommentResponse, CreateComment, EditComment, @@ -12,6 +11,7 @@ import { wsUserOp, } from "lemmy-js-client"; import { Subscription } from "rxjs"; +import { CommentNodeI } from "shared/interfaces"; import { i18n } from "../../i18next"; import { UserService, WebSocketService } from "../../services"; import { diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 99db143..2b7ea6e 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -7,21 +7,19 @@ import { BanFromCommunity, BanPerson, BlockPerson, - CommentNode as CommentNodeI, CommentReplyView, CommentView, CommunityModeratorView, CreateCommentLike, CreateCommentReport, DeleteComment, - EditComment, + DistinguishComment, GetComments, Language, - ListingType, MarkCommentReplyAsRead, MarkPersonMentionAsRead, PersonMentionView, - PersonViewSafe, + PersonView, PurgeComment, PurgePerson, RemoveComment, @@ -30,7 +28,12 @@ import { } from "lemmy-js-client"; import moment from "moment"; import { i18n } from "../../i18next"; -import { BanType, CommentViewType, PurgeType } from "../../interfaces"; +import { + BanType, + CommentNodeI, + CommentViewType, + PurgeType, +} from "../../interfaces"; import { UserService, WebSocketService } from "../../services"; import { amCommunityCreator, @@ -81,9 +84,9 @@ interface CommentNodeState { showReportDialog: boolean; reportReason?: string; my_vote?: number; - score: number; - upvotes: number; - downvotes: number; + score: bigint; + upvotes: bigint; + downvotes: bigint; readLoading: boolean; saveLoading: boolean; } @@ -91,7 +94,7 @@ interface CommentNodeState { interface CommentNodeProps { node: CommentNodeI; moderators?: CommunityModeratorView[]; - admins?: PersonViewSafe[]; + admins?: PersonView[]; noBorder?: boolean; noIndent?: boolean; viewOnly?: boolean; @@ -296,8 +299,8 @@ export class CommentNode extends Component { {numToSI(this.state.score)} @@ -835,7 +838,9 @@ export class CommentNode extends Component { > {i18n.t("x_more_replies", { count: node.comment_view.counts.child_count, - formattedCount: numToSI(node.comment_view.counts.child_count), + formattedCount: numToSI( + BigInt(node.comment_view.counts.child_count) + ), })}{" "} ➔ @@ -1152,19 +1157,19 @@ export class CommentNode extends Component { if (myVote == 1) { this.setState({ - score: this.state.score - 1, - upvotes: this.state.upvotes - 1, + score: this.state.score - 1n, + upvotes: this.state.upvotes - 1n, }); } else if (myVote == -1) { this.setState({ - downvotes: this.state.downvotes - 1, - upvotes: this.state.upvotes + 1, - score: this.state.score + 2, + downvotes: this.state.downvotes - 1n, + upvotes: this.state.upvotes + 1n, + score: this.state.score + 2n, }); } else { this.setState({ - score: this.state.score + 1, - upvotes: this.state.upvotes + 1, + score: this.state.score + 1n, + upvotes: this.state.upvotes + 1n, }); } @@ -1189,19 +1194,19 @@ export class CommentNode extends Component { if (myVote == 1) { this.setState({ - downvotes: this.state.downvotes + 1, - upvotes: this.state.upvotes - 1, - score: this.state.score - 2, + downvotes: this.state.downvotes + 1n, + upvotes: this.state.upvotes - 1n, + score: this.state.score - 2n, }); } else if (myVote == -1) { this.setState({ - downvotes: this.state.downvotes - 1, - score: this.state.score + 1, + downvotes: this.state.downvotes - 1n, + score: this.state.score + 1n, }); } else { this.setState({ - downvotes: this.state.downvotes + 1, - score: this.state.score - 1, + downvotes: this.state.downvotes + 1n, + score: this.state.score - 1n, }); } @@ -1278,7 +1283,7 @@ export class CommentNode extends Component { let comment = i.props.node.comment_view.comment; let auth = myAuth(); if (auth) { - let form: EditComment = { + let form: DistinguishComment = { comment_id: comment.id, distinguished: !comment.distinguished, auth, @@ -1542,8 +1547,8 @@ export class CommentNode extends Component { post_id: i.props.node.comment_view.post.id, parent_id: i.props.node.comment_view.comment.id, max_depth: commentTreeMaxDepth, - limit: 999, // TODO - type_: ListingType.All, + limit: 999n, // TODO + type_: "All", saved_only: false, auth: myAuth(false), }; @@ -1563,18 +1568,18 @@ export class CommentNode extends Component { get pointsTippy(): string { let points = i18n.t("number_of_points", { - count: this.state.score, - formattedCount: this.state.score, + count: Number(this.state.score), + formattedCount: numToSI(this.state.score), }); let upvotes = i18n.t("number_of_upvotes", { - count: this.state.upvotes, - formattedCount: this.state.upvotes, + count: Number(this.state.upvotes), + formattedCount: numToSI(this.state.upvotes), }); let downvotes = i18n.t("number_of_downvotes", { - count: this.state.downvotes, - formattedCount: this.state.downvotes, + count: Number(this.state.downvotes), + formattedCount: numToSI(this.state.downvotes), }); return `${points} • ${upvotes} • ${downvotes}`; diff --git a/src/shared/components/comment/comment-nodes.tsx b/src/shared/components/comment/comment-nodes.tsx index c8fd1cf..ba8997a 100644 --- a/src/shared/components/comment/comment-nodes.tsx +++ b/src/shared/components/comment/comment-nodes.tsx @@ -1,17 +1,12 @@ import { Component } from "inferno"; -import { - CommentNode as CommentNodeI, - CommunityModeratorView, - Language, - PersonViewSafe, -} from "lemmy-js-client"; -import { CommentViewType } from "../../interfaces"; +import { CommunityModeratorView, Language, PersonView } from "lemmy-js-client"; +import { CommentNodeI, CommentViewType } from "../../interfaces"; import { CommentNode } from "./comment-node"; interface CommentNodesProps { nodes: CommentNodeI[]; moderators?: CommunityModeratorView[]; - admins?: PersonViewSafe[]; + admins?: PersonView[]; maxCommentsShown?: number; noBorder?: boolean; noIndent?: boolean; diff --git a/src/shared/components/comment/comment-report.tsx b/src/shared/components/comment/comment-report.tsx index 5f7c24c..232fec6 100644 --- a/src/shared/components/comment/comment-report.tsx +++ b/src/shared/components/comment/comment-report.tsx @@ -1,14 +1,12 @@ import { Component, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; import { - CommentNode as CommentNodeI, CommentReportView, CommentView, ResolveCommentReport, - SubscribedType, } from "lemmy-js-client"; import { i18n } from "../../i18next"; -import { CommentViewType } from "../../interfaces"; +import { CommentNodeI, CommentViewType } from "../../interfaces"; import { WebSocketService } from "../../services"; import { myAuth, wsClient } from "../../utils"; import { Icon } from "../common/icon"; @@ -41,7 +39,7 @@ export class CommentReport extends Component { community: r.community, creator_banned_from_community: r.creator_banned_from_community, counts: r.counts, - subscribed: SubscribedType.NotSubscribed, + subscribed: "NotSubscribed", saved: false, creator_blocked: false, my_vote: r.my_vote, diff --git a/src/shared/components/common/comment-sort-select.tsx b/src/shared/components/common/comment-sort-select.tsx index 1874776..486d99f 100644 --- a/src/shared/components/common/comment-sort-select.tsx +++ b/src/shared/components/common/comment-sort-select.tsx @@ -46,10 +46,10 @@ export class CommentSortSelect extends Component< - , - , - - + , + , + + @@ -63,14 +63,14 @@ export class ListingTypeSelect extends Component<
    )} - {cv.subscribed === SubscribedType.NotSubscribed && ( + {cv.subscribed === "NotSubscribed" && ( )} - {cv.subscribed === SubscribedType.Pending && ( + {cv.subscribed === "Pending" && (
    {i18n.t("subscribe_pending")}
    @@ -283,14 +280,14 @@ export class Communities extends Component { refetch(); } - handlePageChange(page: number) { + handlePageChange(page: bigint) { this.updateUrl({ page }); } handleListingTypeChange(val: ListingType) { this.updateUrl({ listingType: val, - page: 1, + page: 1n, }); } @@ -318,7 +315,7 @@ export class Communities extends Component { }: InitialFetchRequest>): Promise[] { const listCommunitiesForm: ListCommunities = { type_: getListingTypeFromQuery(listingType), - sort: SortType.TopMonth, + sort: "TopMonth", limit: communityLimit, page: getPageFromString(page), auth: auth, diff --git a/src/shared/components/community/community-link.tsx b/src/shared/components/community/community-link.tsx index 04e7a51..bf15971 100644 --- a/src/shared/components/community/community-link.tsx +++ b/src/shared/components/community/community-link.tsx @@ -1,11 +1,11 @@ import { Component } from "inferno"; import { Link } from "inferno-router"; -import { CommunitySafe } from "lemmy-js-client"; +import { Community } from "lemmy-js-client"; import { hostname, relTags, showAvatars } from "../../utils"; import { PictrsImage } from "../common/pictrs-image"; interface CommunityLinkProps { - community: CommunitySafe; + community: Community; realLink?: boolean; useApubName?: boolean; muted?: boolean; diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 4776b4c..8a70378 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -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); diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index c7b1046..4316755 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -8,10 +8,9 @@ import { DeleteCommunity, FollowCommunity, Language, - PersonViewSafe, + PersonView, PurgeCommunity, RemoveCommunity, - SubscribedType, } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { UserService, WebSocketService } from "../../services"; @@ -35,7 +34,7 @@ import { PersonListing } from "../person/person-listing"; interface SidebarProps { community_view: CommunityView; moderators: CommunityModeratorView[]; - admins: PersonViewSafe[]; + admins: PersonView[]; allLanguages: Language[]; siteLanguages: number[]; communityLanguages?: number[]; @@ -134,7 +133,7 @@ export class Sidebar extends Component { )} {community.title} - {subscribed === SubscribedType.Subscribed && ( + {subscribed === "Subscribed" && ( )} - {subscribed === SubscribedType.Pending && ( + {subscribed === "Pending" && (
    - {siteView.local_site.registration_mode == - RegistrationMode.RequireApplication && ( + {siteView.local_site.registration_mode == "RequireApplication" && ( <>
    @@ -486,7 +484,7 @@ export class Signup extends Component { handleRegenCaptcha(i: Signup) { i.audio = undefined; i.setState({ captchaPlaying: false }); - WebSocketService.Instance.send(wsClient.getCaptcha()); + WebSocketService.Instance.send(wsClient.getCaptcha({})); } handleCaptchaPlay(i: Signup) { diff --git a/src/shared/components/home/site-form.tsx b/src/shared/components/home/site-form.tsx index 0bd3c62..ec37af6 100644 --- a/src/shared/components/home/site-form.tsx +++ b/src/shared/components/home/site-form.tsx @@ -3,9 +3,9 @@ import { Prompt } from "inferno-router"; import { CreateSite, EditSite, + GetFederatedInstancesResponse, GetSiteResponse, ListingType, - RegistrationMode, } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { WebSocketService } from "../../services"; @@ -23,6 +23,7 @@ import { MarkdownTextArea } from "../common/markdown-textarea"; interface SiteFormProps { siteRes: GetSiteResponse; + instancesRes?: GetFederatedInstancesResponse; showLocal?: boolean; } @@ -104,8 +105,14 @@ export class SiteForm extends Component { federation_worker_count: ls.federation_worker_count, captcha_enabled: ls.captcha_enabled, captcha_difficulty: ls.captcha_difficulty, - allowed_instances: this.props.siteRes.federated_instances?.allowed, - blocked_instances: this.props.siteRes.federated_instances?.blocked, + allowed_instances: + this.props.instancesRes?.federated_instances?.allowed.map( + i => i.domain + ), + blocked_instances: + this.props.instancesRes?.federated_instances?.blocked.map( + i => i.domain + ), auth: "TODO", }, }; @@ -295,20 +302,15 @@ export class SiteForm extends Component { )} className="custom-select w-auto" > - - - + +
    - {this.state.siteForm.registration_mode == - RegistrationMode.RequireApplication && ( + {this.state.siteForm.registration_mode == "RequireApplication" && (