Refactor lets to consts

This commit is contained in:
James Whitmarsh 2023-06-05 22:31:12 +01:00
parent 400e62b21c
commit 0754b9ba19
50 changed files with 734 additions and 727 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -80,7 +80,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
// 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<NavbarProps, NavbarState> {
}
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<NavbarProps, NavbarState> {
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<NavbarProps, NavbarState> {
this.fetchUnreads();
}
} else if (op == UserOperation.GetUnreadCount) {
let data = wsJsonToRes<GetUnreadCountResponse>(msg);
const data = wsJsonToRes<GetUnreadCountResponse>(msg);
this.setState({
unreadInboxCount: data.replies + data.mentions + data.private_messages,
});
this.sendUnreadCount();
} else if (op == UserOperation.GetReportCount) {
let data = wsJsonToRes<GetReportCountResponse>(msg);
const data = wsJsonToRes<GetReportCountResponse>(msg);
this.setState({
unreadReportCount:
data.post_reports +
@ -478,13 +478,13 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
});
this.sendReportUnread();
} else if (op == UserOperation.GetUnreadRegistrationApplicationCount) {
let data =
const data =
wsJsonToRes<GetUnreadRegistrationApplicationCountResponse>(msg);
this.setState({ unreadApplicationCount: data.registration_applications });
this.sendApplicationUnread();
} else if (op == UserOperation.CreateComment) {
let data = wsJsonToRes<CommentResponse>(msg);
let mui = UserService.Instance.myUserInfo;
const data = wsJsonToRes<CommentResponse>(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<NavbarProps, NavbarState> {
notifyComment(data.comment_view, this.context.router);
}
} else if (op == UserOperation.CreatePrivateMessage) {
let data = wsJsonToRes<PrivateMessageResponse>(msg);
const data = wsJsonToRes<PrivateMessageResponse>(msg);
if (
data.private_message_view.recipient.id ==
@ -514,16 +514,16 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
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<NavbarProps, NavbarState> {
if (amAdmin()) {
console.log("Fetching applications...");
let applicationCountForm: GetUnreadRegistrationApplicationCount = {
const applicationCountForm: GetUnreadRegistrationApplicationCount = {
auth,
};
WebSocketService.Instance.send(

View file

@ -8,8 +8,8 @@ interface Props {
export class Theme extends Component<Props> {
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 (

View file

@ -69,7 +69,7 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
}
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<CommentFormProps, CommentFormState> {
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<CommentFormProps, CommentFormState> {
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<CommentFormProps, CommentFormState> {
};
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<CommentFormProps, CommentFormState> {
}
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<CommentFormProps, CommentFormState> {
op == UserOperation.CreateComment ||
op == UserOperation.EditComment
) {
let data = wsJsonToRes<CommentResponse>(msg);
const data = wsJsonToRes<CommentResponse>(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) {

View file

@ -147,7 +147,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
// 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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
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<CommentNodeProps, CommentNodeState> {
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<CommentNodeProps, CommentNodeState> {
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<CommentNodeProps, CommentNodeState> {
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
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<CommentNodeProps, CommentNodeState> {
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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<CommentNodeProps, CommentNodeState> {
}
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),
});

View file

@ -28,7 +28,7 @@ export class CommentNodes extends Component<CommentNodesProps, any> {
}
render() {
let maxComments = this.props.maxCommentsShown ?? this.props.nodes.length;
const maxComments = this.props.maxCommentsShown ?? this.props.nodes.length;
return (
<div className="comments">

View file

@ -23,16 +23,16 @@ export class CommentReport extends Component<CommentReportProps, any> {
}
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<CommentReportProps, any> {
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<CommentReportProps, any> {
}
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,

View file

@ -12,8 +12,8 @@ export class BannerIconHeader extends Component<BannerIconHeaderProps, any> {
}
render() {
let banner = this.props.banner;
let icon = this.props.icon;
const banner = this.props.banner;
const icon = this.props.icon;
return (
<div className="position-relative mb-2">
{banner && <PictrsImage src={banner} banner alt="" />}

View file

@ -12,7 +12,7 @@ export class EmojiMart extends Component<EmojiMartProps> {
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)

View file

@ -14,9 +14,9 @@ interface HtmlTagsProps {
/// Taken from https://metatags.io/
export class HtmlTags extends Component<HtmlTagsProps, any> {
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 (
<Helmet title={this.props.title}>

View file

@ -31,12 +31,12 @@ export class LanguageSelect extends Component<LanguageSelectProps, any> {
// 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<LanguageSelectProps, any> {
}
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));

View file

@ -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 (
<form id={this.formId} onSubmit={linkEvent(this, this.handleSubmit)}>
@ -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);
}

View file

@ -15,13 +15,13 @@ export class MomentTime extends Component<MomentTimeProps, any> {
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<MomentTimeProps, any> {
</span>
);
} else {
let published = this.props.published;
const published = this.props.published;
return (
<span
className="pointer unselectable"

View file

@ -51,17 +51,17 @@ export class PictrsImage extends Component<PictrsImageProps, any> {
// 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<PictrsImageProps, any> {
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;
}

View file

@ -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 (
<div>
@ -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,

View file

@ -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<CommunityResponse>(msg);
const data = wsJsonToRes<CommunityResponse>(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<CommunityResponse>(msg);
const data = wsJsonToRes<CommunityResponse>(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) {

View file

@ -18,22 +18,22 @@ export class CommunityLink extends Component<CommunityLinkProps, any> {
}
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 ? (
<Link
title={apubName}
@ -55,7 +55,7 @@ export class CommunityLink extends Component<CommunityLinkProps, any> {
}
avatarAndName(displayName: string) {
let icon = this.props.community.icon;
const icon = this.props.community.icon;
return (
<>
{!this.props.hideAvatar &&

View file

@ -124,8 +124,8 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
}
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 (
<div>
<h5 className="mb-0">
@ -178,8 +178,8 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
}
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 (
<ul className="my-1 list-inline">
<li className="list-inline-item badge badge-secondary">
@ -284,7 +284,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
}
createPost() {
let cv = this.props.community_view;
const cv = this.props.community_view;
return (
<Link
className={`btn btn-secondary btn-block mb-2 ${
@ -298,7 +298,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
}
subscribe() {
let community_view = this.props.community_view;
const community_view = this.props.community_view;
return (
<div className="mb-2">
{community_view.subscribed == "NotSubscribed" && (
@ -314,8 +314,8 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
}
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 (
<div className="mb-2">
@ -340,7 +340,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
}
description() {
let desc = this.props.community_view.community.description;
const desc = this.props.community_view.community.description;
return (
desc && (
<div className="md-div" dangerouslySetInnerHTML={mdToHtml(desc)} />
@ -349,7 +349,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
}
adminButtons() {
let community_view = this.props.community_view;
const community_view = this.props.community_view;
return (
<>
<ul className="list-inline mb-1 text-muted font-weight-bold">
@ -536,9 +536,9 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
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<SidebarProps, SidebarState> {
}
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<SidebarProps, SidebarState> {
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<SidebarProps, SidebarState> {
}
// 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<SidebarProps, SidebarState> {
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<SidebarProps, SidebarState> {
}
// 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<SidebarProps, SidebarState> {
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<SidebarProps, SidebarState> {
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<SidebarProps, SidebarState> {
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<SidebarProps, SidebarState> {
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,

View file

@ -70,7 +70,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
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<any, AdminSettingsState> {
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
let promises: Promise<any>[] = [];
const promises: Promise<any>[] = [];
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<any, AdminSettingsState> {
}
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<any, AdminSettingsState> {
}
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<any, AdminSettingsState> {
this.setState({ loading: false });
return;
} else if (op == UserOperation.EditSite) {
let data = wsJsonToRes<SiteResponse>(msg);
const data = wsJsonToRes<SiteResponse>(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<BannedPersonsResponse>(msg);
const data = wsJsonToRes<BannedPersonsResponse>(msg);
this.setState({ banned: data.banned, loading: false });
} else if (op == UserOperation.LeaveAdmin) {
let data = wsJsonToRes<GetSiteResponse>(msg);
const data = wsJsonToRes<GetSiteResponse>(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<GetFederatedInstancesResponse>(msg);
const data = wsJsonToRes<GetFederatedInstancesResponse>(msg);
this.setState({ instancesRes: data });
}
}

View file

@ -325,10 +325,10 @@ export class EmojiForm extends Component<any, EmojiFormState> {
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<any, EmojiFormState> {
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<any, EmojiFormState> {
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<any, EmojiFormState> {
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<any, EmojiFormState> {
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<any, EmojiFormState> {
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<any, EmojiFormState> {
};
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<any, EmojiFormState> {
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<any, EmojiFormState> {
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<any, EmojiFormState> {
}
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<any, EmojiFormState> {
this.setState({ loading: false });
return;
} else if (op == UserOperation.CreateCustomEmoji) {
let data = wsJsonToRes<CustomEmojiResponse>(msg);
const data = wsJsonToRes<CustomEmojiResponse>(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<any, EmojiFormState> {
toast(i18n.t("saved_emoji"));
this.setState({ loading: false });
} else if (op == UserOperation.EditCustomEmoji) {
let data = wsJsonToRes<CustomEmojiResponse>(msg);
const data = wsJsonToRes<CustomEmojiResponse>(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<any, EmojiFormState> {
toast(i18n.t("saved_emoji"));
this.setState({ loading: false });
} else if (op == UserOperation.DeleteCustomEmoji) {
let data = wsJsonToRes<DeleteCustomEmojiResponse>(msg);
const data = wsJsonToRes<DeleteCustomEmojiResponse>(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 });

View file

@ -55,7 +55,7 @@ export class Instances extends Component<any, InstancesState> {
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
let promises: Promise<any>[] = [];
const promises: Promise<any>[] = [];
promises.push(req.client.getFederatedInstances({}));
@ -73,7 +73,7 @@ export class Instances extends Component<any, InstancesState> {
}
render() {
let federated_instances = this.state.instancesRes?.federated_instances;
const federated_instances = this.state.instancesRes?.federated_instances;
return federated_instances ? (
<div className="container-lg">
<HtmlTags
@ -137,7 +137,7 @@ export class Instances extends Component<any, InstancesState> {
);
}
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<any, InstancesState> {
this.setState({ loading: false });
return;
} else if (op == UserOperation.GetFederatedInstances) {
let data = wsJsonToRes<GetFederatedInstancesResponse>(msg);
const data = wsJsonToRes<GetFederatedInstancesResponse>(msg);
this.setState({ loading: false, instancesRes: data });
}
}

View file

@ -23,7 +23,7 @@ export class Legal extends Component<any, LegalState> {
}
render() {
let legal = this.state.siteRes.site_view.local_site.legal_information;
const legal = this.state.siteRes.site_view.local_site.legal_information;
return (
<div className="container-lg">
<HtmlTags

View file

@ -181,12 +181,12 @@ export class Login extends Component<any, State> {
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<any, State> {
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<any, State> {
}
} else {
if (op == UserOperation.Login) {
let data = wsJsonToRes<LoginResponse>(msg);
const data = wsJsonToRes<LoginResponse>(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<GetSiteResponse>(msg);
const data = wsJsonToRes<GetSiteResponse>(msg);
this.setState({ siteRes: data });
}
}

View file

@ -173,9 +173,9 @@ export class Setup extends Component<any, State> {
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<any, State> {
}
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<LoginResponse>(msg);
const data = wsJsonToRes<LoginResponse>(msg);
this.setState({ userLoading: false });
UserService.Instance.login(data);
if (UserService.Instance.jwtInfo) {

View file

@ -109,7 +109,7 @@ export class Signup extends Component<any, State> {
}
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<any, State> {
}
registerForm() {
let siteView = this.state.siteRes.site_view;
const siteView = this.state.siteRes.site_view;
return (
<form onSubmit={linkEvent(this, this.handleRegisterSubmit)}>
<h5>{this.titleName(siteView)}</h5>
@ -371,7 +371,7 @@ export class Signup extends Component<any, State> {
}
showCaptcha() {
let captchaRes = this.state.captcha?.ok;
const captchaRes = this.state.captcha?.ok;
return captchaRes ? (
<div className="col-sm-4">
<>
@ -401,14 +401,14 @@ export class Signup extends Component<any, State> {
}
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<any, State> {
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<any, State> {
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<any, State> {
}
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<any, State> {
return;
} else {
if (op == UserOperation.Register) {
let data = wsJsonToRes<LoginResponse>(msg);
const data = wsJsonToRes<LoginResponse>(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<any, State> {
this.props.history.push("/");
}
} else if (op == UserOperation.GetCaptcha) {
let data = wsJsonToRes<GetCaptchaResponse>(msg);
const data = wsJsonToRes<GetCaptchaResponse>(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<any, State> {
} else if (op == UserOperation.PasswordReset) {
toast(i18n.t("reset_password_mail_sent"));
} else if (op == UserOperation.GetSite) {
let data = wsJsonToRes<GetSiteResponse>(msg);
const data = wsJsonToRes<GetSiteResponse>(msg);
this.setState({ siteRes: data });
}
}

View file

@ -76,8 +76,8 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
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<SiteFormProps, SiteFormState> {
}
render() {
let siteSetup = this.props.siteRes.site_view.local_site.site_setup;
const siteSetup = this.props.siteRes.site_view.local_site.site_setup;
return (
<>
<Prompt
@ -747,13 +747,13 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
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<SiteFormProps, SiteFormState> {
}
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<SiteFormProps, SiteFormState> {
event: InfernoMouseEvent<HTMLButtonElement>
) {
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;

View file

@ -67,7 +67,7 @@ export class SiteSidebar extends Component<SiteSidebarProps, SiteSidebarState> {
}
siteInfo() {
let site = this.props.site;
const site = this.props.site;
return (
<div>
{site.description && <h6>{site.description}</h6>}
@ -98,8 +98,8 @@ export class SiteSidebar extends Component<SiteSidebarProps, SiteSidebarState> {
}
badges(siteAggregates: SiteAggregates) {
let counts = siteAggregates;
let online = this.props.online ?? 1;
const counts = siteAggregates;
const online = this.props.online ?? 1;
return (
<ul className="my-2 list-inline">
<li className="list-inline-item badge badge-secondary">

View file

@ -131,7 +131,7 @@ export class TaglineForm extends Component<TaglineFormProps, TaglineFormState> {
}
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<TaglineFormProps, TaglineFormState> {
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<TaglineFormProps, TaglineFormState> {
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 });

View file

@ -141,7 +141,7 @@ export class Inbox extends Component<any, InboxState> {
}
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<any, InboxState> {
}
render() {
let auth = myAuth();
let inboxRss = auth ? `/feeds/inbox/${auth}.xml` : undefined;
const auth = myAuth();
const inboxRss = auth ? `/feeds/inbox/${auth}.xml` : undefined;
return (
<div className="container-lg">
{this.state.loading ? (
@ -343,13 +343,13 @@ export class Inbox extends Component<any, InboxState> {
}
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<any, InboxState> {
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
let promises: Promise<any>[] = [];
const promises: Promise<any>[] = [];
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<any, InboxState> {
};
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<any, InboxState> {
};
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<any, InboxState> {
}
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<any, InboxState> {
};
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<any, InboxState> {
wsClient.getPersonMentions(personMentionsForm)
);
let privateMessagesForm: GetPrivateMessages = {
const privateMessagesForm: GetPrivateMessages = {
unread_only,
page,
limit,
@ -565,7 +565,7 @@ export class Inbox extends Component<any, InboxState> {
}
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<any, InboxState> {
}
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<any, InboxState> {
}
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<any, InboxState> {
} else if (msg.reconnect) {
this.refetch();
} else if (op == UserOperation.GetReplies) {
let data = wsJsonToRes<GetRepliesResponse>(msg);
const data = wsJsonToRes<GetRepliesResponse>(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<GetPersonMentionsResponse>(msg);
const data = wsJsonToRes<GetPersonMentionsResponse>(msg);
this.setState({ mentions: data.mentions });
this.setState({ combined: this.buildCombined() });
window.scrollTo(0, 0);
setupTippy();
} else if (op == UserOperation.GetPrivateMessages) {
let data = wsJsonToRes<PrivateMessagesResponse>(msg);
const data = wsJsonToRes<PrivateMessagesResponse>(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<PrivateMessageResponse>(msg);
let found = this.state.messages.find(
const data = wsJsonToRes<PrivateMessageResponse>(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<any, InboxState> {
}
this.setState(this.state);
} else if (op == UserOperation.DeletePrivateMessage) {
let data = wsJsonToRes<PrivateMessageResponse>(msg);
let found = this.state.messages.find(
const data = wsJsonToRes<PrivateMessageResponse>(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<any, InboxState> {
}
this.setState(this.state);
} else if (op == UserOperation.MarkPrivateMessageAsRead) {
let data = wsJsonToRes<PrivateMessageResponse>(msg);
let found = this.state.messages.find(
const data = wsJsonToRes<PrivateMessageResponse>(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<any, InboxState> {
op == UserOperation.DeleteComment ||
op == UserOperation.RemoveComment
) {
let data = wsJsonToRes<CommentResponse>(msg);
const data = wsJsonToRes<CommentResponse>(msg);
editCommentRes(data.comment_view, this.state.replies);
this.setState(this.state);
} else if (op == UserOperation.MarkCommentReplyAsRead) {
let data = wsJsonToRes<CommentReplyResponse>(msg);
const data = wsJsonToRes<CommentReplyResponse>(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<any, InboxState> {
this.sendUnreadCount(data.comment_reply_view.comment_reply.read);
this.setState(this.state);
} else if (op == UserOperation.MarkPersonMentionAsRead) {
let data = wsJsonToRes<PersonMentionResponse>(msg);
const data = wsJsonToRes<PersonMentionResponse>(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<any, InboxState> {
this.sendUnreadCount(data.person_mention_view.person_mention.read);
this.setState(this.state);
} else if (op == UserOperation.CreatePrivateMessage) {
let data = wsJsonToRes<PrivateMessageResponse>(msg);
let mui = UserService.Instance.myUserInfo;
const data = wsJsonToRes<PrivateMessageResponse>(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<any, InboxState> {
this.setState(this.state);
}
} else if (op == UserOperation.SaveComment) {
let data = wsJsonToRes<CommentResponse>(msg);
const data = wsJsonToRes<CommentResponse>(msg);
saveCommentRes(data.comment_view, this.state.replies);
this.setState(this.state);
setupTippy();
} else if (op == UserOperation.CreateCommentLike) {
let data = wsJsonToRes<CommentResponse>(msg);
const data = wsJsonToRes<CommentResponse>(msg);
createCommentLikeRes(data.comment_view, this.state.replies);
this.setState(this.state);
} else if (op == UserOperation.BlockPerson) {
let data = wsJsonToRes<BlockPersonResponse>(msg);
const data = wsJsonToRes<BlockPersonResponse>(msg);
updatePersonBlock(data);
} else if (op == UserOperation.CreatePostReport) {
let data = wsJsonToRes<PostReportResponse>(msg);
const data = wsJsonToRes<PostReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}
} else if (op == UserOperation.CreateCommentReport) {
let data = wsJsonToRes<CommentReportResponse>(msg);
const data = wsJsonToRes<CommentReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}
} else if (op == UserOperation.CreatePrivateMessageReport) {
let data = wsJsonToRes<PrivateMessageReportResponse>(msg);
const data = wsJsonToRes<PrivateMessageReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}

View file

@ -143,11 +143,11 @@ export class PasswordChange extends Component<any, State> {
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<any, State> {
}
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<LoginResponse>(msg);
const data = wsJsonToRes<LoginResponse>(msg);
UserService.Instance.login(data);
this.props.history.push("/");
location.reload();

View file

@ -87,7 +87,7 @@ export class PersonDetails extends Component<PersonDetailsProps, any> {
renderItemType(i: ItemType) {
switch (i.type_) {
case ItemEnum.Comment: {
let c = i.view as CommentView;
const c = i.view as CommentView;
return (
<CommentNodes
key={i.id}
@ -105,7 +105,7 @@ export class PersonDetails extends Component<PersonDetailsProps, any> {
);
}
case ItemEnum.Post: {
let p = i.view as PostView;
const p = i.view as PostView;
return (
<PostListing
key={i.id}
@ -126,14 +126,14 @@ export class PersonDetails extends Component<PersonDetailsProps, any> {
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<PersonDetailsProps, any> {
score: r.counts.score,
}));
let combined = [...comments, ...posts];
const combined = [...comments, ...posts];
// Sort it
if (this.props.sort === "New") {

View file

@ -20,15 +20,15 @@ export class PersonListing extends Component<PersonListingProps, any> {
}
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<PersonListingProps, any> {
}
avatarAndName(displayName: string) {
let avatar = this.props.person.avatar;
const avatar = this.props.person.avatar;
return (
<>
{avatar &&

View file

@ -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 && (
<div>
@ -193,11 +193,11 @@ export class RegistrationApplications extends Component<
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
let promises: Promise<any>[] = [];
const promises: Promise<any>[] = [];
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<ListRegistrationApplicationsResponse>(msg);
const data = wsJsonToRes<ListRegistrationApplicationsResponse>(msg);
this.setState({
listRegistrationApplicationsResponse: data,
loading: false,
});
window.scrollTo(0, 0);
} else if (op == UserOperation.ApproveRegistrationApplication) {
let data = wsJsonToRes<RegistrationApplicationResponse>(msg);
const data = wsJsonToRes<RegistrationApplicationResponse>(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);

View file

@ -132,7 +132,7 @@ export class Reports extends Component<any, ReportsState> {
}
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<any, ReportsState> {
// .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<any, ReportsState> {
}
commentReports() {
let reports = this.state.listCommentReportsResponse?.comment_reports;
const reports = this.state.listCommentReportsResponse?.comment_reports;
return (
reports && (
<div>
@ -382,7 +382,7 @@ export class Reports extends Component<any, ReportsState> {
}
postReports() {
let reports = this.state.listPostReportsResponse?.post_reports;
const reports = this.state.listPostReportsResponse?.post_reports;
return (
reports && (
<div>
@ -398,7 +398,7 @@ export class Reports extends Component<any, ReportsState> {
}
privateMessageReports() {
let reports =
const reports =
this.state.listPrivateMessageReportsResponse?.private_message_reports;
return (
reports && (
@ -433,15 +433,15 @@ export class Reports extends Component<any, ReportsState> {
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
let promises: Promise<any>[] = [];
const promises: Promise<any>[] = [];
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<any, ReportsState> {
};
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<any, ReportsState> {
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<any, ReportsState> {
}
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<any, ReportsState> {
wsClient.listCommentReports(commentReportsForm)
);
let postReportsForm: ListPostReports = {
const postReportsForm: ListPostReports = {
unresolved_only,
page,
limit,
@ -498,7 +498,7 @@ export class Reports extends Component<any, ReportsState> {
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<any, ReportsState> {
}
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<any, ReportsState> {
} else if (msg.reconnect) {
this.refetch();
} else if (op == UserOperation.ListCommentReports) {
let data = wsJsonToRes<ListCommentReportsResponse>(msg);
const data = wsJsonToRes<ListCommentReportsResponse>(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<ListPostReportsResponse>(msg);
const data = wsJsonToRes<ListPostReportsResponse>(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<ListPrivateMessageReportsResponse>(msg);
const data = wsJsonToRes<ListPrivateMessageReportsResponse>(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<PostReportResponse>(msg);
const data = wsJsonToRes<PostReportResponse>(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<any, ReportsState> {
}
this.setState(this.state);
} else if (op == UserOperation.ResolveCommentReport) {
let data = wsJsonToRes<CommentReportResponse>(msg);
const data = wsJsonToRes<CommentReportResponse>(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<any, ReportsState> {
}
this.setState(this.state);
} else if (op == UserOperation.ResolvePrivateMessageReport) {
let data = wsJsonToRes<PrivateMessageReportResponse>(msg);
const data = wsJsonToRes<PrivateMessageReportResponse>(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 {

View file

@ -476,7 +476,7 @@ export class Settings extends Component<any, SettingsState> {
}
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<any, SettingsState> {
}
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<any, SettingsState> {
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<any, SettingsState> {
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<any, SettingsState> {
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<any, SettingsState> {
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<any, SettingsState> {
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<any, SettingsState> {
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<any, SettingsState> {
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<any, SettingsState> {
}
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<any, SettingsState> {
toast(i18n.t("saved"));
window.scrollTo(0, 0);
} else if (op == UserOperation.ChangePassword) {
let data = wsJsonToRes<LoginResponse>(msg);
const data = wsJsonToRes<LoginResponse>(msg);
UserService.Instance.login(data);
this.setState({ changePasswordLoading: false });
window.scrollTo(0, 0);
@ -1233,16 +1233,16 @@ export class Settings extends Component<any, SettingsState> {
UserService.Instance.logout();
window.location.href = "/";
} else if (op == UserOperation.BlockPerson) {
let data = wsJsonToRes<BlockPersonResponse>(msg);
const data = wsJsonToRes<BlockPersonResponse>(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<BlockCommunityResponse>(msg);
const data = wsJsonToRes<BlockCommunityResponse>(msg);
updateCommunityBlock(data);
let mui = UserService.Instance.myUserInfo;
const mui = UserService.Instance.myUserInfo;
if (mui) {
this.setState({ communityBlocks: mui.community_blocks });
}

View file

@ -76,7 +76,7 @@ export class VerifyEmail extends Component<any, State> {
}
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<any, State> {
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");

View file

@ -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 && (

View file

@ -186,10 +186,10 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
}
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 (
<div>
<Prompt
@ -449,12 +449,12 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
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<PostFormProps, PostFormState> {
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<PostFormProps, PostFormState> {
}
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<PostFormProps, PostFormState> {
}
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<PostFormProps, PostFormState> {
}
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<PostFormProps, PostFormState> {
}
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<PostFormProps, PostFormState> {
}
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<PostFormProps, PostFormState> {
this.setState({ loading: false });
return;
} else if (op == UserOperation.CreatePost) {
let data = wsJsonToRes<PostResponse>(msg);
const data = wsJsonToRes<PostResponse>(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<PostResponse>(msg);
const data = wsJsonToRes<PostResponse>(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<SearchResponse>(msg);
const data = wsJsonToRes<SearchResponse>(msg);
if (data.type_ == "Posts") {
this.setState({ suggestedPosts: data.posts });

View file

@ -179,7 +179,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
body() {
let body = this.props.post_view.post.body;
const body = this.props.post_view.post.body;
return body ? (
<div className="col-12 card my-2 p-2">
{this.state.viewSource ? (
@ -194,7 +194,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
get img() {
let src = this.imageSrc;
const src = this.imageSrc;
return src ? (
<>
<div className="offset-sm-3 my-2 d-none d-sm-block">
@ -217,7 +217,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
imgThumb(src: string) {
let post_view = this.props.post_view;
const post_view = this.props.post_view;
return (
<PictrsImage
src={src}
@ -229,9 +229,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
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<PostListingProps, PostListingState> {
}
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<PostListingProps, PostListingState> {
}
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 (
<ul className="list-inline mb-1 text-muted small">
<li className="list-inline-item">
@ -438,7 +438,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
get postLink() {
let post = this.props.post_view.post;
const post = this.props.post_view.post;
return (
<Link
className={`d-inline-block ${
@ -458,8 +458,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
postTitleLine() {
let post = this.props.post_view.post;
let url = post.url;
const post = this.props.post_view.post;
const url = post.url;
return (
<div className="post-title overflow-hidden">
@ -550,7 +550,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
duplicatesLine() {
let dupes = this.props.duplicates;
const dupes = this.props.duplicates;
return dupes && dupes.length > 0 ? (
<ul className="list-inline mb-1 small text-muted">
<>
@ -572,7 +572,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
commentsLine(mobile = false) {
let post = this.props.post_view.post;
const post = this.props.post_view.post;
return (
<div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
@ -606,7 +606,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
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<PostListingProps, PostListingState> {
}
get commentsButton() {
let post_view = this.props.post_view;
const post_view = this.props.post_view;
return (
<button className="btn btn-link text-muted py-0 pl-0">
<Link
@ -676,7 +676,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
get unreadCount(): number | undefined {
let pv = this.props.post_view;
const pv = this.props.post_view;
return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
? undefined
: pv.unread_comments;
@ -684,7 +684,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
get mobileVotes() {
// TODO: make nicer
let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
const tippy = showScores()
? { "data-tippy-content": this.pointsTippy }
: {};
return (
<>
<div>
@ -730,8 +732,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
get saveButton() {
let saved = this.props.post_view.saved;
let label = saved ? i18n.t("unsave") : i18n.t("save");
const saved = this.props.post_view.saved;
const label = saved ? i18n.t("unsave") : i18n.t("save");
return (
<button
className="btn btn-link btn-animate text-muted py-0"
@ -807,8 +809,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
get deleteButton() {
let deleted = this.props.post_view.post.deleted;
let label = !deleted ? i18n.t("delete") : i18n.t("restore");
const deleted = this.props.post_view.post.deleted;
const label = !deleted ? i18n.t("delete") : i18n.t("restore");
return (
<button
className="btn btn-link btn-animate text-muted py-0"
@ -856,8 +858,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
get lockButton() {
let locked = this.props.post_view.post.locked;
let label = locked ? i18n.t("unlock") : i18n.t("lock");
const locked = this.props.post_view.post.locked;
const label = locked ? i18n.t("unlock") : i18n.t("lock");
return (
<button
className="btn btn-link btn-animate text-muted py-0"
@ -919,7 +921,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
get modRemoveButton() {
let removed = this.props.post_view.post.removed;
const removed = this.props.post_view.post.removed;
return (
<button
className="btn btn-link btn-animate text-muted py-0"
@ -939,7 +941,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
*/
userActionsLine() {
// TODO: make nicer
let post_view = this.props.post_view;
const post_view = this.props.post_view;
return (
this.state.showAdvanced && (
<>
@ -1089,8 +1091,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
removeAndBanDialogs() {
let post = this.props.post_view;
let purgeTypeText =
const post = this.props.post_view;
const purgeTypeText =
this.state.purgeType == PurgeType.Post
? i18n.t("purge_post")
: `${i18n.t("purge")} ${post.creator.name}`;
@ -1245,7 +1247,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
mobileThumbnail() {
let post = this.props.post_view.post;
const post = this.props.post_view.post;
return post.thumbnail_url || (post.url && isImage(post.url)) ? (
<div className="row">
<div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
@ -1262,7 +1264,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
showMobilePreview() {
let body = this.props.post_view.post.body;
const body = this.props.post_view.post.body;
return !this.showBody && body ? (
<div className="md-div mb-1 preview-lines">{body}</div>
) : (
@ -1331,8 +1333,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
this.context.router.history.push(`/login`);
}
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({
@ -1354,9 +1356,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
this.setState({ my_vote: newVote });
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: CreatePostLike = {
const form: CreatePostLike = {
post_id: this.props.post_view.post.id,
score: newVote,
auth,
@ -1374,8 +1376,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
this.context.router.history.push(`/login`);
}
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({
@ -1397,9 +1399,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
this.setState({ my_vote: newVote });
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: CreatePostLike = {
const form: CreatePostLike = {
post_id: this.props.post_view.post.id,
score: newVote,
auth,
@ -1443,10 +1445,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
handleReportSubmit(i: PostListing, event: any) {
event.preventDefault();
let auth = myAuth();
let reason = i.state.reportReason;
const auth = myAuth();
const reason = i.state.reportReason;
if (auth && reason) {
let form: CreatePostReport = {
const form: CreatePostReport = {
post_id: i.props.post_view.post.id,
reason,
auth,
@ -1458,9 +1460,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handleBlockUserClick(i: PostListing) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let blockUserForm: BlockPerson = {
const blockUserForm: BlockPerson = {
person_id: i.props.post_view.creator.id,
block: true,
auth,
@ -1470,9 +1472,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handleDeleteClick(i: PostListing) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let deleteForm: DeletePost = {
const deleteForm: DeletePost = {
post_id: i.props.post_view.post.id,
deleted: !i.props.post_view.post.deleted,
auth,
@ -1482,11 +1484,11 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handleSavePostClick(i: PostListing) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let saved =
const saved =
i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
let form: SavePost = {
const form: SavePost = {
post_id: i.props.post_view.post.id,
save: saved,
auth,
@ -1514,8 +1516,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
crossPostBody(): string | undefined {
let post = this.props.post_view.post;
let body = post.body;
const post = this.props.post_view.post;
const body = post.body;
return body
? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
@ -1547,9 +1549,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
handleModRemoveSubmit(i: PostListing, event: any) {
event.preventDefault();
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: RemovePost = {
const form: RemovePost = {
post_id: i.props.post_view.post.id,
removed: !i.props.post_view.post.removed,
reason: i.state.removeReason,
@ -1561,9 +1563,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handleModLock(i: PostListing) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: LockPost = {
const form: LockPost = {
post_id: i.props.post_view.post.id,
locked: !i.props.post_view.post.locked,
auth,
@ -1573,9 +1575,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handleModFeaturePostLocal(i: PostListing) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: FeaturePost = {
const form: FeaturePost = {
post_id: i.props.post_view.post.id,
feature_type: "Local",
featured: !i.props.post_view.post.featured_local,
@ -1586,9 +1588,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handleModFeaturePostCommunity(i: PostListing) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: FeaturePost = {
const form: FeaturePost = {
post_id: i.props.post_view.post.id,
feature_type: "Community",
featured: !i.props.post_view.post.featured_community,
@ -1637,17 +1639,17 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
handlePurgeSubmit(i: PostListing, 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.post_view.creator.id,
reason: i.state.purgeReason,
auth,
};
WebSocketService.Instance.send(wsClient.purgePerson(form));
} else if (i.state.purgeType == PurgeType.Post) {
let form: PurgePost = {
const form: PurgePost = {
post_id: i.props.post_view.post.id,
reason: i.state.purgeReason,
auth,
@ -1679,13 +1681,13 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
handleModBanBothSubmit(i: PostListing, event?: any) {
if (event) event.preventDefault();
let auth = myAuth();
const auth = myAuth();
if (auth) {
let ban = !i.props.post_view.creator_banned_from_community;
let person_id = i.props.post_view.creator.id;
let remove_data = i.state.removeData;
let reason = i.state.banReason;
let expires = futureDaysToUnixTime(i.state.banExpireDays);
const ban = !i.props.post_view.creator_banned_from_community;
const person_id = i.props.post_view.creator.id;
const remove_data = i.state.removeData;
const reason = i.state.banReason;
const expires = futureDaysToUnixTime(i.state.banExpireDays);
if (i.state.banType == BanType.Community) {
// If its an unban, restore all their data
@ -1693,7 +1695,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
i.setState({ removeData: false });
}
let form: BanFromCommunity = {
const form: BanFromCommunity = {
person_id,
community_id: i.props.post_view.community.id,
ban,
@ -1705,11 +1707,11 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
WebSocketService.Instance.send(wsClient.banFromCommunity(form));
} else {
// If its an unban, restore all their data
let ban = !i.props.post_view.creator.banned;
const ban = !i.props.post_view.creator.banned;
if (ban == false) {
i.setState({ removeData: false });
}
let form: BanPerson = {
const form: BanPerson = {
person_id,
ban,
remove_data,
@ -1725,9 +1727,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handleAddModToCommunity(i: PostListing) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: AddModToCommunity = {
const form: AddModToCommunity = {
person_id: i.props.post_view.creator.id,
community_id: i.props.post_view.community.id,
added: !i.creatorIsMod_,
@ -1739,9 +1741,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handleAddAdmin(i: PostListing) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: AddAdmin = {
const form: AddAdmin = {
person_id: i.props.post_view.creator.id,
added: !i.creatorIsAdmin_,
auth,
@ -1760,9 +1762,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handleTransferCommunity(i: PostListing) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: TransferCommunity = {
const form: TransferCommunity = {
community_id: i.props.post_view.community.id,
person_id: i.props.post_view.creator.id,
auth,
@ -1809,17 +1811,17 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
get pointsTippy(): string {
let points = i18n.t("number_of_points", {
const points = i18n.t("number_of_points", {
count: Number(this.state.score),
formattedCount: Number(this.state.score),
});
let upvotes = i18n.t("number_of_upvotes", {
const upvotes = i18n.t("number_of_upvotes", {
count: Number(this.state.upvotes),
formattedCount: Number(this.state.upvotes),
});
let downvotes = i18n.t("number_of_downvotes", {
const downvotes = i18n.t("number_of_downvotes", {
count: Number(this.state.downvotes),
formattedCount: Number(this.state.downvotes),
});

View file

@ -62,14 +62,14 @@ export class PostListings extends Component<PostListingsProps, any> {
removeDuplicates(): PostView[] {
// Must use a spread to clone the props, because splice will fail below otherwise.
let posts = [...this.props.posts];
const posts = [...this.props.posts];
// A map from post url to list of posts (dupes)
let urlMap = new Map<string, PostView[]>();
const urlMap = new Map<string, PostView[]>();
// Loop over the posts, find ones with same urls
for (let pv of posts) {
let url = pv.post.url;
for (const pv of posts) {
const url = pv.post.url;
if (
!pv.post.deleted &&
!pv.post.removed &&
@ -87,7 +87,7 @@ export class PostListings extends Component<PostListingsProps, any> {
// Sort by oldest
// Remove the ones that have no length
for (let e of urlMap.entries()) {
for (const e of urlMap.entries()) {
if (e[1].length == 1) {
urlMap.delete(e[0]);
} else {
@ -96,10 +96,10 @@ export class PostListings extends Component<PostListingsProps, any> {
}
for (let i = 0; i < posts.length; i++) {
let pv = posts[i];
let url = pv.post.url;
const pv = posts[i];
const url = pv.post.url;
if (url) {
let found = urlMap.get(url);
const found = urlMap.get(url);
if (found) {
// If its the oldest, add
if (pv.post.id == found[0].post.id) {

View file

@ -18,10 +18,10 @@ export class PostReport extends Component<PostReportProps, any> {
}
render() {
let r = this.props.report;
let resolver = r.resolver;
let post = r.post;
let tippyContent = i18n.t(
const r = this.props.report;
const resolver = r.resolver;
const post = r.post;
const tippyContent = i18n.t(
r.post_report.resolved ? "unresolve_report" : "resolve_report"
);
@ -29,7 +29,7 @@ export class PostReport extends Component<PostReportProps, any> {
post.name = r.post_report.original_post_name;
post.url = r.post_report.original_post_url;
post.body = r.post_report.original_post_body;
let pv: PostView = {
const pv: PostView = {
post,
creator: r.post_creator,
community: r.community,
@ -94,9 +94,9 @@ export class PostReport extends Component<PostReportProps, any> {
}
handleResolveReport(i: PostReport) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: ResolvePostReport = {
const form: ResolvePostReport = {
report_id: i.props.report.post_report.id,
resolved: !i.props.report.post_report.resolved,
auth,

View file

@ -161,15 +161,15 @@ export class Post extends Component<any, PostState> {
}
fetchPost() {
let auth = myAuth(false);
let postForm: GetPost = {
const auth = myAuth(false);
const postForm: GetPost = {
id: this.state.postId,
comment_id: this.state.commentId,
auth,
};
WebSocketService.Instance.send(wsClient.getPost(postForm));
let commentsForm: GetComments = {
const commentsForm: GetComments = {
post_id: this.state.postId,
parent_id: this.state.commentId,
max_depth: commentTreeMaxDepth,
@ -182,9 +182,9 @@ export class Post extends Component<any, PostState> {
}
fetchCrossPosts() {
let q = this.state.postRes?.post_view.post.url;
const q = this.state.postRes?.post_view.post.url;
if (q) {
let form: Search = {
const form: Search = {
q,
type_: "Url",
sort: "TopAll",
@ -198,18 +198,18 @@ export class Post extends Component<any, PostState> {
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
let pathSplit = req.path.split("/");
let promises: Promise<any>[] = [];
const pathSplit = req.path.split("/");
const promises: Promise<any>[] = [];
let pathType = pathSplit.at(1);
let id = pathSplit.at(2) ? Number(pathSplit.at(2)) : undefined;
let auth = req.auth;
const pathType = pathSplit.at(1);
const id = pathSplit.at(2) ? Number(pathSplit.at(2)) : undefined;
const auth = req.auth;
let postForm: GetPost = {
const postForm: GetPost = {
auth,
};
let commentsForm: GetComments = {
const commentsForm: GetComments = {
max_depth: commentTreeMaxDepth,
sort: "Hot",
type_: "All",
@ -286,21 +286,21 @@ export class Post extends Component<any, PostState> {
};
get documentTitle(): string {
let name_ = this.state.postRes?.post_view.post.name;
let siteName = this.state.siteRes.site_view.site.name;
const name_ = this.state.postRes?.post_view.post.name;
const siteName = this.state.siteRes.site_view.site.name;
return name_ ? `${name_} - ${siteName}` : "";
}
get imageTag(): string | undefined {
let post = this.state.postRes?.post_view.post;
let thumbnail = post?.thumbnail_url;
let url = post?.url;
const post = this.state.postRes?.post_view.post;
const thumbnail = post?.thumbnail_url;
const url = post?.url;
return thumbnail || (url && isImage(url) ? url : undefined);
}
render() {
let res = this.state.postRes;
let description = res?.post_view.post.body;
const res = this.state.postRes;
const description = res?.post_view.post.body;
return (
<div className="container-lg">
{this.state.loading ? (
@ -445,8 +445,8 @@ export class Post extends Component<any, PostState> {
commentsFlat() {
// These are already sorted by new
let commentsRes = this.state.commentsRes;
let postRes = this.state.postRes;
const commentsRes = this.state.commentsRes;
const postRes = this.state.postRes;
return (
commentsRes &&
postRes && (
@ -470,7 +470,7 @@ export class Post extends Component<any, PostState> {
}
sidebar() {
let res = this.state.postRes;
const res = this.state.postRes;
return (
res && (
<div className="mb-3">
@ -500,7 +500,7 @@ export class Post extends Component<any, PostState> {
}
handleCommentViewTypeChange(i: Post, event: any) {
let comments = i.state.commentsRes?.comments;
const comments = i.state.commentsRes?.comments;
if (comments) {
i.setState({
commentViewType: Number(event.target.value),
@ -515,14 +515,14 @@ export class Post extends Component<any, PostState> {
}
handleViewPost(i: Post) {
let id = i.state.postRes?.post_view.post.id;
const id = i.state.postRes?.post_view.post.id;
if (id) {
i.context.router.history.push(`/post/${id}`);
}
}
handleViewContext(i: Post) {
let parentId = getCommentParentId(
const parentId = getCommentParentId(
i.state.commentsRes?.comments?.at(0)?.comment
);
if (parentId) {
@ -531,10 +531,10 @@ export class Post extends Component<any, PostState> {
}
commentsTree() {
let res = this.state.postRes;
let firstComment = this.state.commentTree.at(0)?.comment_view.comment;
let depth = getDepthFromComment(firstComment);
let showContextButton = depth ? depth > 0 : false;
const res = this.state.postRes;
const firstComment = this.state.commentTree.at(0)?.comment_view.comment;
const depth = getDepthFromComment(firstComment);
const showContextButton = depth ? depth > 0 : false;
return (
res && (
@ -574,13 +574,13 @@ export class Post extends Component<any, PostState> {
}
parseMessage(msg: any) {
let op = wsUserOp(msg);
const op = wsUserOp(msg);
console.log(msg);
if (msg.error) {
toast(i18n.t(msg.error), "danger");
return;
} else if (msg.reconnect) {
let post_id = this.state.postRes?.post_view.post.id;
const post_id = this.state.postRes?.post_view.post.id;
if (post_id) {
WebSocketService.Instance.send(wsClient.postJoin({ post_id }));
WebSocketService.Instance.send(
@ -591,7 +591,7 @@ export class Post extends Component<any, PostState> {
);
}
} else if (op == UserOperation.GetPost) {
let data = wsJsonToRes<GetPostResponse>(msg);
const data = wsJsonToRes<GetPostResponse>(msg);
this.setState({ postRes: data });
// join the rooms
@ -614,35 +614,35 @@ export class Post extends Component<any, PostState> {
this.scrollIntoCommentSection();
}
} else if (op == UserOperation.GetComments) {
let data = wsJsonToRes<GetCommentsResponse>(msg);
const data = wsJsonToRes<GetCommentsResponse>(msg);
// This section sets the comments res
let comments = this.state.commentsRes?.comments;
const comments = this.state.commentsRes?.comments;
if (comments) {
// You might need to append here, since this could be building more comments from a tree fetch
// Remove the first comment, since it is the parent
let newComments = data.comments;
const newComments = data.comments;
newComments.shift();
comments.push(...newComments);
} else {
this.setState({ commentsRes: data });
}
let cComments = this.state.commentsRes?.comments ?? [];
const cComments = this.state.commentsRes?.comments ?? [];
this.setState({
commentTree: buildCommentsTree(cComments, !!this.state.commentId),
loading: false,
});
} else if (op == UserOperation.CreateComment) {
let data = wsJsonToRes<CommentResponse>(msg);
const data = wsJsonToRes<CommentResponse>(msg);
// Don't get comments from the post room, if the creator is blocked
let creatorBlocked = UserService.Instance.myUserInfo?.person_blocks
const creatorBlocked = UserService.Instance.myUserInfo?.person_blocks
.map(pb => pb.target.id)
.includes(data.comment_view.creator.id);
// Necessary since it might be a user reply, which has the recipients, to avoid double
let postRes = this.state.postRes;
let commentsRes = this.state.commentsRes;
const postRes = this.state.postRes;
const commentsRes = this.state.commentsRes;
if (
data.recipient_ids.length == 0 &&
!creatorBlocked &&
@ -666,21 +666,21 @@ export class Post extends Component<any, PostState> {
op == UserOperation.DeleteComment ||
op == UserOperation.RemoveComment
) {
let data = wsJsonToRes<CommentResponse>(msg);
const data = wsJsonToRes<CommentResponse>(msg);
editCommentRes(data.comment_view, this.state.commentsRes?.comments);
this.setState(this.state);
setupTippy();
} else if (op == UserOperation.SaveComment) {
let data = wsJsonToRes<CommentResponse>(msg);
const data = wsJsonToRes<CommentResponse>(msg);
saveCommentRes(data.comment_view, this.state.commentsRes?.comments);
this.setState(this.state);
setupTippy();
} else if (op == UserOperation.CreateCommentLike) {
let data = wsJsonToRes<CommentResponse>(msg);
const data = wsJsonToRes<CommentResponse>(msg);
createCommentLikeRes(data.comment_view, this.state.commentsRes?.comments);
this.setState(this.state);
} else if (op == UserOperation.CreatePostLike) {
let data = wsJsonToRes<PostResponse>(msg);
const data = wsJsonToRes<PostResponse>(msg);
createPostLikeRes(data.post_view, this.state.postRes?.post_view);
this.setState(this.state);
} else if (
@ -691,8 +691,8 @@ export class Post extends Component<any, PostState> {
op == UserOperation.FeaturePost ||
op == UserOperation.SavePost
) {
let data = wsJsonToRes<PostResponse>(msg);
let res = this.state.postRes;
const data = wsJsonToRes<PostResponse>(msg);
const res = this.state.postRes;
if (res) {
res.post_view = data.post_view;
this.setState(this.state);
@ -704,17 +704,17 @@ export class Post extends Component<any, PostState> {
op == UserOperation.RemoveCommunity ||
op == UserOperation.FollowCommunity
) {
let data = wsJsonToRes<CommunityResponse>(msg);
let res = this.state.postRes;
const data = wsJsonToRes<CommunityResponse>(msg);
const res = this.state.postRes;
if (res) {
res.community_view = data.community_view;
res.post_view.community = data.community_view.community;
this.setState(this.state);
}
} else if (op == UserOperation.BanFromCommunity) {
let data = wsJsonToRes<BanFromCommunityResponse>(msg);
const data = wsJsonToRes<BanFromCommunityResponse>(msg);
let res = this.state.postRes;
const res = this.state.postRes;
if (res) {
if (res.post_view.creator.id == data.person_view.person.id) {
res.post_view.creator_banned_from_community = data.banned;
@ -726,19 +726,19 @@ export class Post extends Component<any, PostState> {
.forEach(c => (c.creator_banned_from_community = data.banned));
this.setState(this.state);
} else if (op == UserOperation.AddModToCommunity) {
let data = wsJsonToRes<AddModToCommunityResponse>(msg);
let res = this.state.postRes;
const data = wsJsonToRes<AddModToCommunityResponse>(msg);
const res = this.state.postRes;
if (res) {
res.moderators = data.moderators;
this.setState(this.state);
}
} else if (op == UserOperation.BanPerson) {
let data = wsJsonToRes<BanPersonResponse>(msg);
const data = wsJsonToRes<BanPersonResponse>(msg);
this.state.commentsRes?.comments
.filter(c => c.creator.id == data.person_view.person.id)
.forEach(c => (c.creator.banned = data.banned));
let res = this.state.postRes;
const res = this.state.postRes;
if (res) {
if (res.post_view.creator.id == data.person_view.person.id) {
res.post_view.creator.banned = data.banned;
@ -746,20 +746,20 @@ export class Post extends Component<any, PostState> {
}
this.setState(this.state);
} else if (op == UserOperation.AddAdmin) {
let data = wsJsonToRes<AddAdminResponse>(msg);
const data = wsJsonToRes<AddAdminResponse>(msg);
this.setState(s => ((s.siteRes.admins = data.admins), s));
} else if (op == UserOperation.Search) {
let data = wsJsonToRes<SearchResponse>(msg);
let xPosts = data.posts.filter(
const data = wsJsonToRes<SearchResponse>(msg);
const xPosts = data.posts.filter(
p => p.post.ap_id != this.state.postRes?.post_view.post.ap_id
);
this.setState({ crossPosts: xPosts.length > 0 ? xPosts : undefined });
} else if (op == UserOperation.LeaveAdmin) {
let data = wsJsonToRes<GetSiteResponse>(msg);
const data = wsJsonToRes<GetSiteResponse>(msg);
this.setState({ siteRes: data });
} else if (op == UserOperation.TransferCommunity) {
let data = wsJsonToRes<GetCommunityResponse>(msg);
let res = this.state.postRes;
const data = wsJsonToRes<GetCommunityResponse>(msg);
const res = this.state.postRes;
if (res) {
res.community_view = data.community_view;
res.post_view.community = data.community_view.community;
@ -767,15 +767,15 @@ export class Post extends Component<any, PostState> {
this.setState(this.state);
}
} else if (op == UserOperation.BlockPerson) {
let data = wsJsonToRes<BlockPersonResponse>(msg);
const data = wsJsonToRes<BlockPersonResponse>(msg);
updatePersonBlock(data);
} else if (op == UserOperation.CreatePostReport) {
let data = wsJsonToRes<PostReportResponse>(msg);
const data = wsJsonToRes<PostReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}
} else if (op == UserOperation.CreateCommentReport) {
let data = wsJsonToRes<CommentReportResponse>(msg);
const data = wsJsonToRes<CommentReportResponse>(msg);
if (data) {
toast(i18n.t("report_created"));
}
@ -785,7 +785,7 @@ export class Post extends Component<any, PostState> {
op == UserOperation.PurgeComment ||
op == UserOperation.PurgeCommunity
) {
let data = wsJsonToRes<PurgeItemResponse>(msg);
const data = wsJsonToRes<PurgeItemResponse>(msg);
if (data.success) {
toast(i18n.t("purge_success"));
this.context.router.history.push(`/`);

View file

@ -65,7 +65,7 @@ export class CreatePrivateMessage extends Component<
}
fetchPersonDetails() {
let form: GetPersonDetails = {
const form: GetPersonDetails = {
person_id: this.state.recipient_id,
sort: "New",
saved_only: false,
@ -75,8 +75,8 @@ export class CreatePrivateMessage extends Component<
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
let person_id = Number(req.path.split("/").pop());
let form: GetPersonDetails = {
const person_id = Number(req.path.split("/").pop());
const form: GetPersonDetails = {
person_id,
sort: "New",
saved_only: false,
@ -86,7 +86,7 @@ export class CreatePrivateMessage extends Component<
}
get documentTitle(): string {
let name_ = this.state.recipientDetailsRes?.person_view.person.name;
const name_ = this.state.recipientDetailsRes?.person_view.person.name;
return name_ ? `${i18n.t("create_private_message")} - ${name_}` : "";
}
@ -97,7 +97,7 @@ export class CreatePrivateMessage extends Component<
}
render() {
let res = this.state.recipientDetailsRes;
const res = this.state.recipientDetailsRes;
return (
<div className="container-lg">
<HtmlTags
@ -133,14 +133,14 @@ export class CreatePrivateMessage 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.GetPersonDetails) {
let data = wsJsonToRes<GetPersonDetailsResponse>(msg);
const data = wsJsonToRes<GetPersonDetailsResponse>(msg);
this.setState({ recipientDetailsRes: data, loading: false });
}
}

View file

@ -183,19 +183,19 @@ export class PrivateMessageForm extends Component<
handlePrivateMessageSubmit(i: PrivateMessageForm, event: any) {
event.preventDefault();
let pm = i.props.privateMessageView;
let auth = myAuth();
let content = i.state.content;
const pm = i.props.privateMessageView;
const auth = myAuth();
const content = i.state.content;
if (auth && content) {
if (pm) {
let form: EditPrivateMessage = {
const form: EditPrivateMessage = {
private_message_id: pm.private_message.id,
content,
auth,
};
WebSocketService.Instance.send(wsClient.editPrivateMessage(form));
} else {
let form: CreatePrivateMessage = {
const form: CreatePrivateMessage = {
content,
recipient_id: i.props.recipient.id,
auth,
@ -224,7 +224,7 @@ export class PrivateMessageForm 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");
@ -235,11 +235,11 @@ export class PrivateMessageForm extends Component<
op == UserOperation.DeletePrivateMessage ||
op == UserOperation.MarkPrivateMessageAsRead
) {
let data = wsJsonToRes<PrivateMessageResponse>(msg);
const data = wsJsonToRes<PrivateMessageResponse>(msg);
this.setState({ loading: false });
this.props.onEdit?.(data.private_message_view);
} else if (op == UserOperation.CreatePrivateMessage) {
let data = wsJsonToRes<PrivateMessageResponse>(msg);
const data = wsJsonToRes<PrivateMessageResponse>(msg);
this.props.onCreate?.(data.private_message_view);
}
}

View file

@ -20,9 +20,9 @@ export class PrivateMessageReport extends Component<Props, any> {
}
render() {
let r = this.props.report;
let pmr = r.private_message_report;
let tippyContent = i18n.t(
const r = this.props.report;
const pmr = r.private_message_report;
const tippyContent = i18n.t(
r.private_message_report.resolved ? "unresolve_report" : "resolve_report"
);
@ -78,10 +78,10 @@ export class PrivateMessageReport extends Component<Props, any> {
}
handleResolveReport(i: PrivateMessageReport) {
let pmr = i.props.report.private_message_report;
let auth = myAuth();
const pmr = i.props.report.private_message_report;
const auth = myAuth();
if (auth) {
let form: ResolvePrivateMessageReport = {
const form: ResolvePrivateMessageReport = {
report_id: pmr.id,
resolved: !pmr.resolved,
auth,

View file

@ -56,8 +56,8 @@ export class PrivateMessage extends Component<
}
render() {
let message_view = this.props.private_message_view;
let otherPerson: Person = this.mine
const message_view = this.props.private_message_view;
const otherPerson: Person = this.mine
? message_view.recipient
: message_view.creator;
@ -261,7 +261,7 @@ export class PrivateMessage extends Component<
}
get messageUnlessRemoved(): string {
let message = this.props.private_message_view.private_message;
const message = this.props.private_message_view.private_message;
return message.deleted ? `*${i18n.t("deleted")}*` : message.content;
}
@ -275,9 +275,9 @@ export class PrivateMessage extends Component<
}
handleDeleteClick(i: PrivateMessage) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: DeletePrivateMessage = {
const form: DeletePrivateMessage = {
private_message_id: i.props.private_message_view.private_message.id,
deleted: !i.props.private_message_view.private_message.deleted,
auth,
@ -291,9 +291,9 @@ export class PrivateMessage extends Component<
}
handleMarkRead(i: PrivateMessage) {
let auth = myAuth();
const auth = myAuth();
if (auth) {
let form: MarkPrivateMessageAsRead = {
const form: MarkPrivateMessageAsRead = {
private_message_id: i.props.private_message_view.private_message.id,
read: !i.props.private_message_view.private_message.read,
auth,
@ -320,10 +320,10 @@ export class PrivateMessage extends Component<
handleReportSubmit(i: PrivateMessage, event: any) {
event.preventDefault();
let auth = myAuth();
let reason = i.state.reportReason;
const auth = myAuth();
const reason = i.state.reportReason;
if (auth && reason) {
let form: CreatePrivateMessageReport = {
const form: CreatePrivateMessageReport = {
private_message_id: i.props.private_message_view.private_message.id,
reason,
auth,

View file

@ -34,7 +34,7 @@ export class UserService {
}
public login(res: LoginResponse) {
let expires = new Date();
const expires = new Date();
expires.setDate(expires.getDate() + 365);
if (res.jwt) {
toast(i18n.t("logged_in"));
@ -56,11 +56,11 @@ export class UserService {
}
public auth(throwErr = true): string | undefined {
let jwt = this.jwtInfo?.jwt;
const jwt = this.jwtInfo?.jwt;
if (jwt) {
return jwt;
} else {
let msg = "No JWT cookie found";
const msg = "No JWT cookie found";
if (throwErr && isBrowser()) {
console.error(msg);
toast(i18n.t("not_logged_in"), "danger");
@ -71,7 +71,7 @@ export class UserService {
}
private setJwtInfo() {
let jwt: string | undefined = IsomorphicCookie.load("jwt");
const jwt: string | undefined = IsomorphicCookie.load("jwt");
if (jwt) {
this.jwtInfo = { jwt, claims: jwt_decode(jwt) };

View file

@ -30,7 +30,7 @@ export class WebSocketService {
console.log(`Connected to ${getWsUri()}`);
if (!firstConnect) {
let res = {
const res = {
reconnect: true,
};
obs.next(res);

View file

@ -110,7 +110,7 @@ export interface ErrorPageData {
adminMatrixIds?: string[];
}
let customEmojis: EmojiMartCategory[] = [];
const customEmojis: EmojiMartCategory[] = [];
export let customEmojisLookup: Map<string, CustomEmojiView> = new Map<
string,
CustomEmojiView
@ -192,11 +192,11 @@ export function hotRankPost(post_view: PostView): number {
export function hotRank(score: number, timeStr: string): number {
// Rank = ScaleFactor * sign(Score) * log(1 + abs(Score)) / (Time + 2)^Gravity
let date: Date = new Date(timeStr + "Z"); // Add Z to convert from UTC date
let now: Date = new Date();
let hoursElapsed: number = (now.getTime() - date.getTime()) / 36e5;
const date: Date = new Date(timeStr + "Z"); // Add Z to convert from UTC date
const now: Date = new Date();
const hoursElapsed: number = (now.getTime() - date.getTime()) / 36e5;
let rank =
const rank =
(10000 * Math.log10(Math.max(1, 3 + Number(score)))) /
Math.pow(hoursElapsed + 2, 1.8);
@ -243,7 +243,7 @@ export function canMod(
.concat(mods?.map(m => m.moderator.id) ?? []) ?? [];
if (myUserInfo) {
let myIndex = adminsThenMods.findIndex(
const myIndex = adminsThenMods.findIndex(
id => id == myUserInfo.local_user_view.person.id
);
if (myIndex == -1) {
@ -294,7 +294,7 @@ export function amCommunityCreator(
mods?: CommunityModeratorView[],
myUserInfo = UserService.Instance.myUserInfo
): boolean {
let myId = myUserInfo?.local_user_view.person.id;
const myId = myUserInfo?.local_user_view.person.id;
// Don't allow mod actions on yourself
return myId == mods?.at(0)?.moderator.id && myId != creator_id;
}
@ -304,7 +304,7 @@ export function amSiteCreator(
admins?: PersonView[],
myUserInfo = UserService.Instance.myUserInfo
): boolean {
let myId = myUserInfo?.local_user_view.person.id;
const myId = myUserInfo?.local_user_view.person.id;
return myId == admins?.at(0)?.person.id && myId != creator_id;
}
@ -331,12 +331,12 @@ export function validURL(str: string) {
}
export function communityRSSUrl(actorId: string, sort: string): string {
let url = new URL(actorId);
const url = new URL(actorId);
return `${url.origin}/feeds${url.pathname}.xml?sort=${sort}`;
}
export function validEmail(email: string) {
let re =
const re =
/^(([^\s"(),.:;<>@[\\\]]+(\.[^\s"(),.:;<>@[\\\]]+)*)|(".+"))@((\[(?:\d{1,3}\.){3}\d{1,3}])|(([\dA-Za-z\-]+\.)+[A-Za-z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
@ -346,8 +346,8 @@ export function capitalizeFirstLetter(str: string): string {
}
export async function getSiteMetadata(url: string) {
let form: GetSiteMetadata = { url };
let client = new LemmyHttp(getHttpBase());
const form: GetSiteMetadata = { url };
const client = new LemmyHttp(getHttpBase());
return client.getSiteMetadata(form);
}
@ -404,8 +404,8 @@ export function getLanguages(
override?: string,
myUserInfo = UserService.Instance.myUserInfo
): string[] {
let myLang = myUserInfo?.local_user_view.local_user.interface_language;
let lang = override || myLang || "browser";
const myLang = myUserInfo?.local_user_view.local_user.interface_language;
const lang = override || myLang || "browser";
if (lang == "browser" && isBrowser()) {
return getBrowserLanguages();
@ -416,10 +416,10 @@ export function getLanguages(
function getBrowserLanguages(): string[] {
// Intersect lemmy's langs, with the browser langs
let langs = languages ? languages.map(l => l.code) : ["en"];
const langs = languages ? languages.map(l => l.code) : ["en"];
// NOTE, mobile browsers seem to be missing this list, so append en
let allowedLangs = navigator.languages
const allowedLangs = navigator.languages
.concat("en")
.filter(v => langs.includes(v));
return allowedLangs;
@ -441,11 +441,11 @@ export async function setTheme(theme: string, forceReload = false) {
theme = "darkly";
}
let themeList = await fetchThemeList();
const themeList = await fetchThemeList();
// Unload all the other themes
for (var i = 0; i < themeList.length; i++) {
let styleSheet = document.getElementById(themeList[i]);
const styleSheet = document.getElementById(themeList[i]);
if (styleSheet) {
styleSheet.setAttribute("disabled", "disabled");
}
@ -457,7 +457,7 @@ export async function setTheme(theme: string, forceReload = false) {
document.getElementById("default-dark")?.setAttribute("disabled", "disabled");
// Load the theme dynamically
let cssLoc = `/css/themes/${theme}.css`;
const cssLoc = `/css/themes/${theme}.css`;
loadCss(theme, cssLoc);
document.getElementById(theme)?.removeAttribute("disabled");
@ -568,10 +568,10 @@ interface NotifyInfo {
export function messageToastify(info: NotifyInfo, router: any) {
if (isBrowser()) {
let htmlBody = info.body ? md.render(info.body) : "";
let backgroundColor = `var(--light)`;
const htmlBody = info.body ? md.render(info.body) : "";
const backgroundColor = `var(--light)`;
let toast = Toastify({
const toast = Toastify({
text: `${htmlBody}<br />${info.name}`,
avatar: info.icon,
backgroundColor: backgroundColor,
@ -593,7 +593,7 @@ export function messageToastify(info: NotifyInfo, router: any) {
}
export function notifyPost(post_view: PostView, router: any) {
let info: NotifyInfo = {
const info: NotifyInfo = {
name: post_view.community.name,
icon: post_view.community.icon,
link: `/post/${post_view.post.id}`,
@ -603,7 +603,7 @@ export function notifyPost(post_view: PostView, router: any) {
}
export function notifyComment(comment_view: CommentView, router: any) {
let info: NotifyInfo = {
const info: NotifyInfo = {
name: comment_view.creator.name,
icon: comment_view.creator.avatar,
link: `/comment/${comment_view.comment.id}`,
@ -613,7 +613,7 @@ export function notifyComment(comment_view: CommentView, router: any) {
}
export function notifyPrivateMessage(pmv: PrivateMessageView, router: any) {
let info: NotifyInfo = {
const info: NotifyInfo = {
name: pmv.creator.name,
icon: pmv.creator.avatar,
link: `/inbox`,
@ -649,11 +649,11 @@ export function setupTribute() {
{
trigger: ":",
menuItemTemplate: (item: any) => {
let shortName = `:${item.original.key}:`;
const shortName = `:${item.original.key}:`;
return `${item.original.val} ${shortName}`;
},
selectTemplate: (item: any) => {
let customEmoji = customEmojisLookup.get(
const customEmoji = customEmojisLookup.get(
item.original.key
)?.custom_emoji;
if (customEmoji == undefined) return `${item.original.val}`;
@ -680,7 +680,7 @@ export function setupTribute() {
{
trigger: "@",
selectTemplate: (item: any) => {
let it: PersonTribute = item.original;
const it: PersonTribute = item.original;
return `[${it.key}](${it.view.person.actor_id})`;
},
values: debounce(async (text: string, cb: any) => {
@ -697,7 +697,7 @@ export function setupTribute() {
{
trigger: "!",
selectTemplate: (item: any) => {
let it: CommunityTribute = item.original;
const it: CommunityTribute = item.original;
return `[${it.key}](${it.view.community.actor_id})`;
},
values: debounce(async (text: string, cb: any) => {
@ -714,7 +714,10 @@ export function setupTribute() {
}
function setupEmojiDataModel(custom_emoji_views: CustomEmojiView[]) {
let groupedEmojis = groupBy(custom_emoji_views, x => x.custom_emoji.category);
const groupedEmojis = groupBy(
custom_emoji_views,
x => x.custom_emoji.category
);
for (const [category, emojis] of Object.entries(groupedEmojis)) {
customEmojis.push({
id: category,
@ -739,7 +742,7 @@ export function updateEmojiDataModel(custom_emoji_view: CustomEmojiView) {
keywords: custom_emoji_view.keywords.map(x => x.keyword),
skins: [{ src: custom_emoji_view.custom_emoji.image_url }],
};
let categoryIndex = customEmojis.findIndex(
const categoryIndex = customEmojis.findIndex(
x => x.id == custom_emoji_view.custom_emoji.category
);
if (categoryIndex == -1) {
@ -749,7 +752,7 @@ export function updateEmojiDataModel(custom_emoji_view: CustomEmojiView) {
emojis: [emoji],
});
} else {
let emojiIndex = customEmojis[categoryIndex].emojis.findIndex(
const emojiIndex = customEmojis[categoryIndex].emojis.findIndex(
x => x.id == custom_emoji_view.custom_emoji.shortcode
);
if (emojiIndex == -1) {
@ -766,7 +769,7 @@ export function updateEmojiDataModel(custom_emoji_view: CustomEmojiView) {
export function removeFromEmojiDataModel(id: number) {
let view: CustomEmojiView | undefined;
for (let item of customEmojisLookup.values()) {
for (const item of customEmojisLookup.values()) {
if (item.custom_emoji.id === id) {
view = item;
break;
@ -872,9 +875,9 @@ interface PersonTribute {
}
async function personSearch(text: string): Promise<PersonTribute[]> {
let users = (await fetchUsers(text)).users;
let persons: PersonTribute[] = users.map(pv => {
let tribute: PersonTribute = {
const users = (await fetchUsers(text)).users;
const persons: PersonTribute[] = users.map(pv => {
const tribute: PersonTribute = {
key: `@${pv.person.name}@${hostname(pv.person.actor_id)}`,
view: pv,
};
@ -889,9 +892,9 @@ interface CommunityTribute {
}
async function communitySearch(text: string): Promise<CommunityTribute[]> {
let comms = (await fetchCommunities(text)).communities;
let communities: CommunityTribute[] = comms.map(cv => {
let tribute: CommunityTribute = {
const comms = (await fetchCommunities(text)).communities;
const communities: CommunityTribute[] = comms.map(cv => {
const tribute: CommunityTribute = {
key: `!${cv.community.name}@${hostname(cv.community.actor_id)}`,
view: cv,
};
@ -907,17 +910,17 @@ export function getRecipientIdFromProps(props: any): number {
}
export function getIdFromProps(props: any): number | undefined {
let id = props.match.params.post_id;
const id = props.match.params.post_id;
return id ? Number(id) : undefined;
}
export function getCommentIdFromProps(props: any): number | undefined {
let id = props.match.params.comment_id;
const id = props.match.params.comment_id;
return id ? Number(id) : undefined;
}
export function editCommentRes(data: CommentView, comments?: CommentView[]) {
let found = comments?.find(c => c.comment.id == data.comment.id);
const found = comments?.find(c => c.comment.id == data.comment.id);
if (found) {
found.comment.content = data.comment.content;
found.comment.distinguished = data.comment.distinguished;
@ -931,7 +934,7 @@ export function editCommentRes(data: CommentView, comments?: CommentView[]) {
}
export function saveCommentRes(data: CommentView, comments?: CommentView[]) {
let found = comments?.find(c => c.comment.id == data.comment.id);
const found = comments?.find(c => c.comment.id == data.comment.id);
if (found) {
found.saved = data.saved;
}
@ -941,7 +944,7 @@ export function updatePersonBlock(
data: BlockPersonResponse,
myUserInfo: MyUserInfo | undefined = UserService.Instance.myUserInfo
) {
let mui = myUserInfo;
const mui = myUserInfo;
if (mui) {
if (data.blocked) {
mui.person_blocks.push({
@ -962,7 +965,7 @@ export function updateCommunityBlock(
data: BlockCommunityResponse,
myUserInfo: MyUserInfo | undefined = UserService.Instance.myUserInfo
) {
let mui = myUserInfo;
const mui = myUserInfo;
if (mui) {
if (data.blocked) {
mui.community_blocks.push({
@ -983,7 +986,7 @@ export function createCommentLikeRes(
data: CommentView,
comments?: CommentView[]
) {
let found = comments?.find(c => c.comment.id === data.comment.id);
const found = comments?.find(c => c.comment.id === data.comment.id);
if (found) {
found.counts.score = data.counts.score;
found.counts.upvotes = data.counts.upvotes;
@ -995,7 +998,7 @@ export function createCommentLikeRes(
}
export function createPostLikeFindRes(data: PostView, posts?: PostView[]) {
let found = posts?.find(p => p.post.id == data.post.id);
const found = posts?.find(p => p.post.id == data.post.id);
if (found) {
createPostLikeRes(data, found);
}
@ -1013,7 +1016,7 @@ export function createPostLikeRes(data: PostView, post_view?: PostView) {
}
export function editPostFindRes(data: PostView, posts?: PostView[]) {
let found = posts?.find(p => p.post.id == data.post.id);
const found = posts?.find(p => p.post.id == data.post.id);
if (found) {
editPostRes(data, found);
}
@ -1039,7 +1042,7 @@ export function updatePostReportRes(
data: PostReportView,
reports?: PostReportView[]
) {
let found = reports?.find(p => p.post_report.id == data.post_report.id);
const found = reports?.find(p => p.post_report.id == data.post_report.id);
if (found) {
found.post_report = data.post_report;
}
@ -1049,7 +1052,9 @@ export function updateCommentReportRes(
data: CommentReportView,
reports?: CommentReportView[]
) {
let found = reports?.find(c => c.comment_report.id == data.comment_report.id);
const found = reports?.find(
c => c.comment_report.id == data.comment_report.id
);
if (found) {
found.comment_report = data.comment_report;
}
@ -1059,7 +1064,7 @@ export function updatePrivateMessageReportRes(
data: PrivateMessageReportView,
reports?: PrivateMessageReportView[]
) {
let found = reports?.find(
const found = reports?.find(
c => c.private_message_report.id == data.private_message_report.id
);
if (found) {
@ -1071,7 +1076,7 @@ export function updateRegistrationApplicationRes(
data: RegistrationApplicationView,
applications?: RegistrationApplicationView[]
) {
let found = applications?.find(
const found = applications?.find(
ra => ra.registration_application.id == data.registration_application.id
);
if (found) {
@ -1082,8 +1087,8 @@ export function updateRegistrationApplicationRes(
}
export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] {
let nodes: CommentNodeI[] = [];
for (let comment of comments) {
const nodes: CommentNodeI[] = [];
for (const comment of comments) {
nodes.push({ comment_view: comment, children: [], depth: 0 });
}
return nodes;
@ -1111,15 +1116,15 @@ export function buildCommentsTree(
comments: CommentView[],
parentComment: boolean
): CommentNodeI[] {
let map = new Map<number, CommentNodeI>();
let depthOffset = !parentComment
const map = new Map<number, CommentNodeI>();
const depthOffset = !parentComment
? 0
: getDepthFromComment(comments[0].comment) ?? 0;
for (let comment_view of comments) {
let depthI = getDepthFromComment(comment_view.comment) ?? 0;
let depth = depthI ? depthI - depthOffset : 0;
let node: CommentNodeI = {
for (const comment_view of comments) {
const depthI = getDepthFromComment(comment_view.comment) ?? 0;
const depth = depthI ? depthI - depthOffset : 0;
const node: CommentNodeI = {
comment_view,
children: [],
depth,
@ -1127,22 +1132,22 @@ export function buildCommentsTree(
map.set(comment_view.comment.id, { ...node });
}
let tree: CommentNodeI[] = [];
const tree: CommentNodeI[] = [];
// if its a parent comment fetch, then push the first comment to the top node.
if (parentComment) {
let cNode = map.get(comments[0].comment.id);
const cNode = map.get(comments[0].comment.id);
if (cNode) {
tree.push(cNode);
}
}
for (let comment_view of comments) {
let child = map.get(comment_view.comment.id);
for (const comment_view of comments) {
const child = map.get(comment_view.comment.id);
if (child) {
let parent_id = getCommentParentId(comment_view.comment);
const parent_id = getCommentParentId(comment_view.comment);
if (parent_id) {
let parent = map.get(parent_id);
const parent = map.get(parent_id);
// Necessary because blocked comment might not exist
if (parent) {
parent.children.push(child);
@ -1159,7 +1164,7 @@ export function buildCommentsTree(
}
export function getCommentParentId(comment?: CommentI): number | undefined {
let split = comment?.path.split(".");
const split = comment?.path.split(".");
// remove the 0
split?.shift();
@ -1169,7 +1174,7 @@ export function getCommentParentId(comment?: CommentI): number | undefined {
}
export function getDepthFromComment(comment?: CommentI): number | undefined {
let len = comment?.path.split(".").length;
const len = comment?.path.split(".").length;
return len ? len - 2 : undefined;
}
@ -1179,15 +1184,15 @@ export function insertCommentIntoTree(
parentComment: boolean
) {
// Building a fake node to be used for later
let node: CommentNodeI = {
const node: CommentNodeI = {
comment_view: cv,
children: [],
depth: 0,
};
let parentId = getCommentParentId(cv.comment);
const parentId = getCommentParentId(cv.comment);
if (parentId) {
let parent_comment = searchCommentTree(tree, parentId);
const parent_comment = searchCommentTree(tree, parentId);
if (parent_comment) {
node.depth = parent_comment.depth + 1;
parent_comment.children.unshift(node);
@ -1201,13 +1206,13 @@ export function searchCommentTree(
tree: CommentNodeI[],
id: number
): CommentNodeI | undefined {
for (let node of tree) {
for (const node of tree) {
if (node.comment_view.comment.id === id) {
return node;
}
for (const child of node.children) {
let res = searchCommentTree([child], id);
const res = searchCommentTree([child], id);
if (res) {
return res;
@ -1232,7 +1237,7 @@ function hsl(num: number) {
}
export function hostname(url: string): string {
let cUrl = new URL(url);
const cUrl = new URL(url);
return cUrl.port ? `${cUrl.hostname}:${cUrl.port}` : `${cUrl.hostname}`;
}
@ -1305,14 +1310,14 @@ moment.updateLocale("en", {
});
export function saveScrollPosition(context: any) {
let path: string = context.router.route.location.pathname;
let y = window.scrollY;
const path: string = context.router.route.location.pathname;
const y = window.scrollY;
sessionStorage.setItem(`scrollPosition_${path}`, y.toString());
}
export function restoreScrollPosition(context: any) {
let path: string = context.router.route.location.pathname;
let y = Number(sessionStorage.getItem(`scrollPosition_${path}`));
const path: string = context.router.route.location.pathname;
const y = Number(sessionStorage.getItem(`scrollPosition_${path}`));
window.scrollTo(0, y);
}
@ -1347,7 +1352,7 @@ export function personToChoice(pvs: PersonView): Choice {
}
export async function fetchCommunities(q: string) {
let form: Search = {
const form: Search = {
q,
type_: "Communities",
sort: "TopAll",
@ -1356,12 +1361,12 @@ export async function fetchCommunities(q: string) {
limit: fetchLimit,
auth: myAuth(false),
};
let client = new LemmyHttp(getHttpBase());
const client = new LemmyHttp(getHttpBase());
return client.search(form);
}
export async function fetchUsers(q: string) {
let form: Search = {
const form: Search = {
q,
type_: "Users",
sort: "TopAll",
@ -1370,7 +1375,7 @@ export async function fetchUsers(q: string) {
limit: fetchLimit,
auth: myAuth(false),
};
let client = new LemmyHttp(getHttpBase());
const client = new LemmyHttp(getHttpBase());
return client.search(form);
}
@ -1408,7 +1413,7 @@ export function numToSI(value: number): string {
}
export function isBanned(ps: Person): boolean {
let expires = ps.ban_expires;
const expires = ps.ban_expires;
// Add Z to convert from UTC date
// TODO this check probably isn't necessary anymore
if (expires) {
@ -1478,8 +1483,8 @@ export function nsfwCheck(
pv: PostView,
myUserInfo = UserService.Instance.myUserInfo
): boolean {
let nsfw = pv.post.nsfw || pv.community.nsfw;
let myShowNsfw = myUserInfo?.local_user_view.local_user.show_nsfw ?? false;
const nsfw = pv.post.nsfw || pv.community.nsfw;
const myShowNsfw = myUserInfo?.local_user_view.local_user.show_nsfw ?? false;
return !nsfw || (nsfw && myShowNsfw);
}
@ -1503,10 +1508,10 @@ export function selectableLanguages(
showSite?: boolean,
myUserInfo = UserService.Instance.myUserInfo
): Language[] {
let allLangIds = allLanguages.map(l => l.id);
const allLangIds = allLanguages.map(l => l.id);
let myLangs = myUserInfo?.discussion_languages ?? allLangIds;
myLangs = myLangs.length == 0 ? allLangIds : myLangs;
let siteLangs = siteLanguages.length == 0 ? allLangIds : siteLanguages;
const siteLangs = siteLanguages.length == 0 ? allLangIds : siteLanguages;
if (showAll) {
return allLanguages;