Skip to content

Commit

Permalink
feat: type + lint improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-guan committed Sep 22, 2023
1 parent e68e218 commit ca81c07
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 221 deletions.
12 changes: 0 additions & 12 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions components/app/home/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const state = reactive({
showLoginScreen: false,
})
watchEffect(() => {
watch([authLoaded, auth], (values) => {
setTimeout(() => { // This shows too fast, so it's better to lag for 1 second to prevent jarring layout changes
state.showLoginScreen = authLoaded.value && !auth.value
state.showLoginScreen = values[0] && !values[1]
}, 1000)
})
</script>
Expand Down
4 changes: 2 additions & 2 deletions composables/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export const $api = $fetch.create({

type ApiFetchRequest<T> = Ref<T> | T | (() => T)

export function useApiFetch<ReqT extends string, ResT>(request: ApiFetchRequest<ReqT>, options: UseFetchOptions<ResT> = {}) {
export function useApiFetch<ResT, ReqT extends string = string>(request: ApiFetchRequest<ReqT>, options: UseFetchOptions<ResT> = {}) {
const defaults: UseFetchOptions<ResT> = {
$fetch: $api,
}
const params = defu(options, defaults)
return useFetch(request, params)
}

export function useLazyApiFetch<ReqT extends string, ResT>(request: ApiFetchRequest<ReqT>, options: Omit<UseFetchOptions<ResT>, 'lazy'> = {}) {
export function useLazyApiFetch<ResT, ReqT extends string = string>(request: ApiFetchRequest<ReqT>, options: Omit<UseFetchOptions<ResT>, 'lazy'> = {}) {
const defaults: UseFetchOptions<ResT> = {
$fetch: $api,
}
Expand Down
4 changes: 3 additions & 1 deletion composables/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { User } from '~/shared/types'

export function useUser() {
const auth = useCurrentUser()
return useApiFetch(() => `/api/user/${auth.value?.uid}`, { immediate: false, watch: [() => auth.value?.uid] })
return useApiFetch<User>(() => `/api/user/${auth.value?.uid}`, { immediate: false, watch: [() => auth.value?.uid] })
}
15 changes: 15 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import antfu from '@antfu/eslint-config'

export default antfu({
stylistic: true, // enable stylistic formatting rules
typescript: true,
vue: true,
}, {
rules: {
// https://github.com/antfu/eslint-config/pull/214
'n/prefer-global/process': [
'off',
'never',
],
},
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"pwa:generate-assets": "pwa-assets-generator --preset minimal public/logo.png"
},
"devDependencies": {
"@antfu/eslint-config": "^0.42.0",
"@antfu/eslint-config": "latest",
"@libsql/client": "^0.3.4",
"@nuxt/devtools": "latest",
"@paralleldrive/cuid2": "^2.2.2",
Expand Down
Loading

0 comments on commit ca81c07

Please sign in to comment.