forked from mirrors/homebox
frontend: cleanup
* dummy commit * cleanup workflows * setup and run eslint * add linter to CI * use eslint for formatting * reorder rules * drop editor config
This commit is contained in:
parent
78fa714297
commit
75c633dcb5
65 changed files with 2048 additions and 641 deletions
|
@ -1,21 +1,21 @@
|
|||
import { PublicApi } from '~~/lib/api/public';
|
||||
import { UserApi } from '~~/lib/api/user';
|
||||
import { Requests } from '~~/lib/requests';
|
||||
import { useAuthStore } from '~~/stores/auth';
|
||||
import { PublicApi } from "~~/lib/api/public";
|
||||
import { UserApi } from "~~/lib/api/user";
|
||||
import { Requests } from "~~/lib/requests";
|
||||
import { useAuthStore } from "~~/stores/auth";
|
||||
|
||||
function logger(r: Response) {
|
||||
console.log(`${r.status} ${r.url} ${r.statusText}`);
|
||||
}
|
||||
|
||||
export function usePublicApi(): PublicApi {
|
||||
const requests = new Requests('', '', {});
|
||||
const requests = new Requests("", "", {});
|
||||
return new PublicApi(requests);
|
||||
}
|
||||
|
||||
export function useUserApi(): UserApi {
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const requests = new Requests('', () => authStore.token, {});
|
||||
const requests = new Requests("", () => authStore.token, {});
|
||||
requests.addResponseInterceptor(logger);
|
||||
requests.addResponseInterceptor(r => {
|
||||
if (r.status === 401) {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { UseConfirmDialogReturn } from '@vueuse/core';
|
||||
import { Ref } from 'vue';
|
||||
import { UseConfirmDialogReturn } from "@vueuse/core";
|
||||
import { Ref } from "vue";
|
||||
|
||||
type Store = UseConfirmDialogReturn<any, Boolean, Boolean> & {
|
||||
type Store = UseConfirmDialogReturn<any, boolean, boolean> & {
|
||||
text: Ref<string>;
|
||||
setup: boolean;
|
||||
};
|
||||
|
||||
const store: Partial<Store> = {
|
||||
text: ref('Are you sure you want to delete this item? '),
|
||||
text: ref("Are you sure you want to delete this item? "),
|
||||
setup: false,
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,7 @@ const store: Partial<Store> = {
|
|||
export function useConfirm(): Store {
|
||||
if (!store.setup) {
|
||||
store.setup = true;
|
||||
const { isRevealed, reveal, confirm, cancel } = useConfirmDialog<any, Boolean, Boolean>();
|
||||
const { isRevealed, reveal, confirm, cancel } = useConfirmDialog<any, boolean, boolean>();
|
||||
store.isRevealed = isRevealed;
|
||||
store.reveal = reveal;
|
||||
store.confirm = confirm;
|
||||
|
|
|
@ -1,31 +1,29 @@
|
|||
function slugify(text: string) {
|
||||
return text
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-') // Replace spaces with -
|
||||
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
|
||||
.replace(/\-\-+/g, '-') // Replace multiple - with single -
|
||||
.replace(/^-+/, '') // Trim - from start of text
|
||||
.replace(/-+$/, ''); // Trim - from end of text
|
||||
}
|
||||
|
||||
function idGenerator(): string {
|
||||
const id =
|
||||
Math.random().toString(32).substring(2, 6) +
|
||||
Math.random().toString(36).substring(2, 6);
|
||||
return slugify(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* useFormIds uses the provided label to generate a unique id for the
|
||||
* form element. If no label is provided the id is generated using a
|
||||
* random string.
|
||||
*/
|
||||
export function useFormIds(label: string): string {
|
||||
const slug = label ? slugify(label) : idGenerator();
|
||||
return `${slug}-${idGenerator()}`;
|
||||
}
|
||||
|
||||
export function useId(): string {
|
||||
return idGenerator();
|
||||
}
|
||||
function slugify(text: string) {
|
||||
return text
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, "-") // Replace spaces with -
|
||||
.replace(/[^\w-]+/g, "") // Remove all non-word chars
|
||||
.replace(/--+/g, "-") // Replace multiple - with single -
|
||||
.replace(/^-+/, "") // Trim - from start of text
|
||||
.replace(/-+$/, ""); // Trim - from end of text
|
||||
}
|
||||
|
||||
function idGenerator(): string {
|
||||
const id = Math.random().toString(32).substring(2, 6) + Math.random().toString(36).substring(2, 6);
|
||||
return slugify(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* useFormIds uses the provided label to generate a unique id for the
|
||||
* form element. If no label is provided the id is generated using a
|
||||
* random string.
|
||||
*/
|
||||
export function useFormIds(label: string): string {
|
||||
const slug = label ? slugify(label) : idGenerator();
|
||||
return `${slug}-${idGenerator()}`;
|
||||
}
|
||||
|
||||
export function useId(): string {
|
||||
return idGenerator();
|
||||
}
|
||||
|
|
|
@ -1,57 +1,55 @@
|
|||
import { useId } from './use-ids';
|
||||
import { useId } from "./use-ids";
|
||||
|
||||
interface Notification {
|
||||
id: string;
|
||||
message: string;
|
||||
type: 'success' | 'error' | 'info';
|
||||
id: string;
|
||||
message: string;
|
||||
type: "success" | "error" | "info";
|
||||
}
|
||||
|
||||
const notifications = ref<Notification[]>([]);
|
||||
|
||||
function addNotification(notification: Notification) {
|
||||
notifications.value.unshift(notification);
|
||||
notifications.value.unshift(notification);
|
||||
|
||||
if (notifications.value.length > 4) {
|
||||
notifications.value.pop();
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
// Remove notification with ID
|
||||
notifications.value = notifications.value.filter(
|
||||
n => n.id !== notification.id
|
||||
);
|
||||
}, 5000);
|
||||
}
|
||||
if (notifications.value.length > 4) {
|
||||
notifications.value.pop();
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
// Remove notification with ID
|
||||
notifications.value = notifications.value.filter(n => n.id !== notification.id);
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
export function useNotifications() {
|
||||
return {
|
||||
notifications,
|
||||
dropNotification: (idx: number) => notifications.value.splice(idx, 1),
|
||||
};
|
||||
return {
|
||||
notifications,
|
||||
dropNotification: (idx: number) => notifications.value.splice(idx, 1),
|
||||
};
|
||||
}
|
||||
|
||||
export function useNotifier() {
|
||||
return {
|
||||
success: (message: string) => {
|
||||
addNotification({
|
||||
id: useId(),
|
||||
message,
|
||||
type: 'success',
|
||||
});
|
||||
},
|
||||
error: (message: string) => {
|
||||
addNotification({
|
||||
id: useId(),
|
||||
message,
|
||||
type: 'error',
|
||||
});
|
||||
},
|
||||
info: (message: string) => {
|
||||
addNotification({
|
||||
id: useId(),
|
||||
message,
|
||||
type: 'info',
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
success: (message: string) => {
|
||||
addNotification({
|
||||
id: useId(),
|
||||
message,
|
||||
type: "success",
|
||||
});
|
||||
},
|
||||
error: (message: string) => {
|
||||
addNotification({
|
||||
id: useId(),
|
||||
message,
|
||||
type: "error",
|
||||
});
|
||||
},
|
||||
info: (message: string) => {
|
||||
addNotification({
|
||||
id: useId(),
|
||||
message,
|
||||
type: "info",
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Ref } from 'vue';
|
||||
import { Ref } from "vue";
|
||||
|
||||
export type LocationViewPreferences = {
|
||||
showDetails: boolean;
|
||||
|
@ -11,7 +11,7 @@ export type LocationViewPreferences = {
|
|||
*/
|
||||
export function useViewPreferences(): Ref<LocationViewPreferences> {
|
||||
const results = useLocalStorage(
|
||||
'homebox/preferences/location',
|
||||
"homebox/preferences/location",
|
||||
{
|
||||
showDetails: true,
|
||||
showEmpty: true,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export function truncate(str: string, length: number) {
|
||||
return str.length > length ? str.substring(0, length) + '...' : str;
|
||||
return str.length > length ? str.substring(0, length) + "..." : str;
|
||||
}
|
||||
|
||||
export function capitalize(str: string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue