From: James Whitmarsh Date: Mon, 5 Jun 2023 21:31:12 +0000 (+0100) Subject: Refactor lets to consts X-Git-Url: http://these/git/%7B%60%24%7BarchiveTodayUrl%7D/%7B%60/feeds/inbox/%24%7BUserService.Instance.auth%7D.xml%60%7D?a=commitdiff_plain;h=0754b9ba193d916651655782f44c051b0cb10268;p=lemmy-ui.git Refactor lets to consts --- diff --git a/.eslintrc.json b/.eslintrc.json index cc1bff1..44dab42 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -37,7 +37,7 @@ "no-useless-constructor": 0, "no-useless-escape": 0, "no-var": 0, - "prefer-const": 0, + "prefer-const": 1, "prefer-rest-params": 0, "quote-props": 0, "unicorn/filename-case": 0 diff --git a/src/server/index.tsx b/src/server/index.tsx index a93595e..94c8e40 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -213,15 +213,15 @@ server.listen(Number(port), hostname, () => { function setForwardedHeaders(headers: IncomingHttpHeaders): { [key: string]: string; } { - let out: { [key: string]: string } = {}; + const out: { [key: string]: string } = {}; if (headers.host) { out.host = headers.host; } - let realIp = headers["x-real-ip"]; + const realIp = headers["x-real-ip"]; if (realIp) { out["x-real-ip"] = realIp as string; } - let forwardedFor = headers["x-forwarded-for"]; + const forwardedFor = headers["x-forwarded-for"]; if (forwardedFor) { out["x-forwarded-for"] = forwardedFor as string; } diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 25c3a30..28fca15 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -80,7 +80,7 @@ export class Navbar extends Component { // Subscribe to jwt changes if (isBrowser()) { // On the first load, check the unreads - let auth = myAuth(false); + const auth = myAuth(false); if (auth && UserService.Instance.myUserInfo) { this.requestNotificationPermission(); WebSocketService.Instance.send( @@ -438,13 +438,13 @@ export class Navbar extends Component { } get moderatesSomething(): boolean { - let mods = UserService.Instance.myUserInfo?.moderates; - let moderatesS = (mods && mods.length > 0) || false; + const mods = UserService.Instance.myUserInfo?.moderates; + const moderatesS = (mods && mods.length > 0) || false; return amAdmin() || moderatesS; } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { if (msg.error == "not_logged_in") { @@ -453,7 +453,7 @@ export class Navbar extends Component { return; } else if (msg.reconnect) { console.log(i18n.t("websocket_reconnected")); - let auth = myAuth(false); + const auth = myAuth(false); if (UserService.Instance.myUserInfo && auth) { WebSocketService.Instance.send( wsClient.userJoin({ @@ -463,13 +463,13 @@ export class Navbar extends Component { this.fetchUnreads(); } } else if (op == UserOperation.GetUnreadCount) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ unreadInboxCount: data.replies + data.mentions + data.private_messages, }); this.sendUnreadCount(); } else if (op == UserOperation.GetReportCount) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ unreadReportCount: data.post_reports + @@ -478,13 +478,13 @@ export class Navbar extends Component { }); this.sendReportUnread(); } else if (op == UserOperation.GetUnreadRegistrationApplicationCount) { - let data = + const data = wsJsonToRes(msg); this.setState({ unreadApplicationCount: data.registration_applications }); this.sendApplicationUnread(); } else if (op == UserOperation.CreateComment) { - let data = wsJsonToRes(msg); - let mui = UserService.Instance.myUserInfo; + const data = wsJsonToRes(msg); + const mui = UserService.Instance.myUserInfo; if ( mui && data.recipient_ids.includes(mui.local_user_view.local_user.id) @@ -496,7 +496,7 @@ export class Navbar extends Component { notifyComment(data.comment_view, this.context.router); } } else if (op == UserOperation.CreatePrivateMessage) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if ( data.private_message_view.recipient.id == @@ -514,16 +514,16 @@ export class Navbar extends Component { fetchUnreads() { console.log("Fetching inbox unreads..."); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let unreadForm: GetUnreadCount = { + const unreadForm: GetUnreadCount = { auth, }; WebSocketService.Instance.send(wsClient.getUnreadCount(unreadForm)); console.log("Fetching reports..."); - let reportCountForm: GetReportCount = { + const reportCountForm: GetReportCount = { auth, }; WebSocketService.Instance.send(wsClient.getReportCount(reportCountForm)); @@ -531,7 +531,7 @@ export class Navbar extends Component { if (amAdmin()) { console.log("Fetching applications..."); - let applicationCountForm: GetUnreadRegistrationApplicationCount = { + const applicationCountForm: GetUnreadRegistrationApplicationCount = { auth, }; WebSocketService.Instance.send( diff --git a/src/shared/components/app/theme.tsx b/src/shared/components/app/theme.tsx index 4510fe2..941eea2 100644 --- a/src/shared/components/app/theme.tsx +++ b/src/shared/components/app/theme.tsx @@ -8,8 +8,8 @@ interface Props { export class Theme extends Component { render() { - let user = UserService.Instance.myUserInfo; - let hasTheme = user?.local_user_view.local_user.theme !== "browser"; + const user = UserService.Instance.myUserInfo; + const hasTheme = user?.local_user_view.local_user.theme !== "browser"; if (user && hasTheme) { return ( diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 74d17bf..4100397 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -69,7 +69,7 @@ export class CommentForm extends Component { } render() { - let initialContent = + const initialContent = typeof this.props.node !== "number" ? this.props.edit ? this.props.node.comment_view.comment.content @@ -113,17 +113,17 @@ export class CommentForm extends Component { formId: string; languageId?: number; }) { - let content = msg.val; - let language_id = msg.languageId; - let node = this.props.node; + const content = msg.val; + const language_id = msg.languageId; + const node = this.props.node; this.setState({ formId: msg.formId }); - let auth = myAuth(); + const auth = myAuth(); if (auth) { if (typeof node === "number") { - let postId = node; - let form: CreateComment = { + const postId = node; + const form: CreateComment = { content, form_id: this.state.formId, post_id: postId, @@ -133,7 +133,7 @@ export class CommentForm extends Component { WebSocketService.Instance.send(wsClient.createComment(form)); } else { if (this.props.edit) { - let form: EditComment = { + const form: EditComment = { content, form_id: this.state.formId, comment_id: node.comment_view.comment.id, @@ -142,7 +142,7 @@ export class CommentForm extends Component { }; WebSocketService.Instance.send(wsClient.editComment(form)); } else { - let form: CreateComment = { + const form: CreateComment = { content, form_id: this.state.formId, post_id: node.comment_view.post.id, @@ -161,7 +161,7 @@ export class CommentForm extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); // Only do the showing and hiding if logged in @@ -170,7 +170,7 @@ export class CommentForm extends Component { op == UserOperation.CreateComment || op == UserOperation.EditComment ) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); // This only finishes this form, if the randomly generated form_id matches the one received if (this.state.formId && this.state.formId == data.form_id) { diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 95fb7d6..f1cd7ff 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -147,7 +147,7 @@ export class CommentNode extends Component { // TODO see if there's a better way to do this, and all willReceiveProps componentWillReceiveProps(nextProps: CommentNodeProps) { - let cv = nextProps.node.comment_view; + const cv = nextProps.node.comment_view; this.setState({ my_vote: cv.my_vote, upvotes: cv.counts.upvotes, @@ -159,18 +159,18 @@ export class CommentNode extends Component { } render() { - let node = this.props.node; - let cv = this.props.node.comment_view; + const node = this.props.node; + const cv = this.props.node.comment_view; - let purgeTypeText = + const purgeTypeText = this.state.purgeType == PurgeType.Comment ? i18n.t("purge_comment") : `${i18n.t("purge")} ${cv.creator.name}`; - let canMod_ = + const canMod_ = canMod(cv.creator.id, this.props.moderators, this.props.admins) && cv.community.local; - let canModOnSelf = + const canModOnSelf = canMod( cv.creator.id, this.props.moderators, @@ -178,31 +178,31 @@ export class CommentNode extends Component { UserService.Instance.myUserInfo, true ) && cv.community.local; - let canAdmin_ = + const canAdmin_ = canAdmin(cv.creator.id, this.props.admins) && cv.community.local; - let canAdminOnSelf = + const canAdminOnSelf = canAdmin( cv.creator.id, this.props.admins, UserService.Instance.myUserInfo, true ) && cv.community.local; - let isMod_ = isMod(cv.creator.id, this.props.moderators); - let isAdmin_ = + const isMod_ = isMod(cv.creator.id, this.props.moderators); + const isAdmin_ = isAdmin(cv.creator.id, this.props.admins) && cv.community.local; - let amCommunityCreator_ = amCommunityCreator( + const amCommunityCreator_ = amCommunityCreator( cv.creator.id, this.props.moderators ); - let borderColor = this.props.node.depth + const borderColor = this.props.node.depth ? colorList[(this.props.node.depth - 1) % colorList.length] : colorList[0]; - let moreRepliesBorderColor = this.props.node.depth + const moreRepliesBorderColor = this.props.node.depth ? colorList[this.props.node.depth % colorList.length] : colorList[0]; - let showMoreChildren = + const showMoreChildren = this.props.viewType == CommentViewType.Tree && !this.state.collapsed && node.children.length == 0 && @@ -1035,7 +1035,7 @@ export class CommentNode extends Component { } get commentReplyOrMentionRead(): boolean { - let cv = this.props.node.comment_view; + const cv = this.props.node.comment_view; if (this.isPersonMentionType(cv)) { return cv.person_mention.read; @@ -1047,12 +1047,12 @@ export class CommentNode extends Component { } linkBtn(small = false) { - let cv = this.props.node.comment_view; - let classnames = classNames("btn btn-link btn-animate text-muted", { + const cv = this.props.node.comment_view; + const classnames = classNames("btn btn-link btn-animate text-muted", { "btn-sm": small, }); - let title = this.props.showContext + const title = this.props.showContext ? i18n.t("show_context") : i18n.t("link"); @@ -1096,7 +1096,7 @@ export class CommentNode extends Component { } get commentUnlessRemoved(): string { - let comment = this.props.node.comment_view.comment; + const comment = this.props.node.comment_view.comment; return comment.removed ? `*${i18n.t("removed")}*` : comment.deleted @@ -1113,9 +1113,9 @@ export class CommentNode extends Component { } handleBlockUserClick(i: CommentNode) { - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let blockUserForm: BlockPerson = { + const blockUserForm: BlockPerson = { person_id: i.props.node.comment_view.creator.id, block: true, auth, @@ -1125,10 +1125,10 @@ export class CommentNode extends Component { } handleDeleteClick(i: CommentNode) { - let comment = i.props.node.comment_view.comment; - let auth = myAuth(); + const comment = i.props.node.comment_view.comment; + const auth = myAuth(); if (auth) { - let deleteForm: DeleteComment = { + const deleteForm: DeleteComment = { comment_id: comment.id, deleted: !comment.deleted, auth, @@ -1138,11 +1138,11 @@ export class CommentNode extends Component { } handleSaveCommentClick(i: CommentNode) { - let cv = i.props.node.comment_view; - let save = cv.saved == undefined ? true : !cv.saved; - let auth = myAuth(); + const cv = i.props.node.comment_view; + const save = cv.saved == undefined ? true : !cv.saved; + const auth = myAuth(); if (auth) { - let form: SaveComment = { + const form: SaveComment = { comment_id: cv.comment.id, save, auth, @@ -1160,8 +1160,8 @@ export class CommentNode extends Component { handleCommentUpvote(event: any) { event.preventDefault(); - let myVote = this.state.my_vote; - let newVote = myVote == 1 ? 0 : 1; + const myVote = this.state.my_vote; + const newVote = myVote == 1 ? 0 : 1; if (myVote == 1) { this.setState({ @@ -1183,9 +1183,9 @@ export class CommentNode extends Component { this.setState({ my_vote: newVote }); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let form: CreateCommentLike = { + const form: CreateCommentLike = { comment_id: this.props.node.comment_view.comment.id, score: newVote, auth, @@ -1197,8 +1197,8 @@ export class CommentNode extends Component { handleCommentDownvote(event: any) { event.preventDefault(); - let myVote = this.state.my_vote; - let newVote = myVote == -1 ? 0 : -1; + const myVote = this.state.my_vote; + const newVote = myVote == -1 ? 0 : -1; if (myVote == 1) { this.setState({ @@ -1220,9 +1220,9 @@ export class CommentNode extends Component { this.setState({ my_vote: newVote }); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let form: CreateCommentLike = { + const form: CreateCommentLike = { comment_id: this.props.node.comment_view.comment.id, score: newVote, auth, @@ -1242,11 +1242,11 @@ export class CommentNode extends Component { } handleReportSubmit(i: CommentNode) { - let comment = i.props.node.comment_view.comment; - let reason = i.state.reportReason; - let auth = myAuth(); + const comment = i.props.node.comment_view.comment; + const reason = i.state.reportReason; + const auth = myAuth(); if (reason && auth) { - let form: CreateCommentReport = { + const form: CreateCommentReport = { comment_id: comment.id, reason, auth, @@ -1272,10 +1272,10 @@ export class CommentNode extends Component { } handleModRemoveSubmit(i: CommentNode) { - let comment = i.props.node.comment_view.comment; - let auth = myAuth(); + const comment = i.props.node.comment_view.comment; + const auth = myAuth(); if (auth) { - let form: RemoveComment = { + const form: RemoveComment = { comment_id: comment.id, removed: !comment.removed, reason: i.state.removeReason, @@ -1288,10 +1288,10 @@ export class CommentNode extends Component { } handleDistinguishClick(i: CommentNode) { - let comment = i.props.node.comment_view.comment; - let auth = myAuth(); + const comment = i.props.node.comment_view.comment; + const auth = myAuth(); if (auth) { - let form: DistinguishComment = { + const form: DistinguishComment = { comment_id: comment.id, distinguished: !comment.distinguished, auth, @@ -1314,17 +1314,17 @@ export class CommentNode extends Component { } handleMarkRead(i: CommentNode) { - let auth = myAuth(); + const auth = myAuth(); if (auth) { if (i.isPersonMentionType(i.props.node.comment_view)) { - let form: MarkPersonMentionAsRead = { + const form: MarkPersonMentionAsRead = { person_mention_id: i.props.node.comment_view.person_mention.id, read: !i.props.node.comment_view.person_mention.read, auth, }; WebSocketService.Instance.send(wsClient.markPersonMentionAsRead(form)); } else if (i.isCommentReplyType(i.props.node.comment_view)) { - let form: MarkCommentReplyAsRead = { + const form: MarkCommentReplyAsRead = { comment_reply_id: i.props.node.comment_view.comment_reply.id, read: !i.props.node.comment_view.comment_reply.read, auth, @@ -1371,16 +1371,16 @@ export class CommentNode extends Component { } handleModBanBothSubmit(i: CommentNode) { - let cv = i.props.node.comment_view; - let auth = myAuth(); + const cv = i.props.node.comment_view; + const auth = myAuth(); if (auth) { if (i.state.banType == BanType.Community) { // If its an unban, restore all their data - let ban = !cv.creator_banned_from_community; + const ban = !cv.creator_banned_from_community; if (ban == false) { i.setState({ removeData: false }); } - let form: BanFromCommunity = { + const form: BanFromCommunity = { person_id: cv.creator.id, community_id: cv.community.id, ban, @@ -1392,11 +1392,11 @@ export class CommentNode extends Component { WebSocketService.Instance.send(wsClient.banFromCommunity(form)); } else { // If its an unban, restore all their data - let ban = !cv.creator.banned; + const ban = !cv.creator.banned; if (ban == false) { i.setState({ removeData: false }); } - let form: BanPerson = { + const form: BanPerson = { person_id: cv.creator.id, ban, remove_data: i.state.removeData, @@ -1433,17 +1433,17 @@ export class CommentNode extends Component { handlePurgeSubmit(i: CommentNode, event: any) { event.preventDefault(); - let auth = myAuth(); + const auth = myAuth(); if (auth) { if (i.state.purgeType == PurgeType.Person) { - let form: PurgePerson = { + const form: PurgePerson = { person_id: i.props.node.comment_view.creator.id, reason: i.state.purgeReason, auth, }; WebSocketService.Instance.send(wsClient.purgePerson(form)); } else if (i.state.purgeType == PurgeType.Comment) { - let form: PurgeComment = { + const form: PurgeComment = { comment_id: i.props.node.comment_view.comment.id, reason: i.state.purgeReason, auth, @@ -1464,10 +1464,10 @@ export class CommentNode extends Component { } handleAddModToCommunity(i: CommentNode) { - let cv = i.props.node.comment_view; - let auth = myAuth(); + const cv = i.props.node.comment_view; + const auth = myAuth(); if (auth) { - let form: AddModToCommunity = { + const form: AddModToCommunity = { person_id: cv.creator.id, community_id: cv.community.id, added: !isMod(cv.creator.id, i.props.moderators), @@ -1487,10 +1487,10 @@ export class CommentNode extends Component { } handleAddAdmin(i: CommentNode) { - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let creatorId = i.props.node.comment_view.creator.id; - let form: AddAdmin = { + const creatorId = i.props.node.comment_view.creator.id; + const form: AddAdmin = { person_id: creatorId, added: !isAdmin(creatorId, i.props.admins), auth, @@ -1509,10 +1509,10 @@ export class CommentNode extends Component { } handleTransferCommunity(i: CommentNode) { - let cv = i.props.node.comment_view; - let auth = myAuth(); + const cv = i.props.node.comment_view; + const auth = myAuth(); if (auth) { - let form: TransferCommunity = { + const form: TransferCommunity = { community_id: cv.community.id, person_id: cv.creator.id, auth, @@ -1531,8 +1531,8 @@ export class CommentNode extends Component { } get isCommentNew(): boolean { - let now = moment.utc().subtract(10, "minutes"); - let then = moment.utc(this.props.node.comment_view.comment.published); + const now = moment.utc().subtract(10, "minutes"); + const then = moment.utc(this.props.node.comment_view.comment.published); return now.isBefore(then); } @@ -1551,7 +1551,7 @@ export class CommentNode extends Component { } handleFetchChildren(i: CommentNode) { - let form: GetComments = { + const form: GetComments = { post_id: i.props.node.comment_view.post.id, parent_id: i.props.node.comment_view.comment.id, max_depth: commentTreeMaxDepth, @@ -1575,17 +1575,17 @@ export class CommentNode extends Component { } get pointsTippy(): string { - let points = i18n.t("number_of_points", { + const points = i18n.t("number_of_points", { count: Number(this.state.score), formattedCount: numToSI(this.state.score), }); - let upvotes = i18n.t("number_of_upvotes", { + const upvotes = i18n.t("number_of_upvotes", { count: Number(this.state.upvotes), formattedCount: numToSI(this.state.upvotes), }); - let downvotes = i18n.t("number_of_downvotes", { + const downvotes = i18n.t("number_of_downvotes", { count: Number(this.state.downvotes), formattedCount: numToSI(this.state.downvotes), }); diff --git a/src/shared/components/comment/comment-nodes.tsx b/src/shared/components/comment/comment-nodes.tsx index ba8997a..23f22fe 100644 --- a/src/shared/components/comment/comment-nodes.tsx +++ b/src/shared/components/comment/comment-nodes.tsx @@ -28,7 +28,7 @@ export class CommentNodes extends Component { } render() { - let maxComments = this.props.maxCommentsShown ?? this.props.nodes.length; + const maxComments = this.props.maxCommentsShown ?? this.props.nodes.length; return (
diff --git a/src/shared/components/comment/comment-report.tsx b/src/shared/components/comment/comment-report.tsx index 232fec6..64c659f 100644 --- a/src/shared/components/comment/comment-report.tsx +++ b/src/shared/components/comment/comment-report.tsx @@ -23,16 +23,16 @@ export class CommentReport extends Component { } render() { - let r = this.props.report; - let comment = r.comment; - let tippyContent = i18n.t( + const r = this.props.report; + const comment = r.comment; + const tippyContent = i18n.t( r.comment_report.resolved ? "unresolve_report" : "resolve_report" ); // Set the original post data ( a troll could change it ) comment.content = r.comment_report.original_comment_text; - let comment_view: CommentView = { + const comment_view: CommentView = { comment, creator: r.comment_creator, post: r.post, @@ -45,7 +45,7 @@ export class CommentReport extends Component { my_vote: r.my_vote, }; - let node: CommentNodeI = { + const node: CommentNodeI = { comment_view, children: [], depth: 0, @@ -102,9 +102,9 @@ export class CommentReport extends Component { } handleResolveReport(i: CommentReport) { - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let form: ResolveCommentReport = { + const form: ResolveCommentReport = { report_id: i.props.report.comment_report.id, resolved: !i.props.report.comment_report.resolved, auth, diff --git a/src/shared/components/common/banner-icon-header.tsx b/src/shared/components/common/banner-icon-header.tsx index e290145..1df23be 100644 --- a/src/shared/components/common/banner-icon-header.tsx +++ b/src/shared/components/common/banner-icon-header.tsx @@ -12,8 +12,8 @@ export class BannerIconHeader extends Component { } render() { - let banner = this.props.banner; - let icon = this.props.icon; + const banner = this.props.banner; + const icon = this.props.icon; return (
{banner && } diff --git a/src/shared/components/common/emoji-mart.tsx b/src/shared/components/common/emoji-mart.tsx index 6210366..dff8c3a 100644 --- a/src/shared/components/common/emoji-mart.tsx +++ b/src/shared/components/common/emoji-mart.tsx @@ -12,7 +12,7 @@ export class EmojiMart extends Component { this.handleEmojiClick = this.handleEmojiClick.bind(this); } componentDidMount() { - let div: any = document.getElementById("emoji-picker"); + const div: any = document.getElementById("emoji-picker"); if (div) { div.appendChild( getEmojiMart(this.handleEmojiClick, this.props.pickerOptions) diff --git a/src/shared/components/common/html-tags.tsx b/src/shared/components/common/html-tags.tsx index 67abe3a..4c673d9 100644 --- a/src/shared/components/common/html-tags.tsx +++ b/src/shared/components/common/html-tags.tsx @@ -14,9 +14,9 @@ interface HtmlTagsProps { /// Taken from https://metatags.io/ export class HtmlTags extends Component { render() { - let url = httpExternalPath(this.props.path); - let desc = this.props.description; - let image = this.props.image; + const url = httpExternalPath(this.props.path); + const desc = this.props.description; + const image = this.props.image; return ( diff --git a/src/shared/components/common/language-select.tsx b/src/shared/components/common/language-select.tsx index a63c4db..3523ab7 100644 --- a/src/shared/components/common/language-select.tsx +++ b/src/shared/components/common/language-select.tsx @@ -31,12 +31,12 @@ export class LanguageSelect extends Component { // Necessary because there is no HTML way to set selected for multiple in value= setSelectedValues() { - let ids = this.props.selectedLanguageIds?.map(toString); + const ids = this.props.selectedLanguageIds?.map(toString); if (ids) { - let select = (document.getElementById(this.id) as HTMLSelectElement) + const select = (document.getElementById(this.id) as HTMLSelectElement) .options; for (let i = 0; i < select.length; i++) { - let o = select[i]; + const o = select[i]; if (ids.includes(o.value)) { o.selected = true; } @@ -130,8 +130,8 @@ export class LanguageSelect extends Component { } handleLanguageChange(i: LanguageSelect, event: any) { - let options: HTMLOptionElement[] = Array.from(event.target.options); - let selected: number[] = options + const options: HTMLOptionElement[] = Array.from(event.target.options); + const selected: number[] = options .filter(o => o.selected) .map(o => Number(o.value)); diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index 8e65a0c..eff10d7 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -85,7 +85,7 @@ export class MarkdownTextArea extends Component< } componentDidMount() { - let textarea: any = document.getElementById(this.id); + const textarea: any = document.getElementById(this.id); if (textarea) { autosize(textarea); this.tribute.attach(textarea); @@ -132,7 +132,7 @@ export class MarkdownTextArea extends Component< } render() { - let languageId = this.state.languageId; + const languageId = this.state.languageId; return (
@@ -321,7 +321,7 @@ export class MarkdownTextArea extends Component< handleEmoji(i: MarkdownTextArea, e: any) { let value = e.native; if (value == null) { - let emoji = customEmojisLookup.get(e.id)?.custom_emoji; + const emoji = customEmojisLookup.get(e.id)?.custom_emoji; if (emoji) { value = `![${emoji.alt_text}](${emoji.image_url} "${emoji.shortcode}")`; } @@ -330,7 +330,7 @@ export class MarkdownTextArea extends Component< content: `${i.state.content ?? ""} ${value} `, }); i.contentChange(); - let textarea: any = document.getElementById(i.id); + const textarea: any = document.getElementById(i.id); autosize.update(textarea); } @@ -420,7 +420,7 @@ export class MarkdownTextArea extends Component< contentChange() { // Coerces the undefineds to empty strings, for replacing in the DB - let content = this.state.content ?? ""; + const content = this.state.content ?? ""; this.props.onContentChange?.(content); } @@ -441,7 +441,7 @@ export class MarkdownTextArea extends Component< handleSubmit(i: MarkdownTextArea, event: any) { event.preventDefault(); i.setState({ loading: true }); - let msg = { + const msg = { val: i.state.content, formId: i.formId, languageId: i.state.languageId, @@ -589,7 +589,7 @@ export class MarkdownTextArea extends Component< } simpleInsert(chars: string) { - let content = this.state.content; + const content = this.state.content; if (!content) { this.setState({ content: `${chars} ` }); } else { @@ -598,7 +598,7 @@ export class MarkdownTextArea extends Component< }); } - let textarea: any = document.getElementById(this.id); + const textarea: any = document.getElementById(this.id); textarea.focus(); setTimeout(() => { autosize.update(textarea); @@ -608,8 +608,8 @@ export class MarkdownTextArea extends Component< handleInsertSpoiler(i: MarkdownTextArea, event: any) { event.preventDefault(); - let beforeChars = `\n::: spoiler ${i18n.t("spoiler")}\n`; - let afterChars = "\n:::\n"; + const beforeChars = `\n::: spoiler ${i18n.t("spoiler")}\n`; + const afterChars = "\n:::\n"; i.simpleSurroundBeforeAfter(beforeChars, afterChars); } diff --git a/src/shared/components/common/moment-time.tsx b/src/shared/components/common/moment-time.tsx index 81aedd1..10714f5 100644 --- a/src/shared/components/common/moment-time.tsx +++ b/src/shared/components/common/moment-time.tsx @@ -15,13 +15,13 @@ export class MomentTime extends Component { constructor(props: any, context: any) { super(props, context); - let lang = getLanguages(); + const lang = getLanguages(); moment.locale(lang); } createdAndModifiedTimes() { - let updated = this.props.updated; + const updated = this.props.updated; let line = `${capitalizeFirstLetter(i18n.t("created"))}: ${this.format( this.props.published )}`; @@ -45,7 +45,7 @@ export class MomentTime extends Component { ); } else { - let published = this.props.published; + const published = this.props.published; return ( { // sample url: // http://localhost:8535/pictrs/image/file.png?thumbnail=256&format=jpg - let split = this.props.src.split("/pictrs/image/"); + const split = this.props.src.split("/pictrs/image/"); // If theres not multiple, then its not a pictrs image if (split.length == 1) { return this.props.src; } - let host = split[0]; - let path = split[1]; + const host = split[0]; + const path = split[1]; - let params = { format }; + const params = { format }; if (this.props.thumbnail) { params["thumbnail"] = thumbnailSize; @@ -69,8 +69,8 @@ export class PictrsImage extends Component { params["thumbnail"] = iconThumbnailSize; } - let paramsStr = new URLSearchParams(params).toString(); - let out = `${host}/pictrs/image/${path}?${paramsStr}`; + const paramsStr = new URLSearchParams(params).toString(); + const out = `${host}/pictrs/image/${path}?${paramsStr}`; return out; } diff --git a/src/shared/components/common/registration-application.tsx b/src/shared/components/common/registration-application.tsx index cbd8ffa..edf03a1 100644 --- a/src/shared/components/common/registration-application.tsx +++ b/src/shared/components/common/registration-application.tsx @@ -35,9 +35,9 @@ export class RegistrationApplication extends Component< } render() { - let a = this.props.application; - let ra = this.props.application.registration_application; - let accepted = a.creator_local_user.accepted_application; + const a = this.props.application; + const ra = this.props.application.registration_application; + const accepted = a.creator_local_user.accepted_application; return (
@@ -116,10 +116,10 @@ export class RegistrationApplication extends Component< } handleApprove(i: RegistrationApplication) { - let auth = myAuth(); + const auth = myAuth(); if (auth) { i.setState({ denyExpanded: false }); - let form: ApproveRegistrationApplication = { + const form: ApproveRegistrationApplication = { id: i.props.application.registration_application.id, approve: true, auth, @@ -133,9 +133,9 @@ export class RegistrationApplication extends Component< handleDeny(i: RegistrationApplication) { if (i.state.denyExpanded) { i.setState({ denyExpanded: false }); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let form: ApproveRegistrationApplication = { + const form: ApproveRegistrationApplication = { id: i.props.application.registration_application.id, approve: false, deny_reason: i.state.denyReason, diff --git a/src/shared/components/community/community-form.tsx b/src/shared/components/community/community-form.tsx index c6ba5d8..372e66a 100644 --- a/src/shared/components/community/community-form.tsx +++ b/src/shared/components/community/community-form.tsx @@ -79,7 +79,7 @@ export class CommunityForm extends Component< this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); - let cv = this.props.community_view; + const cv = this.props.community_view; if (cv) { this.state = { @@ -301,14 +301,14 @@ export class CommunityForm extends Component< handleCreateCommunitySubmit(i: CommunityForm, event: any) { event.preventDefault(); i.setState({ loading: true }); - let cForm = i.state.form; - let auth = myAuth(); + const cForm = i.state.form; + const auth = myAuth(); - let cv = i.props.community_view; + const cv = i.props.community_view; if (auth) { if (cv) { - let form: EditCommunity = { + const form: EditCommunity = { community_id: cv.community.id, title: cForm.title, description: cForm.description, @@ -323,7 +323,7 @@ export class CommunityForm extends Component< WebSocketService.Instance.send(wsClient.editCommunity(form)); } else { if (cForm.title && cForm.name) { - let form: CreateCommunity = { + const form: CreateCommunity = { name: cForm.name, title: cForm.title, description: cForm.description, @@ -390,7 +390,7 @@ export class CommunityForm extends Component< } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { // Errors handled by top level pages @@ -398,15 +398,15 @@ export class CommunityForm extends Component< this.setState({ loading: false }); return; } else if (op == UserOperation.CreateCommunity) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.props.onCreate?.(data.community_view); // Update myUserInfo - let community = data.community_view.community; + const community = data.community_view.community; - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; if (mui) { - let person = mui.local_user_view.person; + const person = mui.local_user_view.person; mui.follows.push({ community, follower: person, @@ -417,21 +417,21 @@ export class CommunityForm extends Component< }); } } else if (op == UserOperation.EditCommunity) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ loading: false }); this.props.onEdit?.(data.community_view); - let community = data.community_view.community; + const community = data.community_view.community; - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; if (mui) { - let followFound = mui.follows.findIndex( + const followFound = mui.follows.findIndex( f => f.community.id == community.id ); if (followFound) { mui.follows[followFound].community = community; } - let moderatesFound = mui.moderates.findIndex( + const moderatesFound = mui.moderates.findIndex( f => f.community.id == community.id ); if (moderatesFound) { diff --git a/src/shared/components/community/community-link.tsx b/src/shared/components/community/community-link.tsx index bf15971..23d52ae 100644 --- a/src/shared/components/community/community-link.tsx +++ b/src/shared/components/community/community-link.tsx @@ -18,22 +18,22 @@ export class CommunityLink extends Component { } render() { - let community = this.props.community; + const community = this.props.community; let name_: string, title: string, link: string; - let local = community.local == null ? true : community.local; + const local = community.local == null ? true : community.local; if (local) { name_ = community.name; title = community.title; link = `/c/${community.name}`; } else { - let domain = hostname(community.actor_id); + const domain = hostname(community.actor_id); name_ = `${community.name}@${domain}`; title = `${community.title}@${domain}`; link = !this.props.realLink ? `/c/${name_}` : community.actor_id; } - let apubName = `!${name_}`; - let displayName = this.props.useApubName ? apubName : title; + const apubName = `!${name_}`; + const displayName = this.props.useApubName ? apubName : title; return !this.props.realLink ? ( { } avatarAndName(displayName: string) { - let icon = this.props.community.icon; + const icon = this.props.community.icon; return ( <> {!this.props.hideAvatar && diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index a5eef75..b55bd50 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -124,8 +124,8 @@ export class Sidebar extends Component { } communityTitle() { - let community = this.props.community_view.community; - let subscribed = this.props.community_view.subscribed; + const community = this.props.community_view.community; + const subscribed = this.props.community_view.subscribed; return (
@@ -178,8 +178,8 @@ export class Sidebar extends Component { } badges() { - let community_view = this.props.community_view; - let counts = community_view.counts; + const community_view = this.props.community_view; + const counts = community_view.counts; return (
  • @@ -284,7 +284,7 @@ export class Sidebar extends Component { } createPost() { - let cv = this.props.community_view; + const cv = this.props.community_view; return ( { } subscribe() { - let community_view = this.props.community_view; + const community_view = this.props.community_view; return (
    {community_view.subscribed == "NotSubscribed" && ( @@ -314,8 +314,8 @@ export class Sidebar extends Component { } blockCommunity() { - let community_view = this.props.community_view; - let blocked = this.props.community_view.blocked; + const community_view = this.props.community_view; + const blocked = this.props.community_view.blocked; return (
    @@ -340,7 +340,7 @@ export class Sidebar extends Component { } description() { - let desc = this.props.community_view.community.description; + const desc = this.props.community_view.community.description; return ( desc && (
    @@ -349,7 +349,7 @@ export class Sidebar extends Component { } adminButtons() { - let community_view = this.props.community_view; + const community_view = this.props.community_view; return ( <>
      @@ -536,9 +536,9 @@ export class Sidebar extends Component { handleDeleteClick(i: Sidebar, event: any) { event.preventDefault(); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let deleteForm: DeleteCommunity = { + const deleteForm: DeleteCommunity = { community_id: i.props.community_view.community.id, deleted: !i.props.community_view.community.deleted, auth, @@ -552,10 +552,10 @@ export class Sidebar extends Component { } handleLeaveModTeamClick(i: Sidebar) { - let mui = UserService.Instance.myUserInfo; - let auth = myAuth(); + const mui = UserService.Instance.myUserInfo; + const auth = myAuth(); if (auth && mui) { - let form: AddModToCommunity = { + const form: AddModToCommunity = { person_id: mui.local_user_view.person.id, community_id: i.props.community_view.community.id, added: false, @@ -572,10 +572,10 @@ export class Sidebar extends Component { handleUnsubscribe(i: Sidebar, event: any) { event.preventDefault(); - let community_id = i.props.community_view.community.id; - let auth = myAuth(); + const community_id = i.props.community_view.community.id; + const auth = myAuth(); if (auth) { - let form: FollowCommunity = { + const form: FollowCommunity = { community_id, follow: false, auth, @@ -584,7 +584,7 @@ export class Sidebar extends Component { } // Update myUserInfo - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; if (mui) { mui.follows = mui.follows.filter(i => i.community.id != community_id); } @@ -592,10 +592,10 @@ export class Sidebar extends Component { handleSubscribe(i: Sidebar, event: any) { event.preventDefault(); - let community_id = i.props.community_view.community.id; - let auth = myAuth(); + const community_id = i.props.community_view.community.id; + const auth = myAuth(); if (auth) { - let form: FollowCommunity = { + const form: FollowCommunity = { community_id, follow: true, auth, @@ -604,7 +604,7 @@ export class Sidebar extends Component { } // Update myUserInfo - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; if (mui) { mui.follows.push({ community: i.props.community_view.community, @@ -635,9 +635,9 @@ export class Sidebar extends Component { handleModRemoveSubmit(i: Sidebar, event: any) { event.preventDefault(); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let removeForm: RemoveCommunity = { + const removeForm: RemoveCommunity = { community_id: i.props.community_view.community.id, removed: !i.props.community_view.community.removed, reason: i.state.removeReason, @@ -661,9 +661,9 @@ export class Sidebar extends Component { handlePurgeSubmit(i: Sidebar, event: any) { event.preventDefault(); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let form: PurgeCommunity = { + const form: PurgeCommunity = { community_id: i.props.community_view.community.id, reason: i.state.purgeReason, auth, @@ -675,9 +675,9 @@ export class Sidebar extends Component { handleBlock(i: Sidebar, event: any) { event.preventDefault(); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let blockCommunityForm: BlockCommunity = { + const blockCommunityForm: BlockCommunity = { community_id: i.props.community_view.community.id, block: true, auth, @@ -690,9 +690,9 @@ export class Sidebar extends Component { handleUnblock(i: Sidebar, event: any) { event.preventDefault(); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let blockCommunityForm: BlockCommunity = { + const blockCommunityForm: BlockCommunity = { community_id: i.props.community_view.community.id, block: false, auth, diff --git a/src/shared/components/home/admin-settings.tsx b/src/shared/components/home/admin-settings.tsx index d266db5..eb455b9 100644 --- a/src/shared/components/home/admin-settings.tsx +++ b/src/shared/components/home/admin-settings.tsx @@ -70,7 +70,7 @@ export class AdminSettings extends Component { loading: false, }; } else { - let cAuth = myAuth(); + const cAuth = myAuth(); if (cAuth) { WebSocketService.Instance.send( wsClient.getBannedPersons({ @@ -85,11 +85,11 @@ export class AdminSettings extends Component { } static fetchInitialData(req: InitialFetchRequest): Promise[] { - let promises: Promise[] = []; + const promises: Promise[] = []; - let auth = req.auth; + const auth = req.auth; if (auth) { - let bannedPersonsForm: GetBannedPersons = { auth }; + const bannedPersonsForm: GetBannedPersons = { auth }; promises.push(req.client.getBannedPersons(bannedPersonsForm)); promises.push(req.client.getFederatedInstances({ auth })); } @@ -236,7 +236,7 @@ export class AdminSettings extends Component { } handleLeaveAdminTeam(i: AdminSettings) { - let auth = myAuth(); + const auth = myAuth(); if (auth) { i.setState({ leaveAdminTeamLoading: true }); WebSocketService.Instance.send(wsClient.leaveAdmin({ auth })); @@ -244,7 +244,7 @@ export class AdminSettings extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); @@ -252,20 +252,20 @@ export class AdminSettings extends Component { this.setState({ loading: false }); return; } else if (op == UserOperation.EditSite) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState(s => ((s.siteRes.site_view = data.site_view), s)); toast(i18n.t("site_saved")); } else if (op == UserOperation.GetBannedPersons) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ banned: data.banned, loading: false }); } else if (op == UserOperation.LeaveAdmin) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState(s => ((s.siteRes.site_view = data.site_view), s)); this.setState({ leaveAdminTeamLoading: false }); toast(i18n.t("left_admin_team")); this.context.router.history.push("/"); } else if (op == UserOperation.GetFederatedInstances) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ instancesRes: data }); } } diff --git a/src/shared/components/home/emojis-form.tsx b/src/shared/components/home/emojis-form.tsx index d63633b..044964d 100644 --- a/src/shared/components/home/emojis-form.tsx +++ b/src/shared/components/home/emojis-form.tsx @@ -325,10 +325,10 @@ export class EmojiForm extends Component { props: { form: EmojiForm; index: number }, event: any ) { - let custom_emojis = [...props.form.state.customEmojis]; - let pagedIndex = + const custom_emojis = [...props.form.state.customEmojis]; + const pagedIndex = (props.form.state.page - 1) * props.form.itemsPerPage + props.index; - let item = { + const item = { ...props.form.state.customEmojis[pagedIndex], category: event.target.value, changed: true, @@ -341,10 +341,10 @@ export class EmojiForm extends Component { props: { form: EmojiForm; index: number }, event: any ) { - let custom_emojis = [...props.form.state.customEmojis]; - let pagedIndex = + const custom_emojis = [...props.form.state.customEmojis]; + const pagedIndex = (props.form.state.page - 1) * props.form.itemsPerPage + props.index; - let item = { + const item = { ...props.form.state.customEmojis[pagedIndex], shortcode: event.target.value, changed: true, @@ -357,10 +357,10 @@ export class EmojiForm extends Component { props: { form: EmojiForm; index: number; overrideValue: string | null }, event: any ) { - let custom_emojis = [...props.form.state.customEmojis]; - let pagedIndex = + const custom_emojis = [...props.form.state.customEmojis]; + const pagedIndex = (props.form.state.page - 1) * props.form.itemsPerPage + props.index; - let item = { + const item = { ...props.form.state.customEmojis[pagedIndex], image_url: props.overrideValue ?? event.target.value, changed: true, @@ -373,10 +373,10 @@ export class EmojiForm extends Component { props: { form: EmojiForm; index: number }, event: any ) { - let custom_emojis = [...props.form.state.customEmojis]; - let pagedIndex = + const custom_emojis = [...props.form.state.customEmojis]; + const pagedIndex = (props.form.state.page - 1) * props.form.itemsPerPage + props.index; - let item = { + const item = { ...props.form.state.customEmojis[pagedIndex], alt_text: event.target.value, changed: true, @@ -389,10 +389,10 @@ export class EmojiForm extends Component { props: { form: EmojiForm; index: number }, event: any ) { - let custom_emojis = [...props.form.state.customEmojis]; - let pagedIndex = + const custom_emojis = [...props.form.state.customEmojis]; + const pagedIndex = (props.form.state.page - 1) * props.form.itemsPerPage + props.index; - let item = { + const item = { ...props.form.state.customEmojis[pagedIndex], keywords: event.target.value, changed: true, @@ -406,7 +406,7 @@ export class EmojiForm extends Component { index: number; cv: CustomEmojiViewForm; }) { - let pagedIndex = + const pagedIndex = (props.form.state.page - 1) * props.form.itemsPerPage + props.index; if (props.cv.id != 0) { const deleteForm: DeleteCustomEmoji = { @@ -415,7 +415,7 @@ export class EmojiForm extends Component { }; WebSocketService.Instance.send(wsClient.deleteCustomEmoji(deleteForm)); } else { - let custom_emojis = [...props.form.state.customEmojis]; + const custom_emojis = [...props.form.state.customEmojis]; custom_emojis.splice(Number(pagedIndex), 1); props.form.setState({ customEmojis: custom_emojis }); } @@ -451,10 +451,10 @@ export class EmojiForm extends Component { handleAddEmojiClick(form: EmojiForm, event: any) { event.preventDefault(); - let custom_emojis = [...form.state.customEmojis]; + const custom_emojis = [...form.state.customEmojis]; const page = 1 + Math.floor(form.state.customEmojis.length / form.itemsPerPage); - let item: CustomEmojiViewForm = { + const item: CustomEmojiViewForm = { id: 0, shortcode: "", alt_text: "", @@ -485,8 +485,8 @@ export class EmojiForm extends Component { pictrsDeleteToast(file.name, res.delete_url as string); } else { toast(JSON.stringify(res), "danger"); - let hash = res.files?.at(0)?.file; - let url = `${res.url}/${hash}`; + const hash = res.files?.at(0)?.file; + const url = `${res.url}/${hash}`; props.form.handleEmojiImageUrlChange( { form: props.form, index: props.index, overrideValue: url }, event @@ -508,7 +508,7 @@ export class EmojiForm extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); @@ -516,11 +516,11 @@ export class EmojiForm extends Component { this.setState({ loading: false }); return; } else if (op == UserOperation.CreateCustomEmoji) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); const custom_emoji_view = data.custom_emoji; updateEmojiDataModel(custom_emoji_view); - let currentEmojis = this.state.customEmojis; - let newEmojiIndex = currentEmojis.findIndex( + const currentEmojis = this.state.customEmojis; + const newEmojiIndex = currentEmojis.findIndex( x => x.shortcode == custom_emoji_view.custom_emoji.shortcode ); currentEmojis[newEmojiIndex].id = custom_emoji_view.custom_emoji.id; @@ -529,11 +529,11 @@ export class EmojiForm extends Component { toast(i18n.t("saved_emoji")); this.setState({ loading: false }); } else if (op == UserOperation.EditCustomEmoji) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); const custom_emoji_view = data.custom_emoji; updateEmojiDataModel(data.custom_emoji); - let currentEmojis = this.state.customEmojis; - let newEmojiIndex = currentEmojis.findIndex( + const currentEmojis = this.state.customEmojis; + const newEmojiIndex = currentEmojis.findIndex( x => x.shortcode == custom_emoji_view.custom_emoji.shortcode ); currentEmojis[newEmojiIndex].changed = false; @@ -541,10 +541,10 @@ export class EmojiForm extends Component { toast(i18n.t("saved_emoji")); this.setState({ loading: false }); } else if (op == UserOperation.DeleteCustomEmoji) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if (data.success) { removeFromEmojiDataModel(data.id); - let custom_emojis = [ + const custom_emojis = [ ...this.state.customEmojis.filter(x => x.id != data.id), ]; this.setState({ customEmojis: custom_emojis }); diff --git a/src/shared/components/home/instances.tsx b/src/shared/components/home/instances.tsx index 674374d..80f7c24 100644 --- a/src/shared/components/home/instances.tsx +++ b/src/shared/components/home/instances.tsx @@ -55,7 +55,7 @@ export class Instances extends Component { } static fetchInitialData(req: InitialFetchRequest): Promise[] { - let promises: Promise[] = []; + const promises: Promise[] = []; promises.push(req.client.getFederatedInstances({})); @@ -73,7 +73,7 @@ export class Instances extends Component { } render() { - let federated_instances = this.state.instancesRes?.federated_instances; + const federated_instances = this.state.instancesRes?.federated_instances; return federated_instances ? (
      { ); } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); @@ -145,7 +145,7 @@ export class Instances extends Component { this.setState({ loading: false }); return; } else if (op == UserOperation.GetFederatedInstances) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ loading: false, instancesRes: data }); } } diff --git a/src/shared/components/home/legal.tsx b/src/shared/components/home/legal.tsx index d2c9953..15bea9b 100644 --- a/src/shared/components/home/legal.tsx +++ b/src/shared/components/home/legal.tsx @@ -23,7 +23,7 @@ export class Legal extends Component { } render() { - let legal = this.state.siteRes.site_view.local_site.legal_information; + const legal = this.state.siteRes.site_view.local_site.legal_information; return (
      { handleLoginSubmit(i: Login, event: any) { event.preventDefault(); i.setState({ loginLoading: true }); - let lForm = i.state.form; - let username_or_email = lForm.username_or_email; - let password = lForm.password; - let totp_2fa_token = lForm.totp_2fa_token; + const lForm = i.state.form; + const username_or_email = lForm.username_or_email; + const password = lForm.password; + const totp_2fa_token = lForm.totp_2fa_token; if (username_or_email && password) { - let form: LoginI = { + const form: LoginI = { username_or_email, password, totp_2fa_token, @@ -212,15 +212,15 @@ export class Login extends Component { handlePasswordReset(i: Login, event: any) { event.preventDefault(); - let email = i.state.form.username_or_email; + const email = i.state.form.username_or_email; if (email) { - let resetForm: PasswordReset = { email }; + const resetForm: PasswordReset = { email }; WebSocketService.Instance.send(wsClient.passwordReset(resetForm)); } } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { // If the error comes back that the token is missing, show the TOTP field @@ -235,14 +235,14 @@ export class Login extends Component { } } else { if (op == UserOperation.Login) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); UserService.Instance.login(data); this.props.history.push("/"); location.reload(); } else if (op == UserOperation.PasswordReset) { toast(i18n.t("reset_password_mail_sent")); } else if (op == UserOperation.GetSite) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ siteRes: data }); } } diff --git a/src/shared/components/home/setup.tsx b/src/shared/components/home/setup.tsx index 726edc3..b1ecb27 100644 --- a/src/shared/components/home/setup.tsx +++ b/src/shared/components/home/setup.tsx @@ -173,9 +173,9 @@ export class Setup extends Component { event.preventDefault(); i.setState({ userLoading: true }); event.preventDefault(); - let cForm = i.state.form; + const cForm = i.state.form; if (cForm.username && cForm.password && cForm.password_verify) { - let form: Register = { + const form: Register = { username: cForm.username, password: cForm.password, password_verify: cForm.password_verify, @@ -211,13 +211,13 @@ export class Setup extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); this.setState({ userLoading: false }); return; } else if (op == UserOperation.Register) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ userLoading: false }); UserService.Instance.login(data); if (UserService.Instance.jwtInfo) { diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx index 457b416..65741eb 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -109,7 +109,7 @@ export class Signup extends Component { } get documentTitle(): string { - let siteView = this.state.siteRes.site_view; + const siteView = this.state.siteRes.site_view; return `${this.titleName(siteView)} - ${siteView.site.name}`; } @@ -140,7 +140,7 @@ export class Signup extends Component { } registerForm() { - let siteView = this.state.siteRes.site_view; + const siteView = this.state.siteRes.site_view; return (
      {this.titleName(siteView)}
      @@ -371,7 +371,7 @@ export class Signup extends Component { } showCaptcha() { - let captchaRes = this.state.captcha?.ok; + const captchaRes = this.state.captcha?.ok; return captchaRes ? (
      <> @@ -401,14 +401,14 @@ export class Signup extends Component { } get passwordStrength(): string | undefined { - let password = this.state.form.password; + const password = this.state.form.password; return password ? passwordStrength(password, passwordStrengthOptions).value : undefined; } get passwordColorClass(): string { - let strength = this.passwordStrength; + const strength = this.passwordStrength; if (strength && ["weak", "medium"].includes(strength)) { return "text-warning"; @@ -422,9 +422,9 @@ export class Signup extends Component { handleRegisterSubmit(i: Signup, event: any) { event.preventDefault(); i.setState({ registerLoading: true }); - let cForm = i.state.form; + const cForm = i.state.form; if (cForm.username && cForm.password && cForm.password_verify) { - let form: Register = { + const form: Register = { username: cForm.username, password: cForm.password, password_verify: cForm.password_verify, @@ -490,10 +490,10 @@ export class Signup extends Component { handleCaptchaPlay(i: Signup) { // This was a bad bug, it should only build the new audio on a new file. // Replays would stop prematurely if this was rebuilt every time. - let captchaRes = i.state.captcha?.ok; + const captchaRes = i.state.captcha?.ok; if (captchaRes) { if (!i.audio) { - let base64 = `data:audio/wav;base64,${captchaRes.wav}`; + const base64 = `data:audio/wav;base64,${captchaRes.wav}`; i.audio = new Audio(base64); i.audio.play(); @@ -514,7 +514,7 @@ export class Signup extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); @@ -524,7 +524,7 @@ export class Signup extends Component { return; } else { if (op == UserOperation.Register) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); // Only log them in if a jwt was set if (data.jwt) { UserService.Instance.login(data); @@ -540,7 +540,7 @@ export class Signup extends Component { this.props.history.push("/"); } } else if (op == UserOperation.GetCaptcha) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if (data.ok) { this.setState({ captcha: data }); this.setState(s => ((s.form.captcha_uuid = data.ok?.uuid), s)); @@ -548,7 +548,7 @@ export class Signup extends Component { } else if (op == UserOperation.PasswordReset) { toast(i18n.t("reset_password_mail_sent")); } else if (op == UserOperation.GetSite) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ siteRes: data }); } } diff --git a/src/shared/components/home/site-form.tsx b/src/shared/components/home/site-form.tsx index d3d3679..b2f6541 100644 --- a/src/shared/components/home/site-form.tsx +++ b/src/shared/components/home/site-form.tsx @@ -76,8 +76,8 @@ export class SiteForm extends Component { this.handleDiscussionLanguageChange = this.handleDiscussionLanguageChange.bind(this); - let site = this.props.siteRes.site_view.site; - let ls = this.props.siteRes.site_view.local_site; + const site = this.props.siteRes.site_view.site; + const ls = this.props.siteRes.site_view.local_site; this.state = { ...this.state, siteForm: { @@ -149,7 +149,7 @@ export class SiteForm extends Component { } render() { - let siteSetup = this.props.siteRes.site_view.local_site.site_setup; + const siteSetup = this.props.siteRes.site_view.local_site.site_setup; return ( <> { handleCreateSiteSubmit(i: SiteForm, event: any) { event.preventDefault(); i.setState({ loading: true }); - let auth = myAuth() ?? "TODO"; + const auth = myAuth() ?? "TODO"; i.setState(s => ((s.siteForm.auth = auth), s)); if (i.props.siteRes.site_view.local_site.site_setup) { WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm)); } else { - let sForm = i.state.siteForm; - let form: CreateSite = { + const sForm = i.state.siteForm; + const form: CreateSite = { name: sForm.name ?? "My site", sidebar: sForm.sidebar, description: sForm.description, @@ -841,7 +841,7 @@ export class SiteForm extends Component { } handleTaglineChange(i: SiteForm, index: number, val: string) { - let taglines = i.state.siteForm.taglines; + const taglines = i.state.siteForm.taglines; if (taglines) { taglines[index] = val; i.setState(i.state); @@ -854,7 +854,7 @@ export class SiteForm extends Component { event: InfernoMouseEvent ) { event.preventDefault(); - let taglines = i.state.siteForm.taglines; + const taglines = i.state.siteForm.taglines; if (taglines) { taglines.splice(index, 1); i.state.siteForm.taglines = undefined; diff --git a/src/shared/components/home/site-sidebar.tsx b/src/shared/components/home/site-sidebar.tsx index 23fbf40..051c3af 100644 --- a/src/shared/components/home/site-sidebar.tsx +++ b/src/shared/components/home/site-sidebar.tsx @@ -67,7 +67,7 @@ export class SiteSidebar extends Component { } siteInfo() { - let site = this.props.site; + const site = this.props.site; return (
      {site.description &&
      {site.description}
      } @@ -98,8 +98,8 @@ export class SiteSidebar extends Component { } badges(siteAggregates: SiteAggregates) { - let counts = siteAggregates; - let online = this.props.online ?? 1; + const counts = siteAggregates; + const online = this.props.online ?? 1; return (
      • diff --git a/src/shared/components/home/tagline-form.tsx b/src/shared/components/home/tagline-form.tsx index 8f46b50..59eeb4a 100644 --- a/src/shared/components/home/tagline-form.tsx +++ b/src/shared/components/home/tagline-form.tsx @@ -131,7 +131,7 @@ export class TaglineForm extends Component { } handleTaglineChange(i: TaglineForm, index: number, val: string) { - let taglines = i.state.siteForm.taglines; + const taglines = i.state.siteForm.taglines; if (taglines) { taglines[index] = val; i.setState(i.state); @@ -143,7 +143,7 @@ export class TaglineForm extends Component { event: any ) { event.preventDefault(); - let taglines = props.form.state.siteForm.taglines; + const taglines = props.form.state.siteForm.taglines; if (taglines) { taglines.splice(props.index, 1); props.form.state.siteForm.taglines = undefined; @@ -167,7 +167,7 @@ export class TaglineForm extends Component { handleSaveClick(i: TaglineForm) { i.setState({ loading: true }); - let auth = myAuth() ?? "TODO"; + const auth = myAuth() ?? "TODO"; i.setState(s => ((s.siteForm.auth = auth), s)); WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm)); i.setState({ ...i.state, editingRow: undefined }); diff --git a/src/shared/components/person/inbox.tsx b/src/shared/components/person/inbox.tsx index 8145ab6..b718e9a 100644 --- a/src/shared/components/person/inbox.tsx +++ b/src/shared/components/person/inbox.tsx @@ -141,7 +141,7 @@ export class Inbox extends Component { } get documentTitle(): string { - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; return mui ? `@${mui.local_user_view.person.name} ${i18n.t("inbox")} - ${ this.state.siteRes.site_view.site.name @@ -150,8 +150,8 @@ export class Inbox extends Component { } render() { - let auth = myAuth(); - let inboxRss = auth ? `/feeds/inbox/${auth}.xml` : undefined; + const auth = myAuth(); + const inboxRss = auth ? `/feeds/inbox/${auth}.xml` : undefined; return (
        {this.state.loading ? ( @@ -343,13 +343,13 @@ export class Inbox extends Component { } buildCombined(): ReplyType[] { - let replies: ReplyType[] = this.state.replies.map(r => + const replies: ReplyType[] = this.state.replies.map(r => this.replyToReplyType(r) ); - let mentions: ReplyType[] = this.state.mentions.map(r => + const mentions: ReplyType[] = this.state.mentions.map(r => this.mentionToReplyType(r) ); - let messages: ReplyType[] = this.state.messages.map(r => + const messages: ReplyType[] = this.state.messages.map(r => this.messageToReplyType(r) ); @@ -482,14 +482,14 @@ export class Inbox extends Component { } static fetchInitialData(req: InitialFetchRequest): Promise[] { - let promises: Promise[] = []; + const promises: Promise[] = []; - let sort: CommentSortType = "New"; - let auth = req.auth; + const sort: CommentSortType = "New"; + const auth = req.auth; if (auth) { // It can be /u/me, or /username/1 - let repliesForm: GetReplies = { + const repliesForm: GetReplies = { sort: "New", unread_only: true, page: 1, @@ -498,7 +498,7 @@ export class Inbox extends Component { }; promises.push(req.client.getReplies(repliesForm)); - let personMentionsForm: GetPersonMentions = { + const personMentionsForm: GetPersonMentions = { sort, unread_only: true, page: 1, @@ -507,7 +507,7 @@ export class Inbox extends Component { }; promises.push(req.client.getPersonMentions(personMentionsForm)); - let privateMessagesForm: GetPrivateMessages = { + const privateMessagesForm: GetPrivateMessages = { unread_only: true, page: 1, limit: fetchLimit, @@ -520,14 +520,14 @@ export class Inbox extends Component { } refetch() { - let sort = this.state.sort; - let unread_only = this.state.unreadOrAll == UnreadOrAll.Unread; - let page = this.state.page; - let limit = fetchLimit; - let auth = myAuth(); + const sort = this.state.sort; + const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread; + const page = this.state.page; + const limit = fetchLimit; + const auth = myAuth(); if (auth) { - let repliesForm: GetReplies = { + const repliesForm: GetReplies = { sort, unread_only, page, @@ -536,7 +536,7 @@ export class Inbox extends Component { }; WebSocketService.Instance.send(wsClient.getReplies(repliesForm)); - let personMentionsForm: GetPersonMentions = { + const personMentionsForm: GetPersonMentions = { sort, unread_only, page, @@ -547,7 +547,7 @@ export class Inbox extends Component { wsClient.getPersonMentions(personMentionsForm) ); - let privateMessagesForm: GetPrivateMessages = { + const privateMessagesForm: GetPrivateMessages = { unread_only, page, limit, @@ -565,7 +565,7 @@ export class Inbox extends Component { } markAllAsRead(i: Inbox) { - let auth = myAuth(); + const auth = myAuth(); if (auth) { WebSocketService.Instance.send( wsClient.markAllAsRead({ @@ -581,7 +581,7 @@ export class Inbox extends Component { } sendUnreadCount(read: boolean) { - let urcs = UserService.Instance.unreadInboxCountSub; + const urcs = UserService.Instance.unreadInboxCountSub; if (read) { urcs.next(urcs.getValue() - 1); } else { @@ -590,7 +590,7 @@ export class Inbox extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); @@ -598,31 +598,31 @@ export class Inbox extends Component { } else if (msg.reconnect) { this.refetch(); } else if (op == UserOperation.GetReplies) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ replies: data.replies }); this.setState({ combined: this.buildCombined(), loading: false }); window.scrollTo(0, 0); setupTippy(); } else if (op == UserOperation.GetPersonMentions) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ mentions: data.mentions }); this.setState({ combined: this.buildCombined() }); window.scrollTo(0, 0); setupTippy(); } else if (op == UserOperation.GetPrivateMessages) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ messages: data.private_messages }); this.setState({ combined: this.buildCombined() }); window.scrollTo(0, 0); setupTippy(); } else if (op == UserOperation.EditPrivateMessage) { - let data = wsJsonToRes(msg); - let found = this.state.messages.find( + const data = wsJsonToRes(msg); + const found = this.state.messages.find( m => m.private_message.id === data.private_message_view.private_message.id ); if (found) { - let combinedView = this.state.combined.find( + const combinedView = this.state.combined.find( i => i.id == data.private_message_view.private_message.id )?.view as PrivateMessageView | undefined; if (combinedView) { @@ -634,13 +634,13 @@ export class Inbox extends Component { } this.setState(this.state); } else if (op == UserOperation.DeletePrivateMessage) { - let data = wsJsonToRes(msg); - let found = this.state.messages.find( + const data = wsJsonToRes(msg); + const found = this.state.messages.find( m => m.private_message.id === data.private_message_view.private_message.id ); if (found) { - let combinedView = this.state.combined.find( + const combinedView = this.state.combined.find( i => i.id == data.private_message_view.private_message.id )?.view as PrivateMessageView | undefined; if (combinedView) { @@ -652,14 +652,14 @@ export class Inbox extends Component { } this.setState(this.state); } else if (op == UserOperation.MarkPrivateMessageAsRead) { - let data = wsJsonToRes(msg); - let found = this.state.messages.find( + const data = wsJsonToRes(msg); + const found = this.state.messages.find( m => m.private_message.id === data.private_message_view.private_message.id ); if (found) { - let combinedView = this.state.combined.find( + const combinedView = this.state.combined.find( i => i.id == data.private_message_view.private_message.id && i.type_ == ReplyEnum.Message @@ -700,18 +700,18 @@ export class Inbox extends Component { op == UserOperation.DeleteComment || op == UserOperation.RemoveComment ) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); editCommentRes(data.comment_view, this.state.replies); this.setState(this.state); } else if (op == UserOperation.MarkCommentReplyAsRead) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); - let found = this.state.replies.find( + const found = this.state.replies.find( c => c.comment_reply.id == data.comment_reply_view.comment_reply.id ); if (found) { - let combinedView = this.state.combined.find( + const combinedView = this.state.combined.find( i => i.id == data.comment_reply_view.comment_reply.id && i.type_ == ReplyEnum.Reply @@ -758,15 +758,15 @@ export class Inbox extends Component { this.sendUnreadCount(data.comment_reply_view.comment_reply.read); this.setState(this.state); } else if (op == UserOperation.MarkPersonMentionAsRead) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); // TODO this might not be correct, it might need to use the comment id - let found = this.state.mentions.find( + const found = this.state.mentions.find( c => c.person_mention.id == data.person_mention_view.person_mention.id ); if (found) { - let combinedView = this.state.combined.find( + const combinedView = this.state.combined.find( i => i.id == data.person_mention_view.person_mention.id && i.type_ == ReplyEnum.Mention @@ -814,8 +814,8 @@ export class Inbox extends Component { this.sendUnreadCount(data.person_mention_view.person_mention.read); this.setState(this.state); } else if (op == UserOperation.CreatePrivateMessage) { - let data = wsJsonToRes(msg); - let mui = UserService.Instance.myUserInfo; + const data = wsJsonToRes(msg); + const mui = UserService.Instance.myUserInfo; if ( data.private_message_view.recipient.id == mui?.local_user_view.person.id ) { @@ -826,29 +826,29 @@ export class Inbox extends Component { this.setState(this.state); } } else if (op == UserOperation.SaveComment) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); saveCommentRes(data.comment_view, this.state.replies); this.setState(this.state); setupTippy(); } else if (op == UserOperation.CreateCommentLike) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); createCommentLikeRes(data.comment_view, this.state.replies); this.setState(this.state); } else if (op == UserOperation.BlockPerson) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); updatePersonBlock(data); } else if (op == UserOperation.CreatePostReport) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if (data) { toast(i18n.t("report_created")); } } else if (op == UserOperation.CreateCommentReport) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if (data) { toast(i18n.t("report_created")); } } else if (op == UserOperation.CreatePrivateMessageReport) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if (data) { toast(i18n.t("report_created")); } diff --git a/src/shared/components/person/password-change.tsx b/src/shared/components/person/password-change.tsx index f3df971..743fef3 100644 --- a/src/shared/components/person/password-change.tsx +++ b/src/shared/components/person/password-change.tsx @@ -143,11 +143,11 @@ export class PasswordChange extends Component { event.preventDefault(); i.setState({ loading: true }); - let password = i.state.form.password; - let password_verify = i.state.form.password_verify; + const password = i.state.form.password; + const password_verify = i.state.form.password_verify; if (password && password_verify) { - let form: PasswordChangeAfterReset = { + const form: PasswordChangeAfterReset = { token: i.state.form.token, password, password_verify, @@ -158,14 +158,14 @@ export class PasswordChange extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); this.setState({ loading: false }); return; } else if (op == UserOperation.PasswordChangeAfterReset) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); UserService.Instance.login(data); this.props.history.push("/"); location.reload(); diff --git a/src/shared/components/person/person-details.tsx b/src/shared/components/person/person-details.tsx index d1ca4e3..650640a 100644 --- a/src/shared/components/person/person-details.tsx +++ b/src/shared/components/person/person-details.tsx @@ -87,7 +87,7 @@ export class PersonDetails extends Component { renderItemType(i: ItemType) { switch (i.type_) { case ItemEnum.Comment: { - let c = i.view as CommentView; + const c = i.view as CommentView; return ( { ); } case ItemEnum.Post: { - let p = i.view as PostView; + const p = i.view as PostView; return ( { overview() { let id = 0; - let comments: ItemType[] = this.props.personRes.comments.map(r => ({ + const comments: ItemType[] = this.props.personRes.comments.map(r => ({ id: id++, type_: ItemEnum.Comment, view: r, published: r.comment.published, score: r.counts.score, })); - let posts: ItemType[] = this.props.personRes.posts.map(r => ({ + const posts: ItemType[] = this.props.personRes.posts.map(r => ({ id: id++, type_: ItemEnum.Post, view: r, @@ -141,7 +141,7 @@ export class PersonDetails extends Component { score: r.counts.score, })); - let combined = [...comments, ...posts]; + const combined = [...comments, ...posts]; // Sort it if (this.props.sort === "New") { diff --git a/src/shared/components/person/person-listing.tsx b/src/shared/components/person/person-listing.tsx index f4121b3..1f0466b 100644 --- a/src/shared/components/person/person-listing.tsx +++ b/src/shared/components/person/person-listing.tsx @@ -20,15 +20,15 @@ export class PersonListing extends Component { } render() { - let person = this.props.person; - let local = person.local; + const person = this.props.person; + const local = person.local; let apubName: string, link: string; if (local) { apubName = `@${person.name}`; link = `/u/${person.name}`; } else { - let domain = hostname(person.actor_id); + const domain = hostname(person.actor_id); apubName = `@${person.name}@${domain}`; link = !this.props.realLink ? `/u/${person.name}@${domain}` @@ -70,7 +70,7 @@ export class PersonListing extends Component { } avatarAndName(displayName: string) { - let avatar = this.props.person.avatar; + const avatar = this.props.person.avatar; return ( <> {avatar && diff --git a/src/shared/components/person/registration-applications.tsx b/src/shared/components/person/registration-applications.tsx index 39b6590..b4318e1 100644 --- a/src/shared/components/person/registration-applications.tsx +++ b/src/shared/components/person/registration-applications.tsx @@ -86,7 +86,7 @@ export class RegistrationApplications extends Component< } get documentTitle(): string { - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; return mui ? `@${mui.local_user_view.person.name} ${i18n.t( "registration_applications" @@ -164,7 +164,7 @@ export class RegistrationApplications extends Component< } applicationList() { - let res = this.state.listRegistrationApplicationsResponse; + const res = this.state.listRegistrationApplicationsResponse; return ( res && (
        @@ -193,11 +193,11 @@ export class RegistrationApplications extends Component< } static fetchInitialData(req: InitialFetchRequest): Promise[] { - let promises: Promise[] = []; + const promises: Promise[] = []; - let auth = req.auth; + const auth = req.auth; if (auth) { - let form: ListRegistrationApplications = { + const form: ListRegistrationApplications = { unread_only: true, page: 1, limit: fetchLimit, @@ -210,10 +210,10 @@ export class RegistrationApplications extends Component< } refetch() { - let unread_only = this.state.unreadOrAll == UnreadOrAll.Unread; - let auth = myAuth(); + const unread_only = this.state.unreadOrAll == UnreadOrAll.Unread; + const auth = myAuth(); if (auth) { - let form: ListRegistrationApplications = { + const form: ListRegistrationApplications = { unread_only: unread_only, page: this.state.page, limit: fetchLimit, @@ -226,7 +226,7 @@ export class RegistrationApplications extends Component< } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); @@ -234,20 +234,20 @@ export class RegistrationApplications extends Component< } else if (msg.reconnect) { this.refetch(); } else if (op == UserOperation.ListRegistrationApplications) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ listRegistrationApplicationsResponse: data, loading: false, }); window.scrollTo(0, 0); } else if (op == UserOperation.ApproveRegistrationApplication) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); updateRegistrationApplicationRes( data.registration_application, this.state.listRegistrationApplicationsResponse ?.registration_applications ); - let uacs = UserService.Instance.unreadApplicationCountSub; + const uacs = UserService.Instance.unreadApplicationCountSub; // Minor bug, where if the application switches from deny to approve, the count will still go down uacs.next(uacs.getValue() - 1); this.setState(this.state); diff --git a/src/shared/components/person/reports.tsx b/src/shared/components/person/reports.tsx index 3c00f54..888b2cd 100644 --- a/src/shared/components/person/reports.tsx +++ b/src/shared/components/person/reports.tsx @@ -132,7 +132,7 @@ export class Reports extends Component { } get documentTitle(): string { - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; return mui ? `@${mui.local_user_view.person.name} ${i18n.t("reports")} - ${ this.state.siteRes.site_view.site.name @@ -314,15 +314,15 @@ export class Reports extends Component { // .map(r => r.comment_reports) // .unwrapOr([]) // .map(r => this.commentReportToItemType(r)); - let comments = + const comments = this.state.listCommentReportsResponse?.comment_reports.map( this.commentReportToItemType ) ?? []; - let posts = + const posts = this.state.listPostReportsResponse?.post_reports.map( this.postReportToItemType ) ?? []; - let privateMessages = + const privateMessages = this.state.listPrivateMessageReportsResponse?.private_message_reports.map( this.privateMessageReportToItemType ) ?? []; @@ -366,7 +366,7 @@ export class Reports extends Component { } commentReports() { - let reports = this.state.listCommentReportsResponse?.comment_reports; + const reports = this.state.listCommentReportsResponse?.comment_reports; return ( reports && (
        @@ -382,7 +382,7 @@ export class Reports extends Component { } postReports() { - let reports = this.state.listPostReportsResponse?.post_reports; + const reports = this.state.listPostReportsResponse?.post_reports; return ( reports && (
        @@ -398,7 +398,7 @@ export class Reports extends Component { } privateMessageReports() { - let reports = + const reports = this.state.listPrivateMessageReportsResponse?.private_message_reports; return ( reports && ( @@ -433,15 +433,15 @@ export class Reports extends Component { } static fetchInitialData(req: InitialFetchRequest): Promise[] { - let promises: Promise[] = []; + const promises: Promise[] = []; - let unresolved_only = true; - let page = 1; - let limit = fetchLimit; - let auth = req.auth; + const unresolved_only = true; + const page = 1; + const limit = fetchLimit; + const auth = req.auth; if (auth) { - let commentReportsForm: ListCommentReports = { + const commentReportsForm: ListCommentReports = { unresolved_only, page, limit, @@ -449,7 +449,7 @@ export class Reports extends Component { }; promises.push(req.client.listCommentReports(commentReportsForm)); - let postReportsForm: ListPostReports = { + const postReportsForm: ListPostReports = { unresolved_only, page, limit, @@ -458,7 +458,7 @@ export class Reports extends Component { promises.push(req.client.listPostReports(postReportsForm)); if (amAdmin()) { - let privateMessageReportsForm: ListPrivateMessageReports = { + const privateMessageReportsForm: ListPrivateMessageReports = { unresolved_only, page, limit, @@ -474,12 +474,12 @@ export class Reports extends Component { } refetch() { - let unresolved_only = this.state.unreadOrAll == UnreadOrAll.Unread; - let page = this.state.page; - let limit = fetchLimit; - let auth = myAuth(); + const unresolved_only = this.state.unreadOrAll == UnreadOrAll.Unread; + const page = this.state.page; + const limit = fetchLimit; + const auth = myAuth(); if (auth) { - let commentReportsForm: ListCommentReports = { + const commentReportsForm: ListCommentReports = { unresolved_only, page, limit, @@ -489,7 +489,7 @@ export class Reports extends Component { wsClient.listCommentReports(commentReportsForm) ); - let postReportsForm: ListPostReports = { + const postReportsForm: ListPostReports = { unresolved_only, page, limit, @@ -498,7 +498,7 @@ export class Reports extends Component { WebSocketService.Instance.send(wsClient.listPostReports(postReportsForm)); if (amAdmin()) { - let privateMessageReportsForm: ListPrivateMessageReports = { + const privateMessageReportsForm: ListPrivateMessageReports = { unresolved_only, page, limit, @@ -512,7 +512,7 @@ export class Reports extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); @@ -520,33 +520,33 @@ export class Reports extends Component { } else if (msg.reconnect) { this.refetch(); } else if (op == UserOperation.ListCommentReports) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ listCommentReportsResponse: data }); this.setState({ combined: this.buildCombined(), loading: false }); // this.sendUnreadCount(); window.scrollTo(0, 0); setupTippy(); } else if (op == UserOperation.ListPostReports) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ listPostReportsResponse: data }); this.setState({ combined: this.buildCombined(), loading: false }); // this.sendUnreadCount(); window.scrollTo(0, 0); setupTippy(); } else if (op == UserOperation.ListPrivateMessageReports) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); this.setState({ listPrivateMessageReportsResponse: data }); this.setState({ combined: this.buildCombined(), loading: false }); // this.sendUnreadCount(); window.scrollTo(0, 0); setupTippy(); } else if (op == UserOperation.ResolvePostReport) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); updatePostReportRes( data.post_report_view, this.state.listPostReportsResponse?.post_reports ); - let urcs = UserService.Instance.unreadReportCountSub; + const urcs = UserService.Instance.unreadReportCountSub; if (data.post_report_view.post_report.resolved) { urcs.next(urcs.getValue() - 1); } else { @@ -554,12 +554,12 @@ export class Reports extends Component { } this.setState(this.state); } else if (op == UserOperation.ResolveCommentReport) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); updateCommentReportRes( data.comment_report_view, this.state.listCommentReportsResponse?.comment_reports ); - let urcs = UserService.Instance.unreadReportCountSub; + const urcs = UserService.Instance.unreadReportCountSub; if (data.comment_report_view.comment_report.resolved) { urcs.next(urcs.getValue() - 1); } else { @@ -567,12 +567,12 @@ export class Reports extends Component { } this.setState(this.state); } else if (op == UserOperation.ResolvePrivateMessageReport) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); updatePrivateMessageReportRes( data.private_message_report_view, this.state.listPrivateMessageReportsResponse?.private_message_reports ); - let urcs = UserService.Instance.unreadReportCountSub; + const urcs = UserService.Instance.unreadReportCountSub; if (data.private_message_report_view.private_message_report.resolved) { urcs.next(urcs.getValue() - 1); } else { diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index a335d21..a40b904 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -476,7 +476,7 @@ export class Settings extends Component { } saveUserSettingsHtmlForm() { - let selectedLangs = this.state.saveUserSettingsForm.discussion_languages; + const selectedLangs = this.state.saveUserSettingsForm.discussion_languages; return ( <> @@ -853,7 +853,7 @@ export class Settings extends Component { } totpSection() { - let totpUrl = + const totpUrl = UserService.Instance.myUserInfo?.local_user_view.local_user.totp_2fa_url; return ( @@ -998,7 +998,7 @@ export class Settings extends Component { handleShowAvatarsChange(i: Settings, event: any) { i.state.saveUserSettingsForm.show_avatars = event.target.checked; - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; if (mui) { mui.local_user_view.local_user.show_avatars = event.target.checked; } @@ -1027,7 +1027,7 @@ export class Settings extends Component { handleShowScoresChange(i: Settings, event: any) { i.state.saveUserSettingsForm.show_scores = event.target.checked; - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; if (mui) { mui.local_user_view.local_user.show_scores = event.target.checked; } @@ -1036,7 +1036,7 @@ export class Settings extends Component { handleGenerateTotp(i: Settings, event: any) { // Coerce false to undefined here, so it won't generate it. - let checked: boolean | undefined = event.target.checked || undefined; + const checked: boolean | undefined = event.target.checked || undefined; if (checked) { toast(i18n.t("two_factor_setup_instructions")); } @@ -1046,7 +1046,7 @@ export class Settings extends Component { handleRemoveTotp(i: Settings, event: any) { // Coerce true to undefined here, so it won't generate it. - let checked: boolean | undefined = !event.target.checked && undefined; + const checked: boolean | undefined = !event.target.checked && undefined; i.state.saveUserSettingsForm.generate_totp_2fa = checked; i.setState(i.state); } @@ -1149,9 +1149,9 @@ export class Settings extends Component { handleSaveSettingsSubmit(i: Settings, event: any) { event.preventDefault(); i.setState({ saveUserSettingsLoading: true }); - let auth = myAuth(); + const auth = myAuth(); if (auth) { - let form: SaveUserSettings = { ...i.state.saveUserSettingsForm, auth }; + const form: SaveUserSettings = { ...i.state.saveUserSettingsForm, auth }; WebSocketService.Instance.send(wsClient.saveUserSettings(form)); } } @@ -1159,13 +1159,13 @@ export class Settings extends Component { handleChangePasswordSubmit(i: Settings, event: any) { event.preventDefault(); i.setState({ changePasswordLoading: true }); - let auth = myAuth(); - let pForm = i.state.changePasswordForm; - let new_password = pForm.new_password; - let new_password_verify = pForm.new_password_verify; - let old_password = pForm.old_password; + const auth = myAuth(); + const pForm = i.state.changePasswordForm; + const new_password = pForm.new_password; + const new_password_verify = pForm.new_password_verify; + const old_password = pForm.old_password; if (auth && new_password && old_password && new_password_verify) { - let form: ChangePassword = { + const form: ChangePassword = { new_password, new_password_verify, old_password, @@ -1189,10 +1189,10 @@ export class Settings extends Component { handleDeleteAccount(i: Settings, event: any) { event.preventDefault(); i.setState({ deleteAccountLoading: true }); - let auth = myAuth(); - let password = i.state.deleteAccountForm.password; + const auth = myAuth(); + const password = i.state.deleteAccountForm.password; if (auth && password) { - let form: DeleteAccount = { + const form: DeleteAccount = { password, auth, }; @@ -1205,7 +1205,7 @@ export class Settings extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { this.setState({ @@ -1220,7 +1220,7 @@ export class Settings extends Component { toast(i18n.t("saved")); window.scrollTo(0, 0); } else if (op == UserOperation.ChangePassword) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); UserService.Instance.login(data); this.setState({ changePasswordLoading: false }); window.scrollTo(0, 0); @@ -1233,16 +1233,16 @@ export class Settings extends Component { UserService.Instance.logout(); window.location.href = "/"; } else if (op == UserOperation.BlockPerson) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); updatePersonBlock(data); - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; if (mui) { this.setState({ personBlocks: mui.person_blocks }); } } else if (op == UserOperation.BlockCommunity) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); updateCommunityBlock(data); - let mui = UserService.Instance.myUserInfo; + const mui = UserService.Instance.myUserInfo; if (mui) { this.setState({ communityBlocks: mui.community_blocks }); } diff --git a/src/shared/components/person/verify-email.tsx b/src/shared/components/person/verify-email.tsx index 61261bb..fdc8210 100644 --- a/src/shared/components/person/verify-email.tsx +++ b/src/shared/components/person/verify-email.tsx @@ -76,7 +76,7 @@ export class VerifyEmail extends Component { } parseMessage(msg: any) { - let op = wsUserOp(msg); + const op = wsUserOp(msg); console.log(msg); if (msg.error) { toast(i18n.t(msg.error), "danger"); @@ -84,7 +84,7 @@ export class VerifyEmail extends Component { this.props.history.push("/"); return; } else if (op == UserOperation.VerifyEmail) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if (data) { toast(i18n.t("email_verified")); this.props.history.push("/login"); diff --git a/src/shared/components/post/metadata-card.tsx b/src/shared/components/post/metadata-card.tsx index 74a4ba6..c57ecd5 100644 --- a/src/shared/components/post/metadata-card.tsx +++ b/src/shared/components/post/metadata-card.tsx @@ -26,7 +26,7 @@ export class MetadataCard extends Component< } render() { - let post = this.props.post; + const post = this.props.post; return ( <> {!this.state.expanded && post.embed_title && post.url && ( diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 18fcee7..9f43d69 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -186,10 +186,10 @@ export class PostForm extends Component { } render() { - let firstLang = this.state.form.language_id; - let selectedLangs = firstLang ? Array.of(firstLang) : undefined; + const firstLang = this.state.form.language_id; + const selectedLangs = firstLang ? Array.of(firstLang) : undefined; - let url = this.state.form.url; + const url = this.state.form.url; return (
        { i.setState(s => ((s.form.url = undefined), s)); } - let pForm = i.state.form; - let pv = i.props.post_view; - let auth = myAuth(); + const pForm = i.state.form; + const pv = i.props.post_view; + const auth = myAuth(); if (auth) { if (pv) { - let form: EditPost = { + const form: EditPost = { name: pForm.name, url: pForm.url, body: pForm.body, @@ -466,7 +466,7 @@ export class PostForm extends Component { WebSocketService.Instance.send(wsClient.editPost(form)); } else { if (pForm.name && pForm.community_id) { - let form: CreatePost = { + const form: CreatePost = { name: pForm.name, community_id: pForm.community_id, url: pForm.url, @@ -483,14 +483,14 @@ export class PostForm extends Component { } copySuggestedTitle(i: PostForm) { - let sTitle = i.state.suggestedTitle; + const sTitle = i.state.suggestedTitle; if (sTitle) { i.setState( s => ((s.form.name = sTitle?.substring(0, MAX_POST_TITLE_LENGTH)), s) ); i.setState({ suggestedTitle: undefined }); setTimeout(() => { - let textarea: any = document.getElementById("post-title"); + const textarea: any = document.getElementById("post-title"); autosize.update(textarea); }, 10); } @@ -502,9 +502,9 @@ export class PostForm extends Component { } fetchPageTitle() { - let url = this.state.form.url; + const url = this.state.form.url; if (url && validURL(url)) { - let form: Search = { + const form: Search = { q: url, type_: "Url", sort: "TopAll", @@ -531,9 +531,9 @@ export class PostForm extends Component { } fetchSimilarPosts() { - let q = this.state.form.name; + const q = this.state.form.name; if (q && q !== "") { - let form: Search = { + const form: Search = { q, type_: "Posts", sort: "TopAll", @@ -580,7 +580,7 @@ export class PostForm extends Component { } handleImageUploadPaste(i: PostForm, event: any) { - let image = event.clipboardData.files[0]; + const image = event.clipboardData.files[0]; if (image) { i.handleImageUpload(i, image); } @@ -649,8 +649,8 @@ export class PostForm extends Component { } parseMessage(msg: any) { - let mui = UserService.Instance.myUserInfo; - let op = wsUserOp(msg); + const mui = UserService.Instance.myUserInfo; + const op = wsUserOp(msg); console.log(msg); if (msg.error) { // Errors handled by top level pages @@ -658,18 +658,18 @@ export class PostForm extends Component { this.setState({ loading: false }); return; } else if (op == UserOperation.CreatePost) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if (data.post_view.creator.id == mui?.local_user_view.person.id) { this.props.onCreate?.(data.post_view); } } else if (op == UserOperation.EditPost) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if (data.post_view.creator.id == mui?.local_user_view.person.id) { this.setState({ loading: false }); this.props.onEdit?.(data.post_view); } } else if (op == UserOperation.Search) { - let data = wsJsonToRes(msg); + const data = wsJsonToRes(msg); if (data.type_ == "Posts") { this.setState({ suggestedPosts: data.posts }); diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 5ede0ed..5ba5313 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -179,7 +179,7 @@ export class PostListing extends Component { } body() { - let body = this.props.post_view.post.body; + const body = this.props.post_view.post.body; return body ? (
        {this.state.viewSource ? ( @@ -194,7 +194,7 @@ export class PostListing extends Component { } get img() { - let src = this.imageSrc; + const src = this.imageSrc; return src ? ( <>
        @@ -217,7 +217,7 @@ export class PostListing extends Component { } imgThumb(src: string) { - let post_view = this.props.post_view; + const post_view = this.props.post_view; return ( { } get imageSrc(): string | undefined { - let post = this.props.post_view.post; - let url = post.url; - let thumbnail = post.thumbnail_url; + const post = this.props.post_view.post; + const url = post.url; + const thumbnail = post.thumbnail_url; if (url && isImage(url)) { if (url.includes("pictrs")) { @@ -249,9 +249,9 @@ export class PostListing extends Component { } thumbnail() { - let post = this.props.post_view.post; - let url = post.url; - let thumbnail = post.thumbnail_url; + const post = this.props.post_view.post; + const url = post.url; + const thumbnail = post.thumbnail_url; if (!this.props.hideImage && url && isImage(url) && this.imageSrc) { return ( @@ -318,9 +318,9 @@ export class PostListing extends Component { } createdLine() { - let post_view = this.props.post_view; - let url = post_view.post.url; - let body = post_view.post.body; + const post_view = this.props.post_view; + const url = post_view.post.url; + const body = post_view.post.body; return (
        • @@ -438,7 +438,7 @@ export class PostListing extends Component { } get postLink() { - let post = this.props.post_view.post; + const post = this.props.post_view.post; return ( { } postTitleLine() { - let post = this.props.post_view.post; - let url = post.url; + const post = this.props.post_view.post; + const url = post.url; return (
          @@ -550,7 +550,7 @@ export class PostListing extends Component { } duplicatesLine() { - let dupes = this.props.duplicates; + const dupes = this.props.duplicates; return dupes && dupes.length > 0 ? (
            <> @@ -572,7 +572,7 @@ export class PostListing extends Component { } commentsLine(mobile = false) { - let post = this.props.post_view.post; + const post = this.props.post_view.post; return (
            @@ -606,7 +606,7 @@ export class PostListing extends Component { postActions(mobile = false) { // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button. // Possible enhancement: Make each button a component. - let post_view = this.props.post_view; + const post_view = this.props.post_view; return ( <> {this.saveButton} @@ -647,7 +647,7 @@ export class PostListing extends Component { } get commentsButton() { - let post_view = this.props.post_view; + const post_view = this.props.post_view; return (