1
1
mirror of https://github.com/usememos/memos.git synced 2024-12-25 04:13:07 +03:00

chore: update eslint rules

This commit is contained in:
Steven 2022-09-04 06:48:19 +08:00
parent 4743818fe7
commit b884327a53
25 changed files with 69 additions and 93 deletions

View File

@ -21,7 +21,6 @@
"endOfLine": "auto"
}
],
"@typescript-eslint/no-empty-interface": ["off"],
"@typescript-eslint/no-explicit-any": ["off"],
"react/react-in-jsx-scope": "off"
},

View File

@ -7,7 +7,7 @@ import { generateDialog } from "./Dialog";
import GitHubBadge from "./GitHubBadge";
import "../less/about-site-dialog.less";
interface Props extends DialogProps {}
type Props = DialogProps;
const AboutSiteDialog: React.FC<Props> = ({ destroy }: Props) => {
const { t } = useI18n();

View File

@ -8,7 +8,7 @@ import toastHelper from "./Toast";
import ArchivedMemo from "./ArchivedMemo";
import "../less/archived-memo-dialog.less";
interface Props extends DialogProps {}
type Props = DialogProps;
const ArchivedMemoDialog: React.FC<Props> = (props: Props) => {
const { destroy } = props;

View File

@ -14,7 +14,7 @@ const validateConfig: ValidatorConfig = {
noChinese: true,
};
interface Props extends DialogProps {}
type Props = DialogProps;
const ChangePasswordDialog: React.FC<Props> = ({ destroy }: Props) => {
const { t } = useI18n();

View File

@ -3,9 +3,7 @@ import * as api from "../helpers/api";
import Icon from "./Icon";
import "../less/github-badge.less";
interface Props {}
const GitHubBadge: React.FC<Props> = () => {
const GitHubBadge = () => {
const [starCount, setStarCount] = useState(0);
useEffect(() => {

View File

@ -9,14 +9,12 @@ import toastHelper from "./Toast";
import Editor, { EditorRefActions } from "./Editor/Editor";
import "../less/memo-editor.less";
interface Props {}
interface State {
isUploadingResource: boolean;
fullscreen: boolean;
}
const MemoEditor: React.FC<Props> = () => {
const MemoEditor = () => {
const { t, locale } = useI18n();
const user = useAppSelector((state) => state.user.user);
const editorState = useAppSelector((state) => state.editor);

View File

@ -4,9 +4,7 @@ import * as utils from "../helpers/utils";
import { getTextWithMemoType } from "../helpers/filter";
import "../less/memo-filter.less";
interface FilterProps {}
const MemoFilter: React.FC<FilterProps> = () => {
const MemoFilter = () => {
const query = useAppSelector((state) => state.location.query);
useAppSelector((state) => state.shortcut.shortcuts);
const { tag: tagQuery, duration, type: memoType, text: textQuery, shortcutId } = query;

View File

@ -10,9 +10,7 @@ import Only from "./common/OnlyWhen";
import Memo from "./Memo";
import "../less/memo-list.less";
interface Props {}
const MemoList: React.FC<Props> = () => {
const MemoList = () => {
const { t } = useI18n();
const query = useAppSelector((state) => state.location.query);
const { memos, isFetching } = useAppSelector((state) => state.memo);

View File

@ -8,9 +8,7 @@ import "../less/memos-header.less";
let prevRequestTimestamp = Date.now();
interface Props {}
const MemosHeader: React.FC<Props> = () => {
const MemosHeader = () => {
const query = useAppSelector((state) => state.location.query);
const shortcuts = useAppSelector((state) => state.shortcut.shortcuts);
const [titleText, setTitleText] = useState("MEMOS");

View File

@ -11,7 +11,7 @@ import Icon from "./Icon";
import toastHelper from "./Toast";
import "../less/resources-dialog.less";
interface Props extends DialogProps {}
type Props = DialogProps;
interface State {
resources: Resource[];

View File

@ -4,9 +4,7 @@ import { memoSpecialTypes } from "../helpers/filter";
import Icon from "./Icon";
import "../less/search-bar.less";
interface Props {}
const SearchBar: React.FC<Props> = () => {
const SearchBar = () => {
const memoType = useAppSelector((state) => state.location.query?.type);
const handleMemoTypeItemClick = (type: MemoSpecType | undefined) => {

View File

@ -8,7 +8,7 @@ import PreferencesSection from "./Settings/PreferencesSection";
import MemberSection from "./Settings/MemberSection";
import "../less/setting-dialog.less";
interface Props extends DialogProps {}
type Props = DialogProps;
type SettingSection = "my-account" | "preferences" | "member";

View File

@ -9,14 +9,12 @@ import Dropdown from "../common/Dropdown";
import { showCommonDialog } from "../Dialog/CommonDialog";
import "../../less/settings/member-section.less";
interface Props {}
interface State {
createUserEmail: string;
createUserPassword: string;
}
const PreferencesSection: React.FC<Props> = () => {
const PreferencesSection = () => {
const { t } = useI18n();
const currentUser = useAppSelector((state) => state.user.user);
const [state, setState] = useState<State>({

View File

@ -15,9 +15,7 @@ const validateConfig: ValidatorConfig = {
noChinese: true,
};
interface Props {}
const MyAccountSection: React.FC<Props> = () => {
const MyAccountSection = () => {
const { t } = useI18n();
const user = useAppSelector((state) => state.user.user as User);
const [username, setUsername] = useState<string>(user.name);

View File

@ -6,8 +6,6 @@ import Selector from "../common/Selector";
import BetaBadge from "../BetaBadge";
import "../../less/settings/preferences-section.less";
interface Props {}
const localeSelectorItems = [
{
text: "English",
@ -30,7 +28,7 @@ const editorFontStyleSelectorItems = [
},
];
const PreferencesSection: React.FC<Props> = () => {
const PreferencesSection = () => {
const { t } = useI18n();
const { setting } = useAppSelector((state) => state.user.user as User);

View File

@ -10,9 +10,7 @@ import toastHelper from "./Toast";
import showCreateShortcutDialog from "./CreateShortcutDialog";
import "../less/shortcut-list.less";
interface Props {}
const ShortcutList: React.FC<Props> = () => {
const ShortcutList = () => {
const query = useAppSelector((state) => state.location.query);
const shortcuts = useAppSelector((state) => state.shortcut.shortcuts);
const loadingState = useLoading();

View File

@ -12,9 +12,7 @@ import ShortcutList from "./ShortcutList";
import TagList from "./TagList";
import "../less/siderbar.less";
interface Props {}
const Sidebar: React.FC<Props> = () => {
const Sidebar = () => {
const { t } = useI18n();
const handleMyAccountBtnClick = () => {

View File

@ -14,9 +14,7 @@ interface Tag {
subTags: Tag[];
}
interface Props {}
const TagList: React.FC<Props> = () => {
const TagList = () => {
const { t } = useI18n();
const { memos, tags: tagsText } = useAppSelector((state) => state.memo);
const query = useAppSelector((state) => state.location.query);

View File

@ -1,6 +1,5 @@
import { useEffect } from "react";
import { createRoot, Root } from "react-dom/client";
import { TOAST_ANIMATION_DURATION } from "../helpers/consts";
import "../less/toast.less";
type ToastType = "normal" | "success" | "info" | "error";
@ -36,42 +35,26 @@ const Toast: React.FC<ToastItemProps> = (props: ToastItemProps) => {
);
};
class ToastHelper {
private shownToastAmount = 0;
private toastWrapper: HTMLDivElement;
private shownToastContainers: [Root, HTMLDivElement][] = [];
// toast animation duration.
const TOAST_ANIMATION_DURATION = 400;
constructor() {
const wrapperClassName = "toast-list-container";
const tempDiv = document.createElement("div");
tempDiv.className = wrapperClassName;
document.body.appendChild(tempDiv);
this.toastWrapper = tempDiv;
}
const initialToastHelper = () => {
const shownToastContainers: [Root, HTMLDivElement][] = [];
let shownToastAmount = 0;
public info = (content: string, duration = 3000) => {
return this.showToast({ type: "normal", content, duration });
};
const wrapperClassName = "toast-list-container";
const tempDiv = document.createElement("div");
tempDiv.className = wrapperClassName;
document.body.appendChild(tempDiv);
const toastWrapper = tempDiv;
public success = (content: string, duration = 3000) => {
return this.showToast({ type: "success", content, duration });
};
public error = (content: string, duration = 3000) => {
return this.showToast({ type: "error", content, duration });
};
private showToast = (config: ToastConfig) => {
const showToast = (config: ToastConfig) => {
const tempDiv = document.createElement("div");
const toast = createRoot(tempDiv);
tempDiv.className = `toast-wrapper ${config.type}`;
this.toastWrapper.appendChild(tempDiv);
this.shownToastAmount++;
this.shownToastContainers.push([toast, tempDiv]);
setTimeout(() => {
tempDiv.classList.add("showup");
}, 0);
toastWrapper.appendChild(tempDiv);
shownToastAmount++;
shownToastContainers.push([toast, tempDiv]);
const cbs = {
destory: () => {
@ -82,13 +65,13 @@ class ToastHelper {
return;
}
this.shownToastAmount--;
if (this.shownToastAmount === 0) {
for (const [root, tempDiv] of this.shownToastContainers) {
shownToastAmount--;
if (shownToastAmount === 0) {
for (const [root, tempDiv] of shownToastContainers) {
root.unmount();
tempDiv.remove();
}
this.shownToastContainers.splice(0, this.shownToastContainers.length);
shownToastContainers.splice(0, shownToastContainers.length);
}
}, TOAST_ANIMATION_DURATION);
},
@ -96,10 +79,32 @@ class ToastHelper {
toast.render(<Toast {...config} destory={cbs.destory} />);
setTimeout(() => {
tempDiv.classList.add("showup");
}, 10);
return cbs;
};
}
const toastHelper = new ToastHelper();
const info = (content: string, duration = 3000) => {
return showToast({ type: "normal", content, duration });
};
const success = (content: string, duration = 3000) => {
return showToast({ type: "success", content, duration });
};
const error = (content: string, duration = 3000) => {
return showToast({ type: "error", content, duration });
};
return {
info,
success,
error,
};
};
const toastHelper = initialToastHelper();
export default toastHelper;

View File

@ -26,9 +26,7 @@ interface DailyUsageStat {
count: number;
}
interface Props {}
const UsageHeatMap: React.FC<Props> = () => {
const UsageHeatMap = () => {
const todayTimeStamp = utils.getDateStampByDate(Date.now());
const todayDay = new Date(todayTimeStamp).getDay() + 1;
const nullCell = new Array(7 - todayDay).fill(0);

View File

@ -7,9 +7,7 @@ import Icon from "./Icon";
import MenuBtnsPopup from "./MenuBtnsPopup";
import "../less/user-banner.less";
interface Props {}
const UserBanner: React.FC<Props> = () => {
const UserBanner = () => {
const { user, owner } = useAppSelector((state) => state.user);
const { memos, tags } = useAppSelector((state) => state.memo);
const [shouldShowPopupBtns, setShouldShowPopupBtns] = useState(false);

View File

@ -4,9 +4,6 @@ export const UNKNOWN_ID = -1;
// default animation duration
export const ANIMATION_DURATION = 200;
// toast animation duration
export const TOAST_ANIMATION_DURATION = 400;
// millisecond in a day
export const DAILY_TIMESTAMP = 3600 * 24 * 1000;

View File

@ -54,10 +54,14 @@
@apply flex-row justify-end items-center hidden shrink-0;
> .action-btn {
@apply flex flex-row justify-center items-center w-6 h-6 shrink-0;
@apply flex flex-row justify-center items-center;
&.toggle-btn {
@apply w-4 h-auto text-gray-600;
@apply text-gray-600;
> .icon-img {
@apply w-4 h-auto;
}
&:hover {
& + .action-btns-wrapper {

View File

@ -6,6 +6,7 @@
> .toast-wrapper {
@apply flex flex-col justify-start items-start relative left-full invisible text-base cursor-pointer shadow-lg rounded bg-white mt-6 py-2 px-4;
min-width: 6em;
left: calc(100% + 32px);
transition: all 0.4s ease;
&.showup {

View File

@ -9,8 +9,6 @@ import Only from "../components/common/OnlyWhen";
import toastHelper from "../components/Toast";
import "../less/auth.less";
interface Props {}
const validateConfig: ValidatorConfig = {
minLength: 4,
maxLength: 24,
@ -18,7 +16,7 @@ const validateConfig: ValidatorConfig = {
noChinese: true,
};
const Auth: React.FC<Props> = () => {
const Auth = () => {
const { t, locale } = useI18n();
const pageLoadingState = useLoading(true);
const [siteHost, setSiteHost] = useState<User>();