mirror of https://github.com/casbin/casnode.git
chore(style): ban `var` and prefer `const` (#532)
This commit is contained in:
parent
68ab191685
commit
483218cddf
|
@ -22,10 +22,14 @@
|
|||
"rules": {
|
||||
// "eqeqeq": "error",
|
||||
"semi": ["error", "always"],
|
||||
"indent": ["error", 2, {
|
||||
"ignoredNodes": ["TemplateLiteral"],
|
||||
"SwitchCase": 1
|
||||
}],
|
||||
"indent": [
|
||||
"error",
|
||||
2,
|
||||
{
|
||||
"ignoredNodes": ["TemplateLiteral"],
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
// follow antd's style guide
|
||||
"quotes": ["error", "double"],
|
||||
"jsx-quotes": ["error", "prefer-double"],
|
||||
|
@ -45,7 +49,13 @@
|
|||
"space-before-function-paren": ["error", "never"],
|
||||
"no-trailing-spaces": ["error", { "ignoreComments": true }],
|
||||
"eol-last": ["error", "always"],
|
||||
// "no-var": ["error"],
|
||||
"no-var": ["error"],
|
||||
"prefer-const": [
|
||||
"error",
|
||||
{
|
||||
"destructuring": "all"
|
||||
}
|
||||
],
|
||||
"curly": ["error", "all"],
|
||||
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
|
||||
"no-mixed-spaces-and-tabs": "error",
|
||||
|
@ -92,7 +102,7 @@
|
|||
// don't use strict mod now, otherwise there are a lot of errors in the codebase
|
||||
"no-unused-vars": "off",
|
||||
"react/no-deprecated": "warn",
|
||||
"no-case-declarations": "warn",
|
||||
"no-case-declarations": "off",
|
||||
"react/jsx-key": "warn"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ class App extends Component {
|
|||
}
|
||||
|
||||
setLanguage(account) {
|
||||
let language = account?.language;
|
||||
const language = account?.language;
|
||||
if (language !== "" && language !== i18next.language) {
|
||||
Setting.setLanguage(language);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class App extends Component {
|
|||
|
||||
getAccount() {
|
||||
AccountBackend.getAccount().then((res) => {
|
||||
let account = res.data;
|
||||
const account = res.data;
|
||||
if (account !== null) {
|
||||
this.setLanguage(account);
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ export const AuthConfig = {
|
|||
redirectPath: "/callback",
|
||||
};
|
||||
|
||||
export let FrontConfig = {
|
||||
export const FrontConfig = {
|
||||
forumName: "",
|
||||
logoImage: "",
|
||||
footerLogoImage: "",
|
||||
|
|
|
@ -35,7 +35,7 @@ class SearchResultPage extends React.Component {
|
|||
|
||||
componentWillMount() {
|
||||
this.props.history.listen((route) => {
|
||||
let params = route.search.split("=");
|
||||
const params = route.search.split("=");
|
||||
if (params.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ export function getUserAvatar(username, isLarge = false) {
|
|||
return null;
|
||||
}
|
||||
|
||||
let identicon = new Identicon(md5(username), 420);
|
||||
const identicon = new Identicon(md5(username), 420);
|
||||
return "data:image/png;base64," + identicon;
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ export function changeMomentLanguage(language) {
|
|||
}
|
||||
|
||||
export function getFormattedContent(content, spacing) {
|
||||
let formattedContent = content.replace(/@(.*?)[ \n\t]|@([^ \n\t]*?)[^ \n\t]$/g, function(w) {
|
||||
const formattedContent = content.replace(/@(.*?)[ \n\t]|@([^ \n\t]*?)[^ \n\t]$/g, function(w) {
|
||||
if (w[w.length - 1] !== " ") {
|
||||
return `@[${w.substring(1, w.length)}](${ClientUrl}/member/${w.substring(1)})`;
|
||||
}
|
||||
|
@ -245,10 +245,10 @@ const stdImageExt = ["png", "jpg", "gif", "jpeg"];
|
|||
|
||||
export function getFileType(fileName) {
|
||||
let fileType = "image";
|
||||
let fileIndex = fileName.lastIndexOf(".");
|
||||
let ext = fileName.substr(fileIndex + 1);
|
||||
let lowerCase = ext.toLowerCase();
|
||||
let index = stdImageExt.indexOf(lowerCase);
|
||||
const fileIndex = fileName.lastIndexOf(".");
|
||||
const ext = fileName.substr(fileIndex + 1);
|
||||
const lowerCase = ext.toLowerCase();
|
||||
const index = stdImageExt.indexOf(lowerCase);
|
||||
if (index < 0) {
|
||||
fileType = "file";
|
||||
}
|
||||
|
@ -261,8 +261,8 @@ export function getFormattedSize(fileSize) {
|
|||
if (fileSize === null) {
|
||||
return "0 Bytes";
|
||||
}
|
||||
let index = Math.floor(Math.log(fileSize) / Math.log(1024));
|
||||
let size = (fileSize / Math.pow(1024, index)).toPrecision(3);
|
||||
const index = Math.floor(Math.log(fileSize) / Math.log(1024));
|
||||
const size = (fileSize / Math.pow(1024, index)).toPrecision(3);
|
||||
|
||||
return size + " " + unitSuffix[index];
|
||||
}
|
||||
|
@ -312,15 +312,15 @@ export function renderLink(props) {
|
|||
}
|
||||
|
||||
export function getFrontConf(field) {
|
||||
let storage = window.localStorage;
|
||||
for (let conf in FrontConfig) {
|
||||
const storage = window.localStorage;
|
||||
for (const conf in FrontConfig) {
|
||||
if (storage[conf] !== undefined) {
|
||||
FrontConfig[conf] = storage[conf];
|
||||
}
|
||||
}
|
||||
|
||||
ConfBackend.getFrontConfsByField(field).then((res) => {
|
||||
for (let key in res.data) {
|
||||
for (const key in res.data) {
|
||||
if (res.data[key].Value !== "") {
|
||||
FrontConfig[res.data[key].id] = res.data[key].value;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class AdminFrontConf extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
@ -89,7 +89,7 @@ class AdminFrontConf extends React.Component {
|
|||
|
||||
updateConf() {
|
||||
this.setState({publishClicked: true});
|
||||
let confs = [];
|
||||
const confs = [];
|
||||
for (const k in this.state.changeForm) {
|
||||
confs.push({id: k, value: this.state.changeForm[k], field: this.state.field});
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ class AdminFrontConf extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
let blurStyle = {color: "#ccc", pointerEvents: "none"};
|
||||
const blurStyle = {color: "#ccc", pointerEvents: "none"};
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
|
|
@ -68,12 +68,12 @@ class AdminFrontConf extends React.Component {
|
|||
|
||||
getFrontConf(field) {
|
||||
ConfBackend.getFrontConfsByField(field).then((res) => {
|
||||
let form = this.state.form;
|
||||
let conf = this.state.conf;
|
||||
for (let k in res.data) {
|
||||
const form = this.state.form;
|
||||
const conf = this.state.conf;
|
||||
for (const k in res.data) {
|
||||
form[res.data[k].id] = res.data[k].value;
|
||||
}
|
||||
for (let i in conf) {
|
||||
for (const i in conf) {
|
||||
conf[i].value = form[conf[i].id];
|
||||
}
|
||||
this.setState({
|
||||
|
@ -91,8 +91,8 @@ class AdminFrontConf extends React.Component {
|
|||
|
||||
inputChange(event, id) {
|
||||
event.target.style.height = event.target.scrollHeight + "px";
|
||||
let forms = this.state.changeForm;
|
||||
let form = this.state.form;
|
||||
const forms = this.state.changeForm;
|
||||
const form = this.state.form;
|
||||
form[id] = event.target.value;
|
||||
forms[id] = event.target.value;
|
||||
this.setState({
|
||||
|
@ -102,7 +102,7 @@ class AdminFrontConf extends React.Component {
|
|||
}
|
||||
|
||||
updateConf() {
|
||||
let confs = [];
|
||||
const confs = [];
|
||||
for (const k in this.state.changeForm) {
|
||||
confs.push({id: k, value: this.state.changeForm[k], field: this.state.field});
|
||||
}
|
||||
|
|
|
@ -140,9 +140,9 @@ class AdminNode extends React.Component {
|
|||
handleUploadImage(event, target) {
|
||||
this.updateFormField(target, i18next.t("file:Uploading..."));
|
||||
|
||||
let file = event.target.files[0];
|
||||
let fileName,
|
||||
fileType = Setting.getFileType(file.name);
|
||||
const file = event.target.files[0];
|
||||
let fileName;
|
||||
const fileType = Setting.getFileType(file.name);
|
||||
|
||||
if (target === "headerImage") {
|
||||
fileName = "header";
|
||||
|
@ -153,7 +153,7 @@ class AdminNode extends React.Component {
|
|||
}
|
||||
fileName += "." + fileType.ext;
|
||||
|
||||
let reader = new FileReader();
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
FileBackend.moderatorUpload(e.target.result, fileName, "sitecontent/nodes/" + this.state.nodeInfo.id).then((res) => {
|
||||
if (res?.status === "ok") {
|
||||
|
@ -169,7 +169,7 @@ class AdminNode extends React.Component {
|
|||
}
|
||||
|
||||
initForm() {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
if (this.props.event === "new") {
|
||||
form["sorter"] = 1;
|
||||
} else {
|
||||
|
@ -202,7 +202,7 @@ class AdminNode extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
@ -341,7 +341,7 @@ class AdminNode extends React.Component {
|
|||
}
|
||||
|
||||
renderProblem() {
|
||||
let problems = [];
|
||||
const problems = [];
|
||||
|
||||
if (this.state.errorMessage !== "") {
|
||||
problems.push(i18next.t(`error:${this.state.errorMessage}`));
|
||||
|
@ -574,7 +574,7 @@ class AdminNode extends React.Component {
|
|||
|
||||
const image = document.getElementById("change_image");
|
||||
if (image !== null) {
|
||||
let contentWidth = image.clientWidth;
|
||||
const contentWidth = image.clientWidth;
|
||||
if (this.state.width === "") {
|
||||
this.setState({
|
||||
width: contentWidth,
|
||||
|
|
|
@ -95,7 +95,7 @@ class AdminPlane extends React.Component {
|
|||
}
|
||||
|
||||
initForm() {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
if (this.props.event === "new") {
|
||||
form["sorter"] = 1;
|
||||
form["visible"] = true;
|
||||
|
@ -115,7 +115,7 @@ class AdminPlane extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
@ -295,7 +295,7 @@ class AdminPlane extends React.Component {
|
|||
}
|
||||
|
||||
renderProblem() {
|
||||
let problems = [];
|
||||
const problems = [];
|
||||
|
||||
if (this.state.errorMessage !== "") {
|
||||
problems.push(i18next.t(`error:${this.state.errorMessage}`));
|
||||
|
|
|
@ -44,9 +44,9 @@ class AdminPoster extends React.Component {
|
|||
}
|
||||
|
||||
changeinputval() {
|
||||
let a_val = this.state.form["advertiser"];
|
||||
let l_val = this.state.form["link"];
|
||||
let p_val = this.state.form["picture_link"];
|
||||
const a_val = this.state.form["advertiser"];
|
||||
const l_val = this.state.form["link"];
|
||||
const p_val = this.state.form["picture_link"];
|
||||
if (a_val !== undefined) {
|
||||
this.adver.current.value = a_val;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class AdminPoster extends React.Component {
|
|||
|
||||
readposter() {
|
||||
PosterBackend.readposter("r_box_poster").then((res) => {
|
||||
let poster = res;
|
||||
const poster = res;
|
||||
if (poster) {
|
||||
this.setState(
|
||||
{
|
||||
|
@ -96,9 +96,9 @@ class AdminPoster extends React.Component {
|
|||
}
|
||||
|
||||
inputChange(id) {
|
||||
let a_val = this.adver.current.value;
|
||||
let l_val = this.links.current.value;
|
||||
let p_val = this.p_link.current.value;
|
||||
const a_val = this.adver.current.value;
|
||||
const l_val = this.links.current.value;
|
||||
const p_val = this.p_link.current.value;
|
||||
this.setState({
|
||||
form: {
|
||||
advertiser: a_val,
|
||||
|
|
|
@ -99,7 +99,7 @@ class AdminTab extends React.Component {
|
|||
}
|
||||
|
||||
initForm() {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
if (this.props.event === "new") {
|
||||
form["sorter"] = 1;
|
||||
form["homePage"] = false;
|
||||
|
@ -117,7 +117,7 @@ class AdminTab extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
@ -231,7 +231,7 @@ class AdminTab extends React.Component {
|
|||
}
|
||||
|
||||
renderProblem() {
|
||||
let problems = [];
|
||||
const problems = [];
|
||||
|
||||
if (this.state.errorMessage !== "") {
|
||||
problems.push(i18next.t(`error:${this.state.errorMessage}`));
|
||||
|
|
|
@ -84,7 +84,7 @@ class AdminTopic extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
if (page === null) {
|
||||
page = 1;
|
||||
|
@ -136,7 +136,7 @@ class AdminTopic extends React.Component {
|
|||
}
|
||||
|
||||
initForm() {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form["deleted"] = this.state.topic?.deleted;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
@ -144,7 +144,7 @@ class AdminTopic extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
|
|
@ -305,7 +305,7 @@ class AdminTranslation extends React.Component {
|
|||
}
|
||||
|
||||
renderProblem() {
|
||||
let problems = [];
|
||||
const problems = [];
|
||||
|
||||
if (this.state.errMessage !== "") {
|
||||
problems.push(this.state.errMessage);
|
||||
|
@ -419,7 +419,7 @@ class AdminTranslation extends React.Component {
|
|||
<td width="auto" align="left">
|
||||
<input
|
||||
onChange={(event) => {
|
||||
let targetVal = event.target.value;
|
||||
const targetVal = event.target.value;
|
||||
this.setState((prevState) => {
|
||||
prevState.form.key = targetVal;
|
||||
return prevState;
|
||||
|
@ -492,7 +492,7 @@ class AdminTranslation extends React.Component {
|
|||
<td width="auto" align="left">
|
||||
<input
|
||||
onChange={(event) => {
|
||||
let targetVal = event.target.value;
|
||||
const targetVal = event.target.value;
|
||||
this.setState((prevState) => {
|
||||
prevState.form.id = targetVal;
|
||||
return prevState;
|
||||
|
@ -510,7 +510,7 @@ class AdminTranslation extends React.Component {
|
|||
<td width="auto" align="left">
|
||||
<input
|
||||
onChange={(event) => {
|
||||
let targetVal = event.target.value;
|
||||
const targetVal = event.target.value;
|
||||
this.setState((prevState) => {
|
||||
prevState.form.name = targetVal;
|
||||
return prevState;
|
||||
|
@ -536,7 +536,7 @@ class AdminTranslation extends React.Component {
|
|||
<td width="auto" align="left">
|
||||
<input
|
||||
onChange={(event) => {
|
||||
let targetVal = event.target.value;
|
||||
const targetVal = event.target.value;
|
||||
this.setState((prevState) => {
|
||||
prevState.form.key = targetVal;
|
||||
return prevState;
|
||||
|
|
|
@ -59,7 +59,7 @@ export function getFileNum() {
|
|||
}
|
||||
|
||||
export function uploadTopicPic(base64, filetype) {
|
||||
let formData = new FormData();
|
||||
const formData = new FormData();
|
||||
formData.append("pic", base64);
|
||||
formData.append("type", filetype);
|
||||
return fetch(`${Setting.ServerUrl}/api/upload-topic-pic`, {
|
||||
|
@ -70,7 +70,7 @@ export function uploadTopicPic(base64, filetype) {
|
|||
}
|
||||
|
||||
export function uploadFile(base64, filename, filetype) {
|
||||
let formData = new FormData();
|
||||
const formData = new FormData();
|
||||
formData.append("file", base64);
|
||||
formData.append("name", filename);
|
||||
formData.append("type", filetype);
|
||||
|
@ -82,7 +82,7 @@ export function uploadFile(base64, filename, filetype) {
|
|||
}
|
||||
|
||||
export function moderatorUpload(base64, filename, filepath) {
|
||||
let formData = new FormData();
|
||||
const formData = new FormData();
|
||||
formData.append("file", base64);
|
||||
formData.append("name", filename);
|
||||
formData.append("filepath", filepath);
|
||||
|
|
|
@ -21,7 +21,7 @@ import * as serviceWorker from "./serviceWorker";
|
|||
import {BrowserRouter} from "react-router-dom";
|
||||
import {loadTheme} from "./theme";
|
||||
|
||||
let theme = localStorage.getItem("CASNODE_THEME");
|
||||
const theme = localStorage.getItem("CASNODE_THEME");
|
||||
|
||||
loadTheme(theme);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class AllCreatedTopicsBox extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
if (page === null) {
|
||||
page = 1;
|
||||
|
|
|
@ -56,7 +56,7 @@ class BalanceBox extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
if (page === null) {
|
||||
page = 1;
|
||||
|
|
|
@ -58,7 +58,7 @@ class EditBox extends React.Component {
|
|||
}
|
||||
|
||||
initForm() {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form["id"] = this.state.editObject?.id;
|
||||
if (this.state.editType === "topic") {
|
||||
form["title"] = this.state.editObject?.title;
|
||||
|
@ -133,7 +133,7 @@ class EditBox extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
|
|
@ -55,7 +55,7 @@ class FavoritesBox extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
if (page === null) {
|
||||
page = 1;
|
||||
|
|
|
@ -67,7 +67,7 @@ class FilesBox extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
if (page === null) {
|
||||
page = 1;
|
||||
|
@ -163,8 +163,8 @@ class FilesBox extends React.Component {
|
|||
}
|
||||
|
||||
uploadFile(file) {
|
||||
let fileInfo = {name: file[0].path, size: file[0].size, status: false};
|
||||
let files = this.state.files;
|
||||
const fileInfo = {name: file[0].path, size: file[0].size, status: false};
|
||||
const files = this.state.files;
|
||||
files.push(fileInfo);
|
||||
this.setState({
|
||||
files: files,
|
||||
|
@ -188,8 +188,8 @@ class FilesBox extends React.Component {
|
|||
if (this.state.event !== "upload") {
|
||||
this.props.history.push("/i?p=1");
|
||||
}
|
||||
let index = this.getIndex(file);
|
||||
let files = this.state.files;
|
||||
const index = this.getIndex(file);
|
||||
const files = this.state.files;
|
||||
files.splice(index, 1);
|
||||
this.setState({
|
||||
files: files,
|
||||
|
@ -206,7 +206,7 @@ class FilesBox extends React.Component {
|
|||
}
|
||||
|
||||
initForm() {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form["fileName"] = this.state.file?.fileName;
|
||||
form["desc"] = this.state.file?.desc;
|
||||
this.setState({
|
||||
|
@ -215,7 +215,7 @@ class FilesBox extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
@ -272,7 +272,7 @@ class FilesBox extends React.Component {
|
|||
|
||||
// url: /i/upload
|
||||
renderUpload() {
|
||||
let progressWidth = (400 / this.state.maxFileNum) * this.state.filesNum;
|
||||
const progressWidth = (400 / this.state.maxFileNum) * this.state.filesNum;
|
||||
|
||||
return (
|
||||
<span>
|
||||
|
@ -502,7 +502,7 @@ class FilesBox extends React.Component {
|
|||
}
|
||||
|
||||
renderProblem() {
|
||||
let problems = [];
|
||||
const problems = [];
|
||||
|
||||
if (this.state.message !== "") {
|
||||
problems.push(i18next.t(`error:${this.state.message}`));
|
||||
|
|
|
@ -59,7 +59,7 @@ class LatestReplyBox extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
if (page === null) {
|
||||
page = 1;
|
||||
|
|
|
@ -41,7 +41,7 @@ class MoveTopicNodeBox extends React.Component {
|
|||
}
|
||||
|
||||
initForm() {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form["id"] = this.state.topic?.id;
|
||||
form["nodeId"] = this.state.topic?.nodeId;
|
||||
form["nodeName"] = this.state.topic?.nodeName;
|
||||
|
@ -82,7 +82,7 @@ class MoveTopicNodeBox extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
|
|
@ -88,7 +88,7 @@ class NewBox extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
@ -169,7 +169,7 @@ class NewBox extends React.Component {
|
|||
return false;
|
||||
}
|
||||
|
||||
let problems = [];
|
||||
const problems = [];
|
||||
if (this.state.form.title === "" || this.state.form.title === undefined) {
|
||||
problems.push(i18next.t("error:Topic title cannot be empty"));
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ class NewBox extends React.Component {
|
|||
}
|
||||
|
||||
renderProblem() {
|
||||
let problems = this.state.problems;
|
||||
const problems = this.state.problems;
|
||||
|
||||
if (problems.length === 0 && this.state.message === "") {
|
||||
return null;
|
||||
|
|
|
@ -81,7 +81,7 @@ class NewNodeTopicBox extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
@ -100,7 +100,7 @@ class NewNodeTopicBox extends React.Component {
|
|||
return false;
|
||||
}
|
||||
|
||||
let problems = [];
|
||||
const problems = [];
|
||||
if (this.state.form.title === "" || this.state.form.title === undefined) {
|
||||
problems.push(i18next.t("error:Topic title cannot be empty"));
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ class NewNodeTopicBox extends React.Component {
|
|||
}
|
||||
|
||||
renderProblem() {
|
||||
let problems = this.state.problems;
|
||||
const problems = this.state.problems;
|
||||
|
||||
if (this.state.problems.length === 0 && this.state.message === "") {
|
||||
return null;
|
||||
|
@ -349,7 +349,7 @@ class NewNodeTopicBox extends React.Component {
|
|||
const title = document.getElementById("topic_title");
|
||||
|
||||
if (title !== null) {
|
||||
let contentWidth = title.clientWidth;
|
||||
const contentWidth = title.clientWidth;
|
||||
if (this.state.width === "") {
|
||||
this.setState({
|
||||
width: contentWidth,
|
||||
|
|
|
@ -75,7 +75,7 @@ class NewReplyBox extends React.Component {
|
|||
}
|
||||
|
||||
updateFormField(key, value) {
|
||||
let form = this.state.form;
|
||||
const form = this.state.form;
|
||||
form[key] = value;
|
||||
this.setState({
|
||||
form: form,
|
||||
|
@ -88,7 +88,7 @@ class NewReplyBox extends React.Component {
|
|||
return false;
|
||||
}
|
||||
|
||||
let problems = [];
|
||||
const problems = [];
|
||||
if (this.state.form.content === "") {
|
||||
problems.push(i18next.t("error:Reply content cannot be empty"));
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ class NewReplyBox extends React.Component {
|
|||
return null;
|
||||
}
|
||||
|
||||
let problems = [];
|
||||
const problems = [];
|
||||
if (this.state.form.content === "") {
|
||||
problems.push(i18next.t("error:Reply content cannot be empty"));
|
||||
}
|
||||
|
@ -195,11 +195,11 @@ class NewReplyBox extends React.Component {
|
|||
}
|
||||
|
||||
synonyms(cm, option) {
|
||||
let comp = this.props.memberList;
|
||||
let res = [];
|
||||
const comp = this.props.memberList;
|
||||
const res = [];
|
||||
return new Promise(function(accept) {
|
||||
setTimeout(function() {
|
||||
let cursor = cm.getCursor(),
|
||||
const cursor = cm.getCursor(),
|
||||
line = cm.getLine(cursor.line);
|
||||
let start = cursor.ch,
|
||||
end = cursor.ch;
|
||||
|
@ -209,7 +209,7 @@ class NewReplyBox extends React.Component {
|
|||
while (end < line.length && /\w/.test(line.charAt(end))) {
|
||||
++end;
|
||||
}
|
||||
let word = line.slice(start, end).toLowerCase();
|
||||
const word = line.slice(start, end).toLowerCase();
|
||||
for (let i = 0; i < comp.length; i++) {
|
||||
if (comp[i].includes(word)) {
|
||||
res.push(comp[i]);
|
||||
|
@ -233,7 +233,7 @@ class NewReplyBox extends React.Component {
|
|||
<input
|
||||
style={{marginRight: 20}}
|
||||
onClick={() => {
|
||||
let encodedUrl = encodeURIComponent(window.location.href);
|
||||
const encodedUrl = encodeURIComponent(window.location.href);
|
||||
localStorage.setItem("loginCallbackUrl", encodedUrl);
|
||||
window.location.href = Setting.getSigninUrl();
|
||||
}}
|
||||
|
@ -243,7 +243,7 @@ class NewReplyBox extends React.Component {
|
|||
/>
|
||||
<input
|
||||
onClick={() => {
|
||||
let encodedUrl = encodeURIComponent(window.location.href);
|
||||
const encodedUrl = encodeURIComponent(window.location.href);
|
||||
localStorage.setItem("loginCallbackUrl", encodedUrl);
|
||||
window.location.href = Setting.getSignupUrl();
|
||||
}}
|
||||
|
@ -389,7 +389,7 @@ class NewReplyBox extends React.Component {
|
|||
return null;
|
||||
}
|
||||
|
||||
let blurStyle = needLogin ? {color: "#ccc", pointerEvents: "none"} : null;
|
||||
const blurStyle = needLogin ? {color: "#ccc", pointerEvents: "none"} : null;
|
||||
|
||||
return (
|
||||
<div className={["box", this.props.sticky ? "sticky" : "", `${this.props.nodeId}`].join(" ")} id="reply-box">
|
||||
|
|
|
@ -69,7 +69,7 @@ class NodeBox extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
if (page === null) {
|
||||
page = 1;
|
||||
|
@ -401,13 +401,13 @@ class NodeBox extends React.Component {
|
|||
|
||||
renderNode() {
|
||||
const {page, limit} = this.state;
|
||||
let from, end;
|
||||
let from;
|
||||
if (this.state.topicNum !== 0) {
|
||||
from = (page - 1) * limit + 1;
|
||||
} else {
|
||||
from = 0;
|
||||
}
|
||||
end = (page - 1) * limit + this.state.topics.length;
|
||||
const end = (page - 1) * limit + this.state.topics.length;
|
||||
|
||||
return (
|
||||
<div className={`box ${this.state.nodeId}`}>
|
||||
|
|
|
@ -58,7 +58,7 @@ class NotificationBox extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
if (page === null) {
|
||||
page = 1;
|
||||
|
@ -125,7 +125,7 @@ class NotificationBox extends React.Component {
|
|||
};
|
||||
|
||||
renderLink = (props) => {
|
||||
let check = Setting.checkPageLink(props.href);
|
||||
const check = Setting.checkPageLink(props.href);
|
||||
if (check) {
|
||||
return <a {...props} />;
|
||||
}
|
||||
|
|
|
@ -78,8 +78,7 @@ class PageColumn extends React.Component {
|
|||
}
|
||||
|
||||
handleMaxPage(total) {
|
||||
let res;
|
||||
res = Math.ceil(total / this.state.defaultPageNum);
|
||||
const res = Math.ceil(total / this.state.defaultPageNum);
|
||||
if (res !== 0) {
|
||||
return res;
|
||||
}
|
||||
|
@ -88,7 +87,7 @@ class PageColumn extends React.Component {
|
|||
|
||||
// Get an array of page number, and there always should have 10 elements except '...'.
|
||||
getShowPages(page, total) {
|
||||
let pages = [];
|
||||
const pages = [];
|
||||
|
||||
if (total <= 10) {
|
||||
for (let i = 1; i <= total; i++) {
|
||||
|
|
|
@ -53,7 +53,7 @@ class RecentTopicsBox extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
if (page === null) {
|
||||
page = 1;
|
||||
|
|
|
@ -69,11 +69,11 @@ class ReplyBox extends React.Component {
|
|||
|
||||
componentDidMount() {
|
||||
// this.getTopic();
|
||||
let lastIndex = window.location.href.lastIndexOf("#");
|
||||
const lastIndex = window.location.href.lastIndexOf("#");
|
||||
if (lastIndex >= 0) {
|
||||
let idString = window.location.href.substring(lastIndex + 1);
|
||||
const idString = window.location.href.substring(lastIndex + 1);
|
||||
if (document.getElementById(idString) === null) {
|
||||
let targetReply = parseInt(idString.substring(2));
|
||||
const targetReply = parseInt(idString.substring(2));
|
||||
if (!isNaN(targetReply)) {
|
||||
this.jumpToTargetPage(targetReply);
|
||||
}
|
||||
|
@ -86,11 +86,11 @@ class ReplyBox extends React.Component {
|
|||
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||
if (prevState.fullUrl !== window.location.href) {
|
||||
this.setState({fullUrl: window.location.href});
|
||||
let lastIndex = window.location.href.lastIndexOf("#");
|
||||
const lastIndex = window.location.href.lastIndexOf("#");
|
||||
if (lastIndex >= 0) {
|
||||
let idString = window.location.href.substring(lastIndex + 1);
|
||||
const idString = window.location.href.substring(lastIndex + 1);
|
||||
if (document.getElementById(idString) === null) {
|
||||
let targetReply = parseInt(idString.substring(2));
|
||||
const targetReply = parseInt(idString.substring(2));
|
||||
if (!isNaN(targetReply)) {
|
||||
this.jumpToTargetPage(targetReply);
|
||||
}
|
||||
|
@ -101,8 +101,8 @@ class ReplyBox extends React.Component {
|
|||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.location !== this.props.location) {
|
||||
let params = new URLSearchParams(newProps.location.search);
|
||||
let page = params.get("p");
|
||||
const params = new URLSearchParams(newProps.location.search);
|
||||
const page = params.get("p");
|
||||
if (page !== null) {
|
||||
this.setState(
|
||||
{
|
||||
|
@ -120,7 +120,7 @@ class ReplyBox extends React.Component {
|
|||
res.data.map((reply, i) => {
|
||||
if (reply.id === targetReply) {
|
||||
found = true;
|
||||
let targetPage = Math.ceil((i + 1) / this.state.limit);
|
||||
const targetPage = Math.ceil((i + 1) / this.state.limit);
|
||||
ReplyBackend.getReplies(this.state.topicId, this.state.limit, targetPage, false).then((res) => {
|
||||
this.setState(
|
||||
{
|
||||
|
@ -198,8 +198,8 @@ class ReplyBox extends React.Component {
|
|||
}
|
||||
|
||||
getMemberList() {
|
||||
let list = [this.props.topic?.author];
|
||||
let temp = [this.props.topic?.author + " "];
|
||||
const list = [this.props.topic?.author];
|
||||
const temp = [this.props.topic?.author + " "];
|
||||
for (let i = 0; i < this.state.replies.length; ++i) {
|
||||
let flag = true;
|
||||
for (let j = 0; j < temp.length; ++j) {
|
||||
|
@ -245,7 +245,7 @@ class ReplyBox extends React.Component {
|
|||
|
||||
scrollToAnchor = (anchorName) => {
|
||||
if (anchorName) {
|
||||
let anchorElement = document.getElementById(anchorName);
|
||||
const anchorElement = document.getElementById(anchorName);
|
||||
if (anchorElement) {
|
||||
anchorElement.scrollIntoView();
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ class ReplyBox extends React.Component {
|
|||
};
|
||||
|
||||
renderLink = (props) => {
|
||||
let check = Setting.checkPageLink(props.href);
|
||||
const check = Setting.checkPageLink(props.href);
|
||||
if (check) {
|
||||
return <a {...props} />;
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ class ReplyBox extends React.Component {
|
|||
};
|
||||
|
||||
renderReplyBox(reply, no = -1) {
|
||||
let isChild = no < 0;
|
||||
const isChild = no < 0;
|
||||
|
||||
return (
|
||||
<div id={`r_${reply.id}`}>
|
||||
|
@ -384,14 +384,14 @@ class ReplyBox extends React.Component {
|
|||
|
||||
renderNestedReply(reply, no, depth) {
|
||||
depth++;
|
||||
let result = [];
|
||||
const result = [];
|
||||
if (no >= 0) {
|
||||
result.push(this.renderReplyBox(reply, no));
|
||||
}
|
||||
result.push(
|
||||
<div style={{paddingLeft: depth < maxReplyDepth ? "40px" : "", marginTop: 16}}>
|
||||
{reply.child?.map((childItem) => {
|
||||
let childResult = [];
|
||||
const childResult = [];
|
||||
if (!(childItem.deleted && childItem.child === null)) {
|
||||
childResult.push(this.renderReplyBox(childItem, -1));
|
||||
}
|
||||
|
|
|
@ -93,9 +93,9 @@ class TopicBox extends React.Component {
|
|||
}
|
||||
|
||||
judgeAnchorElement() {
|
||||
let url = window.location.href;
|
||||
let id = url.substring(url.lastIndexOf("#") + 1);
|
||||
let anchorElement = document.getElementById(id);
|
||||
const url = window.location.href;
|
||||
const id = url.substring(url.lastIndexOf("#") + 1);
|
||||
const anchorElement = document.getElementById(id);
|
||||
return !!anchorElement;
|
||||
}
|
||||
|
||||
|
@ -355,7 +355,7 @@ class TopicBox extends React.Component {
|
|||
};
|
||||
|
||||
renderLink = (props) => {
|
||||
let check = Setting.checkPageLink(props.href);
|
||||
const check = Setting.checkPageLink(props.href);
|
||||
if (check) {
|
||||
return <a {...props} />;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class RightCommunityHealthBox extends React.Component {
|
|||
|
||||
readposter() {
|
||||
PosterBackend.readposter("r_box_poster").then((res) => {
|
||||
let poster = res;
|
||||
const poster = res;
|
||||
if (poster) {
|
||||
this.setState({
|
||||
poster: poster,
|
||||
|
|
|
@ -77,8 +77,8 @@ class RightNodeBox extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
let relatedNum = this.state.info?.relatedNode?.length;
|
||||
let childNum = this.state.info?.childNode?.length;
|
||||
const relatedNum = this.state.info?.relatedNode?.length;
|
||||
const childNum = this.state.info?.childNode?.length;
|
||||
|
||||
return (
|
||||
<div className={`box ${this.state.nodeId}`}>
|
||||
|
|
|
@ -39,7 +39,7 @@ class RightThemeBox extends React.Component {
|
|||
}
|
||||
|
||||
loadThemeFile() {
|
||||
let {theme} = this.state;
|
||||
const {theme} = this.state;
|
||||
loadTheme(theme);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,15 +22,15 @@ export const loadTheme = (theme) => {
|
|||
return;
|
||||
}
|
||||
|
||||
let currTheme = THEME_OPTIONS.find((item) => item.value === theme);
|
||||
const currTheme = THEME_OPTIONS.find((item) => item.value === theme);
|
||||
|
||||
let before = document.querySelector("#casnodeTheme");
|
||||
const before = document.querySelector("#casnodeTheme");
|
||||
if (before) {
|
||||
before.parentNode.removeChild(before);
|
||||
}
|
||||
|
||||
if (currTheme.link) {
|
||||
let after = document.createElement("link");
|
||||
const after = document.createElement("link");
|
||||
after.rel = "stylesheet";
|
||||
after.type = "text/css";
|
||||
after.id = "casnodeTheme";
|
||||
|
|
Loading…
Reference in New Issue