Browse Source

refactor: Further eslint and *.vue consistency tweaks

Owen Diffey 2 years ago
parent
commit
b289d4f283

+ 4 - 1
frontend/.eslintrc

@@ -8,12 +8,13 @@
 	},
 	},
 	"parser": "vue-eslint-parser",
 	"parser": "vue-eslint-parser",
 	"parserOptions": {
 	"parserOptions": {
-		"ecmaVersion": 2018,
+		"ecmaVersion": 2021,
 		"sourceType": "module",
 		"sourceType": "module",
 		"requireConfigFile": false,
 		"requireConfigFile": false,
 		"parser": "@typescript-eslint/parser"
 		"parser": "@typescript-eslint/parser"
 	},
 	},
 	"extends": [
 	"extends": [
+		"airbnb-base",
 		"plugin:vue/vue3-strongly-recommended",
 		"plugin:vue/vue3-strongly-recommended",
 		"eslint:recommended",
 		"eslint:recommended",
 		"prettier",
 		"prettier",
@@ -38,8 +39,10 @@
 		"no-multi-assign": 0,
 		"no-multi-assign": 0,
 		"no-shadow": 0,
 		"no-shadow": 0,
 		"no-new": 0,
 		"no-new": 0,
+		"no-param-reassign": 0,
 		"import/no-unresolved": 0,
 		"import/no-unresolved": 0,
 		"import/extensions": 0,
 		"import/extensions": 0,
+		"import/prefer-default-export": 0,
 		"prettier/prettier": [
 		"prettier/prettier": [
 			"error"
 			"error"
 		],
 		],

+ 7 - 7
frontend/src/components/ActivityItem.vue

@@ -33,10 +33,10 @@ const messageStripped = computed(() => {
 	return message;
 	return message;
 });
 });
 
 
-function getMessagePartType(messagePart) {
-	return messagePart.substring(1, messagePart.indexOf(">"));
-}
-function getMessagePartText(messagePart) {
+const getMessagePartType = messagePart =>
+	messagePart.substring(1, messagePart.indexOf(">"));
+
+const getMessagePartText = messagePart => {
 	let message = messagePart;
 	let message = messagePart;
 
 
 	message = message.replace(/<reportId>(.*)<\/reportId>/g, "report");
 	message = message.replace(/<reportId>(.*)<\/reportId>/g, "report");
@@ -45,9 +45,9 @@ function getMessagePartText(messagePart) {
 	message = message.replace(/<stationId>(.*)<\/stationId>/g, `$1`);
 	message = message.replace(/<stationId>(.*)<\/stationId>/g, `$1`);
 
 
 	return message;
 	return message;
-}
+};
 
 
-function getIcon() {
+const getIcon = () => {
 	const icons = {
 	const icons = {
 		/** User */
 		/** User */
 		user__joined: "account_circle",
 		user__joined: "account_circle",
@@ -89,7 +89,7 @@ function getIcon() {
 	};
 	};
 
 
 	return icons[props.activity.type];
 	return icons[props.activity.type];
-}
+};
 
 
 onMounted(() => {
 onMounted(() => {
 	if (props.activity.type === "station__edit_theme")
 	if (props.activity.type === "station__edit_theme")

+ 17 - 12
frontend/src/components/SongItem.vue

@@ -44,14 +44,15 @@ const { loggedIn, role: userRole } = storeToRefs(userAuthStore);
 
 
 const { openModal } = useModalsStore();
 const { openModal } = useModalsStore();
 
 
-function formatRequestedAt() {
+const formatRequestedAt = () => {
 	if (props.requestedBy && props.song.requestedAt)
 	if (props.requestedBy && props.song.requestedAt)
 		formatedRequestedAt.value = formatDistance(
 		formatedRequestedAt.value = formatDistance(
 			parseISO(props.song.requestedAt),
 			parseISO(props.song.requestedAt),
 			new Date()
 			new Date()
 		);
 		);
-}
-function formatArtists() {
+};
+
+const formatArtists = () => {
 	if (props.song.artists.length === 1) {
 	if (props.song.artists.length === 1) {
 		return props.song.artists[0];
 		return props.song.artists[0];
 	}
 	}
@@ -64,8 +65,9 @@ function formatArtists() {
 			.join(", ")} & ${props.song.artists.slice(-1)}`;
 			.join(", ")} & ${props.song.artists.slice(-1)}`;
 	}
 	}
 	return null;
 	return null;
-}
-function hideTippyElements() {
+};
+
+const hideTippyElements = () => {
 	songActions.value.tippy.hide();
 	songActions.value.tippy.hide();
 
 
 	setTimeout(
 	setTimeout(
@@ -75,21 +77,24 @@ function hideTippyElements() {
 			),
 			),
 		500
 		500
 	);
 	);
-}
-function hoverTippy() {
+};
+
+const hoverTippy = () => {
 	hoveredTippy.value = true;
 	hoveredTippy.value = true;
-}
-function report(song) {
+};
+
+const report = song => {
 	hideTippyElements();
 	hideTippyElements();
 	openModal({ modal: "report", data: { song } });
 	openModal({ modal: "report", data: { song } });
-}
-function edit(song) {
+};
+
+const edit = song => {
 	hideTippyElements();
 	hideTippyElements();
 	openModal({
 	openModal({
 		modal: "editSong",
 		modal: "editSong",
 		data: { song }
 		data: { song }
 	});
 	});
-}
+};
 
 
 onMounted(() => {
 onMounted(() => {
 	if (props.requestedBy) {
 	if (props.requestedBy) {

+ 20 - 19
frontend/src/components/StationInfoBox.vue

@@ -19,48 +19,49 @@ const { loggedIn, userId, role } = storeToRefs(userAuthStore);
 
 
 const { openModal } = useModalsStore();
 const { openModal } = useModalsStore();
 
 
-function isOwnerOnly() {
-	return loggedIn.value && userId.value === props.station.owner;
-}
-function isAdminOnly() {
-	return loggedIn.value && role.value === "admin";
-}
-function isOwnerOrAdmin() {
-	return isOwnerOnly() || isAdminOnly();
-}
+const isOwnerOnly = () =>
+	loggedIn.value && userId.value === props.station.owner;
+
+const isAdminOnly = () => loggedIn.value && role.value === "admin";
 
 
-function resumeStation() {
+const isOwnerOrAdmin = () => isOwnerOnly() || isAdminOnly();
+
+const resumeStation = () => {
 	socket.dispatch("stations.resume", props.station._id, data => {
 	socket.dispatch("stations.resume", props.station._id, data => {
 		if (data.status !== "success") new Toast(`Error: ${data.message}`);
 		if (data.status !== "success") new Toast(`Error: ${data.message}`);
 		else new Toast("Successfully resumed the station.");
 		else new Toast("Successfully resumed the station.");
 	});
 	});
-}
-function pauseStation() {
+};
+
+const pauseStation = () => {
 	socket.dispatch("stations.pause", props.station._id, data => {
 	socket.dispatch("stations.pause", props.station._id, data => {
 		if (data.status !== "success") new Toast(`Error: ${data.message}`);
 		if (data.status !== "success") new Toast(`Error: ${data.message}`);
 		else new Toast("Successfully paused the station.");
 		else new Toast("Successfully paused the station.");
 	});
 	});
-}
-function skipStation() {
+};
+
+const skipStation = () => {
 	socket.dispatch("stations.forceSkip", props.station._id, data => {
 	socket.dispatch("stations.forceSkip", props.station._id, data => {
 		if (data.status !== "success") new Toast(`Error: ${data.message}`);
 		if (data.status !== "success") new Toast(`Error: ${data.message}`);
 		else new Toast("Successfully skipped the station's current song.");
 		else new Toast("Successfully skipped the station's current song.");
 	});
 	});
-}
-function favoriteStation() {
+};
+
+const favoriteStation = () => {
 	socket.dispatch("stations.favoriteStation", props.station._id, res => {
 	socket.dispatch("stations.favoriteStation", props.station._id, res => {
 		if (res.status === "success") {
 		if (res.status === "success") {
 			new Toast("Successfully favorited station.");
 			new Toast("Successfully favorited station.");
 		} else new Toast(res.message);
 		} else new Toast(res.message);
 	});
 	});
-}
-function unfavoriteStation() {
+};
+
+const unfavoriteStation = () => {
 	socket.dispatch("stations.unfavoriteStation", props.station._id, res => {
 	socket.dispatch("stations.unfavoriteStation", props.station._id, res => {
 		if (res.status === "success") {
 		if (res.status === "success") {
 			new Toast("Successfully unfavorited station.");
 			new Toast("Successfully unfavorited station.");
 		} else new Toast(res.message);
 		} else new Toast(res.message);
 	});
 	});
-}
+};
 </script>
 </script>
 
 
 <template>
 <template>

+ 2 - 1
frontend/src/components/global/QuickConfirm.vue

@@ -9,6 +9,7 @@ const emit = defineEmits(["confirm"]);
 
 
 const clickedOnce = ref(false);
 const clickedOnce = ref(false);
 const body = ref(document.body);
 const body = ref(document.body);
+const quickConfirm = ref();
 
 
 const confirm = event => {
 const confirm = event => {
 	if (
 	if (
@@ -23,7 +24,7 @@ const confirm = event => {
 	clickedOnce.value = false;
 	clickedOnce.value = false;
 	emit("confirm");
 	emit("confirm");
 	setTimeout(() => {
 	setTimeout(() => {
-		ref("confirm").tippy.hide();
+		quickConfirm.value.tippy.hide();
 	}, 25);
 	}, 25);
 };
 };
 
 

+ 4 - 6
frontend/src/composables/useReports.ts

@@ -2,8 +2,8 @@ import Toast from "toasters";
 import ws from "@/ws";
 import ws from "@/ws";
 
 
 export const useReports = () => {
 export const useReports = () => {
-	const resolveReport = ({ reportId, value }) => {
-		return new Promise((resolve, reject) => {
+	const resolveReport = ({ reportId, value }) =>
+		new Promise((resolve, reject) => {
 			ws.socket.dispatch("reports.resolve", reportId, value, res => {
 			ws.socket.dispatch("reports.resolve", reportId, value, res => {
 				new Toast(res.message);
 				new Toast(res.message);
 				if (res.status === "success")
 				if (res.status === "success")
@@ -11,10 +11,9 @@ export const useReports = () => {
 				return reject(new Error(res.message));
 				return reject(new Error(res.message));
 			});
 			});
 		});
 		});
-	};
 
 
-	const removeReport = reportId => {
-		return new Promise((resolve, reject) => {
+	const removeReport = reportId =>
+		new Promise((resolve, reject) => {
 			ws.socket.dispatch("reports.remove", reportId, res => {
 			ws.socket.dispatch("reports.remove", reportId, res => {
 				new Toast(res.message);
 				new Toast(res.message);
 				if (res.status === "success")
 				if (res.status === "success")
@@ -22,7 +21,6 @@ export const useReports = () => {
 				return reject(new Error(res.message));
 				return reject(new Error(res.message));
 			});
 			});
 		});
 		});
-	};
 
 
 	return {
 	return {
 		resolveReport,
 		resolveReport,

+ 2 - 2
frontend/src/pages/Station/Sidebar/Users.vue

@@ -17,7 +17,7 @@ const frontendDomain = ref("");
 
 
 const { users, userCount } = storeToRefs(stationStore);
 const { users, userCount } = storeToRefs(stationStore);
 
 
-async function copyToClipboard() {
+const copyToClipboard = async () => {
 	try {
 	try {
 		await navigator.clipboard.writeText(
 		await navigator.clipboard.writeText(
 			frontendDomain.value + route.fullPath
 			frontendDomain.value + route.fullPath
@@ -25,7 +25,7 @@ async function copyToClipboard() {
 	} catch (err) {
 	} catch (err) {
 		new Toast("Failed to copy to clipboard.");
 		new Toast("Failed to copy to clipboard.");
 	}
 	}
-}
+};
 
 
 onMounted(async () => {
 onMounted(async () => {
 	frontendDomain.value = await lofig.get("frontendDomain");
 	frontendDomain.value = await lofig.get("frontendDomain");

+ 2 - 2
frontend/src/pages/Station/index.vue

@@ -76,7 +76,7 @@ const activityWatchVideoLastStatus = ref("");
 const activityWatchVideoLastYouTubeId = ref("");
 const activityWatchVideoLastYouTubeId = ref("");
 // const activityWatchVideoLastStartDuration = ref("");
 // const activityWatchVideoLastStartDuration = ref("");
 const nextCurrentSong = ref(null);
 const nextCurrentSong = ref(null);
-const editSongModalWatcher = ref(null);
+// const editSongModalWatcher = ref(null);
 // const beforeEditSongModalLocalPaused = ref(null);
 // const beforeEditSongModalLocalPaused = ref(null);
 const socketConnected = ref(null);
 const socketConnected = ref(null);
 const persistentToastCheckerInterval = ref(null);
 const persistentToastCheckerInterval = ref(null);
@@ -1375,7 +1375,7 @@ onBeforeUnmount(() => {
 		keyboardShortcuts.unregisterShortcut(shortcutName);
 		keyboardShortcuts.unregisterShortcut(shortcutName);
 	});
 	});
 
 
-	editSongModalWatcher.value(); // removes the watcher
+	// editSongModalWatcher.value(); // removes the watcher
 
 
 	clearInterval(activityWatchVideoDataInterval.value);
 	clearInterval(activityWatchVideoDataInterval.value);
 	clearTimeout(window.stationNextSongTimeout);
 	clearTimeout(window.stationNextSongTimeout);

+ 9 - 9
frontend/src/stores/userAuth.ts

@@ -23,9 +23,9 @@ export const useUserAuthStore = defineStore("userAuth", {
 				const { username, email, password, recaptchaToken } = user;
 				const { username, email, password, recaptchaToken } = user;
 
 
 				if (!email || !username || !password)
 				if (!email || !username || !password)
-					return reject(new Error("Please fill in all fields"));
+					reject(new Error("Please fill in all fields"));
 				else if (!validation.isLength(email, 3, 254))
 				else if (!validation.isLength(email, 3, 254))
-					return reject(
+					reject(
 						new Error(
 						new Error(
 							"Email must have between 3 and 254 characters."
 							"Email must have between 3 and 254 characters."
 						)
 						)
@@ -34,39 +34,39 @@ export const useUserAuthStore = defineStore("userAuth", {
 					email.indexOf("@") !== email.lastIndexOf("@") ||
 					email.indexOf("@") !== email.lastIndexOf("@") ||
 					!validation.regex.emailSimple.test(email)
 					!validation.regex.emailSimple.test(email)
 				)
 				)
-					return reject(new Error("Invalid email format."));
+					reject(new Error("Invalid email format."));
 				else if (!validation.isLength(username, 2, 32))
 				else if (!validation.isLength(username, 2, 32))
-					return reject(
+					reject(
 						new Error(
 						new Error(
 							"Username must have between 2 and 32 characters."
 							"Username must have between 2 and 32 characters."
 						)
 						)
 					);
 					);
 				else if (!validation.regex.azAZ09_.test(username))
 				else if (!validation.regex.azAZ09_.test(username))
-					return reject(
+					reject(
 						new Error(
 						new Error(
 							"Invalid username format. Allowed characters: a-z, A-Z, 0-9 and _."
 							"Invalid username format. Allowed characters: a-z, A-Z, 0-9 and _."
 						)
 						)
 					);
 					);
 				else if (username.replaceAll(/[_]/g, "").length === 0)
 				else if (username.replaceAll(/[_]/g, "").length === 0)
-					return reject(
+					reject(
 						new Error(
 						new Error(
 							"Invalid username format. Allowed characters: a-z, A-Z, 0-9 and _, and there has to be at least one letter or number."
 							"Invalid username format. Allowed characters: a-z, A-Z, 0-9 and _, and there has to be at least one letter or number."
 						)
 						)
 					);
 					);
 				else if (!validation.isLength(password, 6, 200))
 				else if (!validation.isLength(password, 6, 200))
-					return reject(
+					reject(
 						new Error(
 						new Error(
 							"Password must have between 6 and 200 characters."
 							"Password must have between 6 and 200 characters."
 						)
 						)
 					);
 					);
 				else if (!validation.regex.password.test(password))
 				else if (!validation.regex.password.test(password))
-					return reject(
+					reject(
 						new Error(
 						new Error(
 							"Invalid password format. Must have one lowercase letter, one uppercase letter, one number and one special character."
 							"Invalid password format. Must have one lowercase letter, one uppercase letter, one number and one special character."
 						)
 						)
 					);
 					);
 				else
 				else
-					return ws.socket.dispatch(
+					ws.socket.dispatch(
 						"users.register",
 						"users.register",
 						username,
 						username,
 						email,
 						email,