use eslint for formatting

This commit is contained in:
Hayden 2022-09-09 14:38:45 -08:00
parent beefb88367
commit a8780c942a
55 changed files with 456 additions and 457 deletions

51
frontend/.eslintrc.js Normal file
View file

@ -0,0 +1,51 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:vue/essential",
"plugin:@typescript-eslint/recommended",
"@nuxtjs/eslint-config-typescript",
"plugin:vue/vue3-recommended",
"plugin:prettier/recommended",
],
parserOptions: {
ecmaVersion: "latest",
parser: "@typescript-eslint/parser",
sourceType: "module",
},
plugins: ["vue", "@typescript-eslint"],
rules: {
"vue/multi-word-component-names": "off",
"vue/no-setup-props-destructure": 0,
"vue/no-multiple-template-root": 0,
"no-console": 0,
"vue/no-v-model-argument": 0,
"@typescript-eslint/ban-ts-comment": 0,
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
ignoreRestSiblings: true,
destructuredArrayIgnorePattern: "_",
caughtErrors: "none",
},
],
"prettier/prettier": [
"warn",
{
arrowParens: "avoid",
semi: true,
tabWidth: 2,
useTabs: false,
vueIndentScriptAndStyle: true,
singleQuote: false,
trailingComma: "es5",
printWidth: 120,
},
],
},
};

View file

@ -1,42 +0,0 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:vue/essential",
"plugin:@typescript-eslint/recommended",
"@nuxtjs/eslint-config-typescript",
"plugin:vue/vue3-recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": "latest",
"parser": "@typescript-eslint/parser",
"sourceType": "module"
},
"plugins": ["vue", "@typescript-eslint"],
"rules": {
"vue/multi-word-component-names": "off",
"vue/no-setup-props-destructure": 0,
"vue/no-multiple-template-root": 0,
"no-console": 1,
"vue/no-v-model-argument": 0,
"@typescript-eslint/ban-ts-comment": 0,
"prettier/prettier": [
"warn",
{
"arrowParens": "avoid",
"semi": true,
"tabWidth": 2,
"useTabs": false,
"vueIndentScriptAndStyle": true,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 120
}
]
}
}

View file

@ -1,10 +0,0 @@
{
"arrowParens": "avoid",
"semi": true,
"tabWidth": 2,
"useTabs": false,
"vueIndentScriptAndStyle": true,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 120
}

View file

@ -1,5 +1,5 @@
<script lang="ts" setup>
import { useAuthStore } from '~~/stores/auth';
import { useAuthStore } from "~~/stores/auth";
const authStore = useAuthStore();
const api = useUserApi();
@ -10,16 +10,16 @@
return;
}
navigateTo('/');
navigateTo("/");
}
const links = [
{
name: 'Home',
href: '/home',
name: "Home",
href: "/home",
},
{
name: 'Logout',
name: "Logout",
action: logout,
last: true,
},
@ -33,19 +33,19 @@
const dropdown = [
{
name: 'Item / Asset',
name: "Item / Asset",
action: () => {
modals.item = true;
},
},
{
name: 'Location',
name: "Location",
action: () => {
modals.location = true;
},
},
{
name: 'Label',
name: "Label",
action: () => {
modals.label = true;
},

View file

@ -31,7 +31,7 @@
</template>
<script setup lang="ts">
import { useNotifications } from '@/composables/use-notifier';
import { useNotifications } from "@/composables/use-notifier";
const { notifications, dropNotification } = useNotifications();
</script>

View file

@ -35,7 +35,7 @@
</template>
<script setup lang="ts">
type Sizes = 'sm' | 'md' | 'lg';
type Sizes = "sm" | "md" | "lg";
const props = defineProps({
loading: {
@ -48,7 +48,7 @@
},
size: {
type: String as () => Sizes,
default: 'md',
default: "md",
},
to: {
type: String as () => string | null,

View file

@ -2,7 +2,7 @@
defineProps({
cmp: {
type: String,
default: 'div',
default: "div",
},
});
</script>

View file

@ -15,7 +15,7 @@
</template>
<script setup lang="ts">
const emit = defineEmits(['cancel', 'update:modelValue']);
const emit = defineEmits(["cancel", "update:modelValue"]);
const props = defineProps({
modelValue: {
type: Boolean,
@ -34,12 +34,12 @@
function close() {
if (props.readonly) {
emit('cancel');
emit("cancel");
return;
}
modal.value = false;
}
const modalId = useId();
const modal = useVModel(props, 'modelValue', emit);
const modal = useVModel(props, "modelValue", emit);
</script>

View file

@ -36,7 +36,7 @@
</template>
<script setup lang="ts">
const emit = defineEmits(['update:modelValue', 'update:text']);
const emit = defineEmits(["update:modelValue", "update:text"]);
const props = defineProps({
modelValue: {
@ -50,12 +50,12 @@
},
});
const selected = useVModel(props, 'modelValue', emit);
const selected = useVModel(props, "modelValue", emit);
const dateText = computed(() => {
if (selected.value) {
return selected.value.toLocaleDateString();
}
return '';
return "";
});
const time = ref(new Date());
@ -69,7 +69,7 @@
});
const month = computed(() => {
return time.value.toLocaleString('default', { month: 'long' });
return time.value.toLocaleString("default", { month: "long" });
});
const year = computed(() => {
@ -87,7 +87,7 @@
}
const daysIdx = computed(() => {
return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
return ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
});
function select(e: MouseEvent, day: Date) {
@ -117,7 +117,7 @@
for (let i = 0; i < firstDay; i++) {
days.push({
number: '',
number: "",
date: new Date(),
});
}

View file

@ -6,7 +6,7 @@
<div class="dropdown dropdown-top sm:dropdown-end">
<div tabindex="0" class="w-full min-h-[48px] flex gap-2 p-4 flex-wrap border border-gray-400 rounded-lg">
<span v-for="itm in value" :key="name != '' ? itm[name] : itm" class="badge">
{{ name != '' ? itm[name] : itm }}
{{ name != "" ? itm[name] : itm }}
</span>
</div>
<ul
@ -21,7 +21,7 @@
}"
>
<button type="button" @click="toggle(idx)">
{{ name != '' ? obj[name] : obj }}
{{ name != "" ? obj[name] : obj }}
</button>
</li>
</ul>
@ -30,11 +30,11 @@
</template>
<script lang="ts" setup>
const emit = defineEmits(['update:modelValue']);
const emit = defineEmits(["update:modelValue"]);
const props = defineProps({
label: {
type: String,
default: '',
default: "",
},
modelValue: {
type: Array as () => any[],
@ -46,7 +46,7 @@
},
name: {
type: String,
default: 'name',
default: "name",
},
selectFirst: {
type: Boolean,
@ -77,5 +77,5 @@
}
);
const value = useVModel(props, 'modelValue', emit);
const value = useVModel(props, "modelValue", emit);
</script>

View file

@ -6,7 +6,7 @@
<select v-model="value" class="select select-bordered">
<option disabled selected>Pick one</option>
<option v-for="obj in items" :key="name != '' ? obj[name] : obj" :value="obj">
{{ name != '' ? obj[name] : obj }}
{{ name != "" ? obj[name] : obj }}
</option>
</select>
<!-- <label class="label">
@ -17,11 +17,11 @@
</template>
<script lang="ts" setup>
const emit = defineEmits(['update:modelValue']);
const emit = defineEmits(["update:modelValue"]);
const props = defineProps({
label: {
type: String,
default: '',
default: "",
},
modelValue: {
type: Object as any,
@ -33,7 +33,7 @@
},
name: {
type: String,
default: 'name',
default: "name",
},
selectFirst: {
type: Boolean,
@ -50,5 +50,5 @@
}
);
const value = useVModel(props, 'modelValue', emit);
const value = useVModel(props, "modelValue", emit);
</script>

View file

@ -23,7 +23,7 @@
</template>
<script lang="ts" setup>
const emit = defineEmits(['update:modelValue']);
const emit = defineEmits(["update:modelValue"]);
const props = defineProps({
modelValue: {
type: [String],
@ -35,7 +35,7 @@
},
type: {
type: String,
default: 'text',
default: "text",
},
limit: {
type: [Number, String],
@ -43,7 +43,7 @@
},
placeholder: {
type: String,
default: '',
default: "",
},
inline: {
type: Boolean,
@ -51,7 +51,7 @@
},
});
const value = useVModel(props, 'modelValue', emit);
const value = useVModel(props, "modelValue", emit);
const valueLen = computed(() => {
return value.value ? value.value.length : 0;
});

View file

@ -17,7 +17,7 @@
const props = defineProps({
label: {
type: String,
default: '',
default: "",
},
modelValue: {
type: [String, Number],
@ -25,7 +25,7 @@
},
type: {
type: String,
default: 'text',
default: "text",
},
triggerFocus: {
type: Boolean,
@ -48,5 +48,5 @@
}
);
const value = useVModel(props, 'modelValue');
const value = useVModel(props, "modelValue");
</script>

View file

@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Ref } from 'vue';
import type { IconifyIcon } from '@iconify/vue';
import { Icon as Iconify, loadIcon } from '@iconify/vue';
import type { Ref } from "vue";
import type { IconifyIcon } from "@iconify/vue";
import { Icon as Iconify, loadIcon } from "@iconify/vue";
const nuxtApp = useNuxtApp();
const props = defineProps({
@ -14,12 +14,12 @@
const icon: Ref<IconifyIcon | null> = ref(null);
const component = computed(() => nuxtApp.vueApp.component(props.name));
icon.value = await loadIcon(props.name).catch(_ => null);
icon.value = await loadIcon(props.name).catch(() => null);
watch(
() => props.name,
async () => {
icon.value = await loadIcon(props.name).catch(_ => null);
icon.value = await loadIcon(props.name).catch(() => null);
}
);
</script>

View file

@ -22,7 +22,7 @@
</template>
<script setup lang="ts">
import { Item } from '~~/lib/api/classes/items';
import { Item } from "~~/lib/api/classes/items";
const props = defineProps({
item: {

View file

@ -26,7 +26,7 @@
</template>
<script setup lang="ts">
import { type Location } from '~~/lib/api/classes/locations';
import { type Location } from "~~/lib/api/classes/locations";
const props = defineProps({
modelValue: {
type: Boolean,
@ -36,21 +36,21 @@
const submitBtn = ref(null);
const modal = useVModel(props, 'modelValue');
const modal = useVModel(props, "modelValue");
const loading = ref(false);
const focused = ref(false);
const form = reactive({
location: {} as Location,
name: '',
description: '',
color: '', // Future!
name: "",
description: "",
color: "", // Future!
labels: [],
});
function reset() {
form.name = '';
form.description = '';
form.color = '';
form.name = "";
form.description = "";
form.color = "";
focused.value = false;
modal.value = false;
loading.value = false;
@ -93,7 +93,7 @@
return;
}
toast.success('Item created');
toast.success("Item created");
reset();
}
</script>

View file

@ -1,7 +1,7 @@
<script setup lang="ts">
import { Label } from '~~/lib/api/classes/labels';
import { Label } from "~~/lib/api/classes/labels";
export type sizes = 'sm' | 'md' | 'lg';
export type sizes = "sm" | "md" | "lg";
defineProps({
label: {
type: Object as () => Label,
@ -9,7 +9,7 @@
},
size: {
type: String as () => sizes,
default: 'md',
default: "md",
},
});

View file

@ -25,19 +25,19 @@
},
});
const modal = useVModel(props, 'modelValue');
const modal = useVModel(props, "modelValue");
const loading = ref(false);
const focused = ref(false);
const form = reactive({
name: '',
description: '',
color: '', // Future!
name: "",
description: "",
color: "", // Future!
});
function reset() {
form.name = '';
form.description = '';
form.color = '';
form.name = "";
form.description = "";
form.color = "";
focused.value = false;
modal.value = false;
loading.value = false;
@ -60,7 +60,7 @@
return;
}
toast.success('Label created');
toast.success("Label created");
reset();
}
</script>

View file

@ -26,7 +26,7 @@
</template>
<script lang="ts" setup>
import { Location } from '~~/lib/api/classes/locations';
import { Location } from "~~/lib/api/classes/locations";
defineProps({
location: {

View file

@ -25,12 +25,12 @@
},
});
const modal = useVModel(props, 'modelValue');
const modal = useVModel(props, "modelValue");
const loading = ref(false);
const focused = ref(false);
const form = reactive({
name: '',
description: '',
name: "",
description: "",
});
whenever(
@ -41,8 +41,8 @@
);
function reset() {
form.name = '';
form.description = '';
form.name = "";
form.description = "";
focused.value = false;
modal.value = false;
loading.value = false;
@ -61,7 +61,7 @@
}
if (data) {
toast.success('Location created');
toast.success("Location created");
navigateTo(`/location/${data.id}`);
}

View file

@ -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) {

View file

@ -1,5 +1,5 @@
import { UseConfirmDialogReturn } from '@vueuse/core';
import { Ref } from 'vue';
import { UseConfirmDialogReturn } from "@vueuse/core";
import { Ref } from "vue";
type Store = UseConfirmDialogReturn<any, boolean, boolean> & {
text: Ref<string>;
@ -7,7 +7,7 @@ type Store = UseConfirmDialogReturn<any, boolean, 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,
};

View file

@ -2,11 +2,11 @@ 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
.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 {

View file

@ -1,9 +1,9 @@
import { useId } from './use-ids';
import { useId } from "./use-ids";
interface Notification {
id: string;
message: string;
type: 'success' | 'error' | 'info';
type: "success" | "error" | "info";
}
const notifications = ref<Notification[]>([]);
@ -34,21 +34,21 @@ export function useNotifier() {
addNotification({
id: useId(),
message,
type: 'success',
type: "success",
});
},
error: (message: string) => {
addNotification({
id: useId(),
message,
type: 'error',
type: "error",
});
},
info: (message: string) => {
addNotification({
id: useId(),
message,
type: 'info',
type: "info",
});
},
};

View file

@ -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,

View file

@ -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) {

View file

@ -1,8 +1,8 @@
import { describe, test, expect } from 'vitest';
import { client, userClient } from './test-utils';
import { describe, test, expect } from "vitest";
import { client, userClient } from "./test-utils";
describe('[GET] /api/v1/status', () => {
test('server should respond', async () => {
describe("[GET] /api/v1/status", () => {
test("server should respond", async () => {
const api = client();
const { response, data } = await api.status();
expect(response.status).toBe(200);
@ -10,23 +10,23 @@ describe('[GET] /api/v1/status', () => {
});
});
describe('first time user workflow (register, login)', () => {
describe("first time user workflow (register, login)", () => {
const api = client();
const userData = {
groupName: 'test-group',
groupName: "test-group",
user: {
email: 'test-user@email.com',
name: 'test-user',
password: 'test-password',
email: "test-user@email.com",
name: "test-user",
password: "test-password",
},
};
test('user should be able to register', async () => {
test("user should be able to register", async () => {
const { response } = await api.register(userData);
expect(response.status).toBe(204);
});
test('user should be able to login', async () => {
test("user should be able to login", async () => {
const { response, data } = await api.login(userData.user.email, userData.user.password);
expect(response.status).toBe(200);
expect(data.token).toBeTruthy();

View file

@ -1,24 +1,24 @@
import { beforeAll, expect } from 'vitest';
import { Requests } from '../../requests';
import { overrideParts } from '../base/urls';
import { PublicApi } from '../public';
import * as config from '../../../test/config';
import { UserApi } from '../user';
import { beforeAll, expect } from "vitest";
import { Requests } from "../../requests";
import { overrideParts } from "../base/urls";
import { PublicApi } from "../public";
import * as config from "../../../test/config";
import { UserApi } from "../user";
export function client() {
overrideParts(config.BASE_URL, '/api/v1');
const requests = new Requests('');
overrideParts(config.BASE_URL, "/api/v1");
const requests = new Requests("");
return new PublicApi(requests);
}
export function userClient(token: string) {
overrideParts(config.BASE_URL, '/api/v1');
const requests = new Requests('', token);
overrideParts(config.BASE_URL, "/api/v1");
const requests = new Requests("", token);
return new UserApi(requests);
}
const cache = {
token: '',
token: "",
};
/*
@ -30,11 +30,11 @@ export async function sharedUserClient(): Promise<UserApi> {
return userClient(cache.token);
}
const testUser = {
groupName: 'test-group',
groupName: "test-group",
user: {
email: '__test__@__test__.com',
name: '__test__',
password: '__test__',
email: "__test__@__test__.com",
name: "__test__",
password: "__test__",
},
};

View file

@ -1,9 +1,9 @@
import { describe, expect, test } from 'vitest';
import { Label } from '../../classes/labels';
import { UserApi } from '../../user';
import { sharedUserClient } from '../test-utils';
import { describe, expect, test } from "vitest";
import { Label } from "../../classes/labels";
import { UserApi } from "../../user";
import { sharedUserClient } from "../test-utils";
describe('locations lifecycle (create, update, delete)', () => {
describe("locations lifecycle (create, update, delete)", () => {
let increment = 0;
/**
@ -14,7 +14,7 @@ describe('locations lifecycle (create, update, delete)', () => {
const { response, data } = await api.labels.create({
name: `__test__.label.name_${increment}`,
description: `__test__.label.description_${increment}`,
color: '',
color: "",
});
expect(response.status).toBe(201);
increment++;
@ -26,13 +26,13 @@ describe('locations lifecycle (create, update, delete)', () => {
return [data, cleanup];
}
test('user should be able to create a label', async () => {
test("user should be able to create a label", async () => {
const api = await sharedUserClient();
const labelData = {
name: 'test-label',
description: 'test-description',
color: '',
name: "test-label",
description: "test-description",
color: "",
};
const { response, data } = await api.labels.create(labelData);
@ -53,14 +53,14 @@ describe('locations lifecycle (create, update, delete)', () => {
expect(deleteResponse.status).toBe(204);
});
test('user should be able to update a label', async () => {
test("user should be able to update a label", async () => {
const api = await sharedUserClient();
const [label, cleanup] = await useLabel(api);
const labelData = {
name: 'test-label',
description: 'test-description',
color: '',
name: "test-label",
description: "test-description",
color: "",
};
const { response, data } = await api.labels.update(label.id, labelData);
@ -78,7 +78,7 @@ describe('locations lifecycle (create, update, delete)', () => {
await cleanup();
});
test('user should be able to delete a label', async () => {
test("user should be able to delete a label", async () => {
const api = await sharedUserClient();
const [label, _] = await useLabel(api);

View file

@ -1,9 +1,9 @@
import { describe, expect, test } from 'vitest';
import { Location } from '../../classes/locations';
import { UserApi } from '../../user';
import { sharedUserClient } from '../test-utils';
import { describe, expect, test } from "vitest";
import { Location } from "../../classes/locations";
import { UserApi } from "../../user";
import { sharedUserClient } from "../test-utils";
describe('locations lifecycle (create, update, delete)', () => {
describe("locations lifecycle (create, update, delete)", () => {
let increment = 0;
/**
@ -26,12 +26,12 @@ describe('locations lifecycle (create, update, delete)', () => {
return [data, cleanup];
}
test('user should be able to create a location', async () => {
test("user should be able to create a location", async () => {
const api = await sharedUserClient();
const locationData = {
name: 'test-location',
description: 'test-description',
name: "test-location",
description: "test-description",
};
const { response, data } = await api.locations.create(locationData);
@ -52,13 +52,13 @@ describe('locations lifecycle (create, update, delete)', () => {
expect(deleteResponse.status).toBe(204);
});
test('user should be able to update a location', async () => {
test("user should be able to update a location", async () => {
const api = await sharedUserClient();
const [location, cleanup] = await useLocation(api);
const updateData = {
name: 'test-location-updated',
description: 'test-description-updated',
name: "test-location-updated",
description: "test-description-updated",
};
const { response } = await api.locations.update(location.id, updateData);
@ -75,7 +75,7 @@ describe('locations lifecycle (create, update, delete)', () => {
await cleanup();
});
test('user should be able to delete a location', async () => {
test("user should be able to delete a location", async () => {
const api = await sharedUserClient();
const [location, _] = await useLocation(api);

View file

@ -1,4 +1,4 @@
import { Requests } from '../../requests';
import { Requests } from "../../requests";
// <
// TGetResult,
// TPostData,

View file

@ -1,24 +1,24 @@
import { describe, expect, it } from 'vitest';
import { route } from '.';
import { describe, expect, it } from "vitest";
import { route } from ".";
describe('UrlBuilder', () => {
it('basic query parameter', () => {
const result = route('/test', { a: 'b' });
expect(result).toBe('/api/v1/test?a=b');
describe("UrlBuilder", () => {
it("basic query parameter", () => {
const result = route("/test", { a: "b" });
expect(result).toBe("/api/v1/test?a=b");
});
it('multiple query parameters', () => {
const result = route('/test', { a: 'b', c: 'd' });
expect(result).toBe('/api/v1/test?a=b&c=d');
it("multiple query parameters", () => {
const result = route("/test", { a: "b", c: "d" });
expect(result).toBe("/api/v1/test?a=b&c=d");
});
it('no query parameters', () => {
const result = route('/test');
expect(result).toBe('/api/v1/test');
it("no query parameters", () => {
const result = route("/test");
expect(result).toBe("/api/v1/test");
});
it('list-like query parameters', () => {
const result = route('/test', { a: ['b', 'c'] });
expect(result).toBe('/api/v1/test?a=b&a=c');
it("list-like query parameters", () => {
const result = route("/test", { a: ["b", "c"] });
expect(result).toBe("/api/v1/test?a=b&a=c");
});
});

View file

@ -1,2 +1,2 @@
export { BaseAPI } from './base-api';
export { route } from './urls';
export { BaseAPI } from "./base-api";
export { route } from "./urls";

View file

@ -1,6 +1,6 @@
const parts = {
host: 'http://localhost.com',
prefix: '/api/v1',
host: "http://localhost.com",
prefix: "/api/v1",
};
export function overrideParts(host: string, prefix: string) {
@ -32,5 +32,5 @@ export function route(rest: string, params: Record<string, QueryValue> = {}): st
}
}
return url.toString().replace('http://localhost.com', '');
return url.toString().replace("http://localhost.com", "");
}

View file

@ -1,7 +1,7 @@
import { BaseAPI, route } from '../base';
import { Label } from './labels';
import { Location } from './locations';
import { Results } from './types';
import { BaseAPI, route } from "../base";
import { Label } from "./labels";
import { Location } from "./locations";
import { Results } from "./types";
export interface ItemCreate {
name: string;
@ -36,11 +36,11 @@ export interface Item {
export class ItemsApi extends BaseAPI {
getAll() {
return this.http.get<Results<Item>>({ url: route('/items') });
return this.http.get<Results<Item>>({ url: route("/items") });
}
create(item: ItemCreate) {
return this.http.post<ItemCreate, Item>({ url: route('/items'), body: item });
return this.http.post<ItemCreate, Item>({ url: route("/items"), body: item });
}
async get(id: string) {
@ -68,8 +68,8 @@ export class ItemsApi extends BaseAPI {
import(file: File) {
const formData = new FormData();
formData.append('csv', file);
formData.append("csv", file);
return this.http.post<FormData, void>({ url: route('/items/import'), data: formData });
return this.http.post<FormData, void>({ url: route("/items/import"), data: formData });
}
}

View file

@ -1,6 +1,6 @@
import { BaseAPI, route } from '../base';
import { Item } from './items';
import { Details, OutType, Results } from './types';
import { BaseAPI, route } from "../base";
import { Item } from "./items";
import { Details, OutType, Results } from "./types";
export type LabelCreate = Details & {
color: string;
@ -16,11 +16,11 @@ export type Label = LabelCreate &
export class LabelsApi extends BaseAPI {
getAll() {
return this.http.get<Results<Label>>({ url: route('/labels') });
return this.http.get<Results<Label>>({ url: route("/labels") });
}
create(body: LabelCreate) {
return this.http.post<LabelCreate, Label>({ url: route('/labels'), body });
return this.http.post<LabelCreate, Label>({ url: route("/labels"), body });
}
get(id: string) {

View file

@ -1,6 +1,6 @@
import { BaseAPI, route } from '../base';
import { Item } from './items';
import { Details, OutType, Results } from './types';
import { BaseAPI, route } from "../base";
import { Item } from "./items";
import { Details, OutType, Results } from "./types";
export type LocationCreate = Details;
@ -15,11 +15,11 @@ export type LocationUpdate = LocationCreate;
export class LocationsApi extends BaseAPI {
getAll() {
return this.http.get<Results<Location>>({ url: route('/locations') });
return this.http.get<Results<Location>>({ url: route("/locations") });
}
create(body: LocationCreate) {
return this.http.post<LocationCreate, Location>({ url: route('/locations'), body });
return this.http.post<LocationCreate, Location>({ url: route("/locations"), body });
}
get(id: string) {

View file

@ -1,4 +1,4 @@
import { BaseAPI, route } from './base';
import { BaseAPI, route } from "./base";
export type LoginResult = {
token: string;
@ -28,12 +28,12 @@ export type StatusResult = {
export class PublicApi extends BaseAPI {
public status() {
return this.http.get<StatusResult>({ url: route('/status') });
return this.http.get<StatusResult>({ url: route("/status") });
}
public login(username: string, password: string) {
return this.http.post<LoginPayload, LoginResult>({
url: route('/users/login'),
url: route("/users/login"),
body: {
username,
password,
@ -42,6 +42,6 @@ export class PublicApi extends BaseAPI {
}
public register(body: RegisterPayload) {
return this.http.post<RegisterPayload, LoginResult>({ url: route('/users/register'), body });
return this.http.post<RegisterPayload, LoginResult>({ url: route("/users/register"), body });
}
}

View file

@ -1,8 +1,8 @@
import { BaseAPI, route } from './base';
import { ItemsApi } from './classes/items';
import { LabelsApi } from './classes/labels';
import { LocationsApi } from './classes/locations';
import { Requests } from '~~/lib/requests';
import { BaseAPI, route } from "./base";
import { ItemsApi } from "./classes/items";
import { LabelsApi } from "./classes/labels";
import { LocationsApi } from "./classes/locations";
import { Requests } from "~~/lib/requests";
export type Result<T> = {
item: T;
@ -30,14 +30,14 @@ export class UserApi extends BaseAPI {
}
public self() {
return this.http.get<Result<User>>({ url: route('/users/self') });
return this.http.get<Result<User>>({ url: route("/users/self") });
}
public logout() {
return this.http.post<object, void>({ url: route('/users/logout') });
return this.http.post<object, void>({ url: route("/users/logout") });
}
public deleteAccount() {
return this.http.delete<void>({ url: route('/users/self') });
return this.http.delete<void>({ url: route("/users/self") });
}
}

View file

@ -1 +1 @@
export { Requests, type TResponse } from './requests';
export { Requests, type TResponse } from "./requests";

View file

@ -1,8 +1,8 @@
export enum Method {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
DELETE = 'DELETE',
GET = "GET",
POST = "POST",
PUT = "PUT",
DELETE = "DELETE",
}
export type RequestInterceptor = (r: Response) => void;
@ -40,9 +40,9 @@ export class Requests {
return this.baseUrl + rest;
}
constructor(baseUrl: string, token: string | (() => string) = '', headers: Record<string, string> = {}) {
constructor(baseUrl: string, token: string | (() => string) = "", headers: Record<string, string> = {}) {
this.baseUrl = baseUrl;
this.token = typeof token === 'string' ? () => token : token;
this.token = typeof token === "string" ? () => token : token;
this.headers = headers;
}
@ -72,19 +72,19 @@ export class Requests {
headers: {
...rargs.headers,
...this.headers,
},
} as Record<string, string>,
};
const token = this.token();
if (token !== '' && payload.headers !== undefined) {
payload.headers.Authorization = token;
if (token !== "" && payload.headers !== undefined) {
payload.headers["Authorization"] = token; // eslint-disable-line dot-notation
}
if (this.methodSupportsBody(method)) {
if (rargs.data) {
payload.body = rargs.data;
} else {
payload.headers['Content-Type'] = 'application/json';
payload.headers["Content-Type"] = "application/json";
payload.body = JSON.stringify(rargs.body);
}
}

View file

@ -1,18 +1,18 @@
import { defineNuxtConfig } from 'nuxt';
import { defineNuxtConfig } from "nuxt";
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
target: 'static',
target: "static",
ssr: false,
modules: ['@nuxtjs/tailwindcss', '@pinia/nuxt', '@vueuse/nuxt'],
modules: ["@nuxtjs/tailwindcss", "@pinia/nuxt", "@vueuse/nuxt"],
meta: {
title: 'Homebox',
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.svg' }],
title: "Homebox",
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.svg" }],
},
vite: {
server: {
proxy: {
'/api': 'http://localhost:7745',
"/api": "http://localhost:7745",
},
},
plugins: [],

View file

@ -1,9 +1,9 @@
<script setup lang="ts">
useHead({
title: '404. Not Found',
title: "404. Not Found",
});
definePageMeta({
layout: '404',
layout: "404",
});
</script>

View file

@ -1,24 +1,24 @@
<script setup lang="ts">
definePageMeta({
layout: 'home',
layout: "home",
});
useHead({
title: 'Homebox | Home',
title: "Homebox | Home",
});
const api = useUserApi();
const { data: locations } = useAsyncData('locations', async () => {
const { data: locations } = useAsyncData("locations", async () => {
const { data } = await api.locations.getAll();
return data.items;
});
const { data: labels } = useAsyncData('labels', async () => {
const { data: labels } = useAsyncData("labels", async () => {
const { data } = await api.labels.getAll();
return data.items;
});
const { data: items } = useAsyncData('items', async () => {
const { data: items } = useAsyncData("items", async () => {
const { data } = await api.items.getAll();
return data.items;
});
@ -29,15 +29,15 @@
const stats = [
{
label: 'Locations',
label: "Locations",
value: totalLocations,
},
{
label: 'Items',
label: "Items",
value: totalItems,
},
{
label: 'Labels',
label: "Labels",
value: totalLabels,
},
];
@ -55,7 +55,7 @@
function setFile(e: Event & { target: HTMLInputElement }) {
importCsv.value = e.target.files[0];
console.log('importCsv.value', importCsv.value);
console.log("importCsv.value", importCsv.value);
}
const toast = useNotifier();
@ -74,7 +74,7 @@
const { error } = await api.items.import(importCsv.value);
if (error) {
toast.error('Import failed. Please try again later.');
toast.error("Import failed. Please try again later.");
}
// Reset
@ -138,7 +138,7 @@
>
<div v-for="stat in stats" :key="stat.label" class="px-6 py-5 text-center text-sm font-medium">
<span class="text-gray-900">{{ stat.value.value }}</span>
{{ ' ' }}
{{ " " }}
<span class="text-gray-600">{{ stat.label }}</span>
</div>
</div>

View file

@ -1,43 +1,43 @@
<script setup lang="ts">
import TextField from '@/components/Form/TextField.vue';
import { useNotifier } from '@/composables/use-notifier';
import { usePublicApi } from '@/composables/use-api';
import { useAuthStore } from '~~/stores/auth';
import TextField from "@/components/Form/TextField.vue";
import { useNotifier } from "@/composables/use-notifier";
import { usePublicApi } from "@/composables/use-api";
import { useAuthStore } from "~~/stores/auth";
useHead({
title: 'Homebox | Organize and Tag Your Stuff',
title: "Homebox | Organize and Tag Your Stuff",
});
definePageMeta({
layout: 'empty',
layout: "empty",
});
const authStore = useAuthStore();
if (!authStore.isTokenExpired) {
navigateTo('/home');
navigateTo("/home");
}
const registerFields = [
{
label: "What's your name?",
value: '',
value: "",
},
{
label: "What's your email?",
value: '',
value: "",
},
{
label: 'Name your group',
value: '',
label: "Name your group",
value: "",
},
{
label: 'Set your password',
value: '',
type: 'password',
label: "Set your password",
value: "",
type: "password",
},
{
label: 'Confirm your password',
value: '',
type: 'password',
label: "Confirm your password",
value: "",
type: "password",
},
];
@ -57,11 +57,11 @@
});
if (error) {
toast.error('Problem registering user');
toast.error("Problem registering user");
return;
}
toast.success('User registered');
toast.success("User registered");
loading.value = false;
loginFields[0].value = registerFields[1].value;
@ -70,13 +70,13 @@
const loginFields = [
{
label: 'Email',
value: '',
label: "Email",
value: "",
},
{
label: 'Password',
value: '',
type: 'password',
label: "Password",
value: "",
type: "password",
},
];
@ -88,16 +88,16 @@
const { data, error } = await api.login(loginFields[0].value, loginFields[1].value);
if (error) {
toast.error('Invalid email or password');
toast.error("Invalid email or password");
} else {
toast.success('Logged in successfully');
toast.success("Logged in successfully");
authStore.$patch({
token: data.token,
expires: data.expiresAt,
});
navigateTo('/home');
navigateTo("/home");
}
loading.value = false;
}
@ -207,7 +207,7 @@
class="text-base-content text-lg hover:bg-primary hover:text-primary-content px-3 py-1 rounded-xl transition-colors duration-200"
@click="toggleLogin"
>
{{ registerForm ? 'Already a User? Login' : 'Not a User? Register' }}
{{ registerForm ? "Already a User? Login" : "Not a User? Register" }}
</button>
</div>
</div>

View file

@ -1,6 +1,6 @@
<script setup lang="ts">
definePageMeta({
layout: 'home',
layout: "home",
});
const route = useRoute();
@ -12,85 +12,85 @@
const { data: item } = useAsyncData(async () => {
const { data, error } = await api.items.get(itemId.value);
if (error) {
toast.error('Failed to load item');
navigateTo('/home');
toast.error("Failed to load item");
navigateTo("/home");
return;
}
return data;
});
type FormField = {
type: 'text' | 'textarea' | 'select' | 'date';
type: "text" | "textarea" | "select" | "date";
label: string;
ref: string;
};
const mainFields: FormField[] = [
{
type: 'text',
label: 'Name',
ref: 'name',
type: "text",
label: "Name",
ref: "name",
},
{
type: 'textarea',
label: 'Description',
ref: 'description',
type: "textarea",
label: "Description",
ref: "description",
},
{
type: 'text',
label: 'Serial Number',
ref: 'serialNumber',
type: "text",
label: "Serial Number",
ref: "serialNumber",
},
{
type: 'text',
label: 'Model Number',
ref: 'modelNumber',
type: "text",
label: "Model Number",
ref: "modelNumber",
},
{
type: 'text',
label: 'Manufacturer',
ref: 'manufacturer',
type: "text",
label: "Manufacturer",
ref: "manufacturer",
},
{
type: 'textarea',
label: 'Notes',
ref: 'notes',
type: "textarea",
label: "Notes",
ref: "notes",
},
];
const purchaseFields: FormField[] = [
{
type: 'text',
label: 'Purchased From',
ref: 'purchaseFrom',
type: "text",
label: "Purchased From",
ref: "purchaseFrom",
},
{
type: 'text',
label: 'Purchased Price',
ref: 'purchasePrice',
type: "text",
label: "Purchased Price",
ref: "purchasePrice",
},
{
type: 'date',
label: 'Purchased At',
ref: 'purchaseTime',
type: "date",
label: "Purchased At",
ref: "purchaseTime",
},
];
const soldFields = [
{
type: 'text',
label: 'Sold To',
ref: 'soldTo',
type: "text",
label: "Sold To",
ref: "soldTo",
},
{
type: 'text',
label: 'Sold Price',
ref: 'soldPrice',
type: "text",
label: "Sold Price",
ref: "soldPrice",
},
{
type: 'date',
label: 'Sold At',
ref: 'soldTime',
type: "date",
label: "Sold At",
ref: "soldTime",
},
];
</script>

View file

@ -1,6 +1,6 @@
<script setup lang="ts">
definePageMeta({
layout: 'home',
layout: "home",
});
const route = useRoute();
@ -13,8 +13,8 @@
const { data: item } = useAsyncData(async () => {
const { data, error } = await api.items.get(itemId.value);
if (error) {
toast.error('Failed to load item');
navigateTo('/home');
toast.error("Failed to load item");
navigateTo("/home");
return;
}
return data;
@ -22,12 +22,12 @@
const itemSummary = computed(() => {
return {
Description: item.value?.description || '',
'Serial Number': item.value?.serialNumber || '',
'Model Number': item.value?.modelNumber || '',
Manufacturer: item.value?.manufacturer || '',
Notes: item.value?.notes || '',
Attachments: '', // TODO: Attachments
Description: item.value?.description || "",
"Serial Number": item.value?.serialNumber || "",
"Model Number": item.value?.modelNumber || "",
Manufacturer: item.value?.manufacturer || "",
Notes: item.value?.notes || "",
Attachments: "", // TODO: Attachments
};
});
@ -42,12 +42,12 @@
const payload = {};
if (item.value.lifetimeWarranty) {
payload['Lifetime Warranty'] = 'Yes';
payload["Lifetime Warranty"] = "Yes";
} else {
payload['Warranty Expires'] = item.value?.warrantyExpires || '';
payload["Warranty Expires"] = item.value?.warrantyExpires || "";
}
payload['Warranty Details'] = item.value?.warrantyDetails || '';
payload["Warranty Details"] = item.value?.warrantyDetails || "";
return payload;
});
@ -61,9 +61,9 @@
const purchaseDetails = computed(() => {
return {
'Purchased From': item.value?.purchaseFrom || '',
'Purchased Price': item.value?.purchasePrice || '',
'Purchased At': item.value?.purchaseTime || '',
"Purchased From": item.value?.purchaseFrom || "",
"Purchased Price": item.value?.purchasePrice || "",
"Purchased At": item.value?.purchaseTime || "",
};
});
@ -77,16 +77,16 @@
const soldDetails = computed(() => {
return {
'Sold To': item.value?.soldTo || '',
'Sold Price': item.value?.soldPrice || '',
'Sold At': item.value?.soldTime || '',
"Sold To": item.value?.soldTo || "",
"Sold Price": item.value?.soldPrice || "",
"Sold At": item.value?.soldTime || "",
};
});
const confirm = useConfirm();
async function deleteItem() {
const confirmed = await confirm.reveal('Are you sure you want to delete this item?');
const confirmed = await confirm.reveal("Are you sure you want to delete this item?");
if (!confirmed.data) {
return;
@ -94,11 +94,11 @@
const { error } = await api.items.delete(itemId.value);
if (error) {
toast.error('Failed to delete item');
toast.error("Failed to delete item");
return;
}
toast.success('Item deleted');
navigateTo('/home');
toast.success("Item deleted");
navigateTo("/home");
}
</script>

View file

@ -1,6 +1,6 @@
<script setup>
definePageMeta({
layout: 'home',
layout: "home",
});
const show = reactive({
@ -11,29 +11,29 @@
});
const form = reactive({
name: '',
description: '',
notes: '',
name: "",
description: "",
notes: "",
// Item Identification
serialNumber: '',
modelNumber: '',
manufacturer: '',
serialNumber: "",
modelNumber: "",
manufacturer: "",
// Purchase Information
purchaseTime: '',
purchasePrice: '',
purchaseFrom: '',
purchaseTime: "",
purchasePrice: "",
purchaseFrom: "",
// Sold Information
soldTime: '',
soldPrice: '',
soldTo: '',
soldNotes: '',
soldTime: "",
soldPrice: "",
soldTo: "",
soldNotes: "",
});
function submit() {
console.log('Submitted!');
console.log("Submitted!");
}
</script>

View file

@ -1,8 +1,8 @@
<script setup lang="ts">
import ActionsDivider from '../../components/Base/ActionsDivider.vue';
import ActionsDivider from "../../components/Base/ActionsDivider.vue";
definePageMeta({
layout: 'home',
layout: "home",
});
const route = useRoute();
@ -16,8 +16,8 @@
const { data: label } = useAsyncData(labelId.value, async () => {
const { data, error } = await api.labels.get(labelId.value);
if (error) {
toast.error('Failed to load label');
navigateTo('/home');
toast.error("Failed to load label");
navigateTo("/home");
return;
}
return data;
@ -25,25 +25,25 @@
function maybeTimeAgo(date?: string): string {
if (!date) {
return '??';
return "??";
}
const time = new Date(date);
return `${useTimeAgo(time).value} (${useDateFormat(time, 'MM-DD-YYYY').value})`;
return `${useTimeAgo(time).value} (${useDateFormat(time, "MM-DD-YYYY").value})`;
}
const details = computed(() => {
const dt = {
Name: label.value?.name || '',
Description: label.value?.description || '',
Name: label.value?.name || "",
Description: label.value?.description || "",
};
if (preferences.value.showDetails) {
dt['Created At'] = maybeTimeAgo(label.value?.createdAt);
dt['Updated At'] = maybeTimeAgo(label.value?.updatedAt);
dt['Database ID'] = label.value?.id || '';
dt['Group Id'] = label.value?.groupId || '';
dt["Created At"] = maybeTimeAgo(label.value?.createdAt);
dt["Updated At"] = maybeTimeAgo(label.value?.updatedAt);
dt["Database ID"] = label.value?.id || "";
dt["Group Id"] = label.value?.groupId || "";
}
return dt;
@ -52,7 +52,7 @@
const { reveal } = useConfirm();
async function confirmDelete() {
const { isCanceled } = await reveal('Are you sure you want to delete this label? This action cannot be undone.');
const { isCanceled } = await reveal("Are you sure you want to delete this label? This action cannot be undone.");
if (isCanceled) {
return;
@ -61,24 +61,24 @@
const { error } = await api.labels.delete(labelId.value);
if (error) {
toast.error('Failed to delete label');
toast.error("Failed to delete label");
return;
}
toast.success('Label deleted');
navigateTo('/home');
toast.success("Label deleted");
navigateTo("/home");
}
const updateModal = ref(false);
const updating = ref(false);
const updateData = reactive({
name: '',
description: '',
color: '',
name: "",
description: "",
color: "",
});
function openUpdate() {
updateData.name = label.value?.name || '';
updateData.description = label.value?.description || '';
updateData.name = label.value?.name || "";
updateData.description = label.value?.description || "";
updateModal.value = true;
}
@ -87,11 +87,11 @@
const { error, data } = await api.labels.update(labelId.value, updateData);
if (error) {
toast.error('Failed to update label');
toast.error("Failed to update label");
return;
}
toast.success('Label updated');
toast.success("Label updated");
label.value = data;
updateModal.value = false;
updating.value = false;
@ -112,7 +112,7 @@
</BaseModal>
<section>
<BaseSectionHeader class="mb-5" dark>
{{ label ? label.name : '' }}
{{ label ? label.name : "" }}
</BaseSectionHeader>
<BaseDetails class="mb-2" :details="details">
<template #title> Label Details </template>

View file

@ -1,8 +1,8 @@
<script setup lang="ts">
import ActionsDivider from '../../components/Base/ActionsDivider.vue';
import ActionsDivider from "../../components/Base/ActionsDivider.vue";
definePageMeta({
layout: 'home',
layout: "home",
});
const route = useRoute();
@ -16,8 +16,8 @@
const { data: location } = useAsyncData(locationId.value, async () => {
const { data, error } = await api.locations.get(locationId.value);
if (error) {
toast.error('Failed to load location');
navigateTo('/home');
toast.error("Failed to load location");
navigateTo("/home");
return;
}
return data;
@ -25,25 +25,25 @@
function maybeTimeAgo(date?: string): string {
if (!date) {
return '??';
return "??";
}
const time = new Date(date);
return `${useTimeAgo(time).value} (${useDateFormat(time, 'MM-DD-YYYY').value})`;
return `${useTimeAgo(time).value} (${useDateFormat(time, "MM-DD-YYYY").value})`;
}
const details = computed(() => {
const dt = {
Name: location.value?.name || '',
Description: location.value?.description || '',
Name: location.value?.name || "",
Description: location.value?.description || "",
};
if (preferences.value.showDetails) {
dt['Created At'] = maybeTimeAgo(location.value?.createdAt);
dt['Updated At'] = maybeTimeAgo(location.value?.updatedAt);
dt['Database ID'] = location.value?.id || '';
dt['Group Id'] = location.value?.groupId || '';
dt["Created At"] = maybeTimeAgo(location.value?.createdAt);
dt["Updated At"] = maybeTimeAgo(location.value?.updatedAt);
dt["Database ID"] = location.value?.id || "";
dt["Group Id"] = location.value?.groupId || "";
}
return dt;
@ -52,7 +52,7 @@
const { reveal } = useConfirm();
async function confirmDelete() {
const { isCanceled } = await reveal('Are you sure you want to delete this location? This action cannot be undone.');
const { isCanceled } = await reveal("Are you sure you want to delete this location? This action cannot be undone.");
if (isCanceled) {
return;
@ -61,23 +61,23 @@
const { error } = await api.locations.delete(locationId.value);
if (error) {
toast.error('Failed to delete location');
toast.error("Failed to delete location");
return;
}
toast.success('Location deleted');
navigateTo('/home');
toast.success("Location deleted");
navigateTo("/home");
}
const updateModal = ref(false);
const updating = ref(false);
const updateData = reactive({
name: '',
description: '',
name: "",
description: "",
});
function openUpdate() {
updateData.name = location.value?.name || '';
updateData.description = location.value?.description || '';
updateData.name = location.value?.name || "";
updateData.description = location.value?.description || "";
updateModal.value = true;
}
@ -86,11 +86,11 @@
const { error, data } = await api.locations.update(locationId.value, updateData);
if (error) {
toast.error('Failed to update location');
toast.error("Failed to update location");
return;
}
toast.success('Location updated');
toast.success("Location updated");
location.value = data;
updateModal.value = false;
updating.value = false;
@ -111,7 +111,7 @@
</BaseModal>
<section>
<BaseSectionHeader class="mb-5" dark>
{{ location ? location.name : '' }}
{{ location ? location.name : "" }}
</BaseSectionHeader>
<BaseDetails class="mb-2" :details="details">
<template #title> Location Details </template>

View file

@ -1,11 +1,11 @@
import { defineStore } from 'pinia';
import { useLocalStorage } from '@vueuse/core';
import { UserApi } from '~~/lib/api/user';
import { defineStore } from "pinia";
import { useLocalStorage } from "@vueuse/core";
import { UserApi } from "~~/lib/api/user";
export const useAuthStore = defineStore('auth', {
export const useAuthStore = defineStore("auth", {
state: () => ({
token: useLocalStorage('pinia/auth/token', ''),
expires: useLocalStorage('pinia/auth/expires', ''),
token: useLocalStorage("pinia/auth/token", ""),
expires: useLocalStorage("pinia/auth/expires", ""),
}),
getters: {
isTokenExpired: state => {
@ -13,7 +13,7 @@ export const useAuthStore = defineStore('auth', {
return true;
}
if (typeof state.expires === 'string') {
if (typeof state.expires === "string") {
return new Date(state.expires) < new Date();
}
@ -28,8 +28,8 @@ export const useAuthStore = defineStore('auth', {
return result;
}
this.token = '';
this.expires = '';
this.token = "";
this.expires = "";
return result;
},
@ -38,9 +38,9 @@ export const useAuthStore = defineStore('auth', {
* must clear it's local session, usually when a 401 is received.
*/
clearSession() {
this.token = '';
this.expires = '';
navigateTo('/');
this.token = "";
this.expires = "";
navigateTo("/");
},
},
});

View file

@ -1,11 +1,11 @@
module.exports = {
content: ['./app.vue', './{components,pages,layouts}/**/*.{vue,js,ts,jsx,tsx}'],
darkMode: 'class', // or 'media' or 'class'
content: ["./app.vue", "./{components,pages,layouts}/**/*.{vue,js,ts,jsx,tsx}"],
darkMode: "class", // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [require('@tailwindcss/aspect-ratio'), require('@tailwindcss/typography'), require('daisyui')],
plugins: [require("@tailwindcss/aspect-ratio"), require("@tailwindcss/typography"), require("daisyui")],
};

View file

@ -1,3 +1,3 @@
export const PORT = '7745';
export const HOST = 'http://127.0.0.1';
export const BASE_URL = HOST + ':' + PORT;
export const PORT = "7745";
export const HOST = "http://127.0.0.1";
export const BASE_URL = HOST + ":" + PORT;

View file

@ -1,8 +1,8 @@
import { exec } from 'child_process';
import * as config from './config';
import { exec } from "child_process";
import * as config from "./config";
export const setup = () => {
console.log('Starting Client Tests');
console.log("Starting Client Tests");
console.log({
PORT: config.PORT,
HOST: config.HOST,
@ -12,8 +12,8 @@ export const setup = () => {
export const teardown = () => {
if (process.env.TEST_SHUTDOWN_API_SERVER) {
const pc = exec('pkill -SIGTERM api'); // Kill background API process
pc.stdout.on('data', data => {
const pc = exec("pkill -SIGTERM api"); // Kill background API process
pc.stdout.on("data", data => {
console.log(`stdout: ${data}`);
});
}

View file

@ -1,8 +1,8 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import { defineConfig } from "vite";
export default defineConfig({
test: {
globalSetup: './test/setup.ts',
globalSetup: "./test/setup.ts",
},
});