Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor lets to consts #1089

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"no-useless-constructor": 0,
"no-useless-escape": 0,
"no-var": 0,
"prefer-const": 0,
"prefer-const": 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised booleans aren't used for these.

"prefer-rest-params": 0,
"quote-props": 0,
"unicorn/filename-case": 0
Expand Down
6 changes: 3 additions & 3 deletions src/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
30 changes: 15 additions & 15 deletions src/shared/components/app/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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") {
Expand All @@ -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({
Expand All @@ -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 +
Expand All @@ -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)
Expand All @@ -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 ==
Expand All @@ -514,24 +514,24 @@ 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));

if (amAdmin()) {
console.log("Fetching applications...");

let applicationCountForm: GetUnreadRegistrationApplicationCount = {
const applicationCountForm: GetUnreadRegistrationApplicationCount = {
auth,
};
WebSocketService.Instance.send(
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/app/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
22 changes: 11 additions & 11 deletions src/shared/components/comment/comment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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) {
Expand Down
Loading