refactor: organize the import format

This commit is contained in:
mutoe 2021-02-27 18:02:05 +08:00
parent fd62cef075
commit 8fefc74448
32 changed files with 93 additions and 129 deletions

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
root = true
[*]
indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

View File

@ -1,7 +1,7 @@
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import registerGlobalComponents from 'src/plugins/global-components'
import { router } from 'src/router'
import AppFooter from './AppFooter.vue' import AppFooter from './AppFooter.vue'
import registerGlobalComponents from '../plugins/global-components'
import { router } from '../router'
describe('# AppFooter', () => { describe('# AppFooter', () => {
beforeEach(async () => { beforeEach(async () => {

View File

@ -1,6 +1,6 @@
import AppLink from './AppLink.vue'
import { router } from '../router'
import { flushPromises, mount } from '@vue/test-utils' import { flushPromises, mount } from '@vue/test-utils'
import { router } from 'src/router'
import AppLink from './AppLink.vue'
describe('# AppLink', function () { describe('# AppLink', function () {
beforeEach(async () => { beforeEach(async () => {

View File

@ -9,10 +9,9 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import type { RouteParams } from 'vue-router' import type { AppRouteNames } from 'src/router'
import type { AppRouteNames } from '../router'
import { defineComponent, PropType } from 'vue' import { defineComponent, PropType } from 'vue'
import type { RouteParams } from 'vue-router'
import { RouterLink } from 'vue-router' import { RouterLink } from 'vue-router'
export default defineComponent({ export default defineComponent({

View File

@ -32,13 +32,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, computed } from 'vue' import type { AppRouteNames } from 'src/router'
import { user } from 'src/store/user'
import { computed, defineComponent } from 'vue'
import type { RouteParams } from 'vue-router' import type { RouteParams } from 'vue-router'
import type { AppRouteNames } from '../router'
import { user } from '../store/user'
interface NavLink { interface NavLink {
name: AppRouteNames name: AppRouteNames
params?: Partial<RouteParams> params?: Partial<RouteParams>

View File

@ -14,8 +14,8 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, computed, toRefs } from 'vue' import { limit } from 'src/services'
import { limit } from '../services' import { computed, defineComponent, toRefs } from 'vue'
export default defineComponent({ export default defineComponent({
name: 'AppPagination', name: 'AppPagination',

View File

@ -43,13 +43,11 @@
<script lang="ts"> <script lang="ts">
import DOMPurify from 'dompurify' import DOMPurify from 'dompurify'
import md2html from 'marked' import md2html from 'marked'
import { getArticle } from 'src/services/article/getArticle'
import { computed, defineComponent, reactive } from 'vue' import { computed, defineComponent, reactive } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import ArticleDetailMeta from './ArticleDetailMeta.vue' import ArticleDetailMeta from './ArticleDetailMeta.vue'
import { getArticle } from '../services/article/getArticle'
export default defineComponent({ export default defineComponent({
name: 'ArticleDetail', name: 'ArticleDetail',
components: { components: {

View File

@ -14,16 +14,13 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { getCommentsByArticle } from 'src/services/comment/getComments'
import { deleteComment } from 'src/services/comment/postComment'
import { user } from 'src/store/user'
import { computed, defineComponent, ref } from 'vue' import { computed, defineComponent, ref } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import ArticleDetailCommentsForm from './ArticleDetailCommentsForm.vue'
import ArticleDetailComment from './ArticleDetailComment.vue' import ArticleDetailComment from './ArticleDetailComment.vue'
import ArticleDetailCommentsForm from './ArticleDetailCommentsForm.vue'
import { getCommentsByArticle } from '../services/comment/getComments'
import { deleteComment } from '../services/comment/postComment'
import { user } from '../store/user'
export default defineComponent({ export default defineComponent({
name: 'ArticleDetailComments', name: 'ArticleDetailComments',

View File

@ -60,16 +60,13 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { useFavoriteArticle } from 'src/composable/useFavoriteArticle'
import { useFollow } from 'src/composable/useFollowProfile'
import { routerPush } from 'src/router'
import { deleteArticle } from 'src/services/article/deleteArticle'
import { checkAuthorization, user } from 'src/store/user'
import { computed, defineComponent, PropType, toRefs } from 'vue' import { computed, defineComponent, PropType, toRefs } from 'vue'
import { deleteArticle } from '../services/article/deleteArticle'
import { useFavoriteArticle } from '../composable/useFavoriteArticle'
import { useFollow } from '../composable/useFollowProfile'
import { user, checkAuthorization } from '../store/user'
import { routerPush } from '../router'
export default defineComponent({ export default defineComponent({
name: 'ArticleDetailMeta', name: 'ArticleDetailMeta',
props: { props: {

View File

@ -34,13 +34,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { useArticles } from 'src/composable/useArticles'
import { defineComponent } from 'vue' import { defineComponent } from 'vue'
import ArticlesListNavigation from './ArticlesListNavigation.vue'
import ArticlesListArticlePreview from './ArticlesListArticlePreview.vue'
import AppPagination from './AppPagination.vue' import AppPagination from './AppPagination.vue'
import ArticlesListArticlePreview from './ArticlesListArticlePreview.vue'
import { useArticles } from '../composable/useArticles' import ArticlesListNavigation from './ArticlesListNavigation.vue'
export default defineComponent({ export default defineComponent({
name: 'ArticlesList', name: 'ArticlesList',

View File

@ -50,8 +50,8 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { useFavoriteArticle } from 'src/composable/useFavoriteArticle'
import { computed, defineComponent, PropType } from 'vue' import { computed, defineComponent, PropType } from 'vue'
import { useFavoriteArticle } from '../composable/useFavoriteArticle'
export default defineComponent({ export default defineComponent({
name: 'ArticlesListArticlePreview', name: 'ArticlesListArticlePreview',

View File

@ -23,13 +23,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import type { ArticlesType } from 'src/composable/useArticles'
import type { AppRouteNames } from 'src/router'
import { isAuthorized } from 'src/store/user'
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import type { RouteParams } from 'vue-router' import type { RouteParams } from 'vue-router'
import type { AppRouteNames } from '../router'
import type { ArticlesType } from '../composable/useArticles'
import { isAuthorized } from '../store/user'
interface ArticlesListNavLink { interface ArticlesListNavLink {
name: ArticlesType name: ArticlesType

View File

@ -16,7 +16,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue' import { defineComponent } from 'vue'
import { useTags } from '../composable/useTags' import { useTags } from 'src/composable/useTags'
export default defineComponent({ export default defineComponent({
name: 'PopularTags', name: 'PopularTags',

View File

@ -1,16 +1,14 @@
import { computed, ComputedRef, ref, watch } from 'vue' import type { AppRouteNames } from 'src/router'
import { useRoute } from 'vue-router'
import type { AppRouteNames } from '../router'
import createAsyncProcess from '../utils/create-async-process'
import { import {
getArticles, getArticles,
getFavoritedArticles,
getProfileArticles,
getFeeds,
getArticlesByTag, getArticlesByTag,
} from '../services/article/getArticles' getFavoritedArticles,
getFeeds,
getProfileArticles,
} from 'src/services/article/getArticles'
import createAsyncProcess from 'src/utils/create-async-process'
import { computed, ComputedRef, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export function useArticles () { export function useArticles () {

View File

@ -1,12 +1,9 @@
import { routerPush } from 'src/router'
import { deleteFavoriteArticle, postFavoriteArticle } from 'src/services/article/favoriteArticle'
import type { AuthorizationError } from 'src/types/error'
import createAsyncProcess from 'src/utils/create-async-process'
import type { Either } from 'src/utils/either'
import { ComputedRef } from 'vue' import { ComputedRef } from 'vue'
import { routerPush } from '../router'
import type { AuthorizationError } from '../types/error'
import { deleteFavoriteArticle, postFavoriteArticle } from '../services/article/favoriteArticle'
import type { Either } from '../utils/either'
import createAsyncProcess from '../utils/create-async-process'
interface useFavoriteArticleProps { interface useFavoriteArticleProps {
isFavorited: ComputedRef<boolean> isFavorited: ComputedRef<boolean>

View File

@ -1,12 +1,9 @@
import { routerPush } from 'src/router'
import { deleteFollowProfile, postFollowProfile } from 'src/services/profile/followProfile'
import type { AuthorizationError } from 'src/types/error'
import createAsyncProcess from 'src/utils/create-async-process'
import type { Either } from 'src/utils/either'
import type { ComputedRef } from 'vue' import type { ComputedRef } from 'vue'
import { routerPush } from '../router'
import type { AuthorizationError } from '../types/error'
import type { Either } from '../utils/either'
import createAsyncProcess from '../utils/create-async-process'
import { postFollowProfile, deleteFollowProfile } from '../services/profile/followProfile'
interface UseFollowProps { interface UseFollowProps {
username: ComputedRef<string> username: ComputedRef<string>

View File

@ -1,7 +1,6 @@
import { getProfile } from 'src/services/profile/getProfile'
import { ComputedRef, ref, watch } from 'vue' import { ComputedRef, ref, watch } from 'vue'
import { getProfile } from '../services/profile/getProfile'
interface UseProfileProps { interface UseProfileProps {
username: ComputedRef<string> username: ComputedRef<string>
} }

View File

@ -1,7 +1,6 @@
import { getAllTags } from 'src/services/tag/getTags'
import { ref } from 'vue' import { ref } from 'vue'
import { getAllTags } from '../services/tag/getTags'
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export function useTags () { export function useTags () {
const tags = ref<string[]>([]) const tags = ref<string[]>([])

View File

@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import { router } from 'src/router'
import Article from './Article.vue' import Article from './Article.vue'
import { router } from '../router'
describe('# Article', () => { describe('# Article', () => {
beforeEach(async () => { beforeEach(async () => {

View File

@ -29,11 +29,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import ArticleDetail from 'src/components/ArticleDetail.vue'
import ArticleDetailComments from 'src/components/ArticleDetailComments.vue'
import { defineComponent } from 'vue' import { defineComponent } from 'vue'
import ArticleDetail from '../components/ArticleDetail.vue'
import ArticleDetailComments from '../components/ArticleDetailComments.vue'
export default defineComponent({ export default defineComponent({
name: 'ArticlePage', name: 'ArticlePage',
components: { components: {

View File

@ -66,10 +66,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { getArticle } from 'src/services/article/getArticle'
import { postArticle, putArticle } from 'src/services/article/postArticle'
import { computed, defineComponent, onMounted, reactive, ref } from 'vue' import { computed, defineComponent, onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { getArticle } from '../services/article/getArticle'
import { postArticle, putArticle } from '../services/article/postArticle'
interface FormState { interface FormState {
title: string; title: string;

View File

@ -44,11 +44,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import ArticlesList from 'src/components/ArticlesList.vue'
import PopularTags from 'src/components/PopularTags.vue'
import { defineComponent } from 'vue' import { defineComponent } from 'vue'
import ArticlesList from '../components/ArticlesList.vue'
import PopularTags from '../components/PopularTags.vue'
export default defineComponent({ export default defineComponent({
name: 'HomePage', name: 'HomePage',
components: { components: {

View File

@ -61,12 +61,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { routerPush } from 'src/router'
import { postLogin, PostLoginErrors, PostLoginForm } from 'src/services/auth/postLogin'
import { updateUser } from 'src/store/user'
import { defineComponent, reactive, ref } from 'vue' import { defineComponent, reactive, ref } from 'vue'
import { routerPush } from '../router'
import { postLogin, PostLoginForm, PostLoginErrors } from '../services/auth/postLogin'
import { updateUser } from '../store/user'
export default defineComponent({ export default defineComponent({
name: 'LoginPage', name: 'LoginPage',

View File

@ -67,16 +67,13 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import ArticlesList from 'src/components/ArticlesList.vue'
import { useFollow } from 'src/composable/useFollowProfile'
import { useProfile } from 'src/composable/useProfile'
import { checkAuthorization, user } from 'src/store/user'
import { computed, defineComponent } from 'vue' import { computed, defineComponent } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import ArticlesList from '../components/ArticlesList.vue'
import { useProfile } from '../composable/useProfile'
import { useFollow } from '../composable/useFollowProfile'
import { user, checkAuthorization } from '../store/user'
export default defineComponent({ export default defineComponent({
name: 'ProfilePage', name: 'ProfilePage',
components: { components: {

View File

@ -68,12 +68,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { routerPush } from 'src/router'
import { postRegister, PostRegisterErrors, PostRegisterForm } from 'src/services/auth/postRegister'
import { updateUser } from 'src/store/user'
import { defineComponent, reactive, ref } from 'vue' import { defineComponent, reactive, ref } from 'vue'
import { routerPush } from '../router'
import { postRegister, PostRegisterForm, PostRegisterErrors } from '../services/auth/postRegister'
import { updateUser } from '../store/user'
export default defineComponent({ export default defineComponent({
name: 'RegisterPage', name: 'RegisterPage',

View File

@ -74,12 +74,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { routerPush } from 'src/router'
import { putProfile, PutProfileForm } from 'src/services/profile/putProfile'
import { checkAuthorization, updateUser, user } from 'src/store/user'
import { computed, defineComponent, onMounted, reactive } from 'vue' import { computed, defineComponent, onMounted, reactive } from 'vue'
import { routerPush } from '../router'
import { putProfile, PutProfileForm } from '../services/profile/putProfile'
import { user, checkAuthorization, updateUser } from '../store/user'
export default defineComponent({ export default defineComponent({
name: 'SettingsPage', name: 'SettingsPage',

View File

@ -1,7 +1,6 @@
import AppLink from 'src/components/AppLink.vue'
import type { App } from 'vue' import type { App } from 'vue'
import AppLink from '../components/AppLink.vue'
export default function registerGlobalComponents (app: App): void { export default function registerGlobalComponents (app: App): void {
app.component('AppLink', AppLink) app.component('AppLink', AppLink)
} }

View File

@ -1,5 +1,5 @@
import { request } from '../services' import { request } from 'src/services'
import storage from '../utils/storage' import storage from 'src/utils/storage'
export default function (): void { export default function (): void {
const token = storage.get<User>('user')?.token const token = storage.get<User>('user')?.token

View File

@ -1,10 +1,8 @@
import type { AuthorizationError } from 'src/types/error'
import { Either, fail, success } from 'src/utils/either'
import { mapAuthorizationResponse } from 'src/utils/map-checkable-response'
import { request } from '../index' import { request } from '../index'
import type { AuthorizationError } from '../../types/error'
import { Either, fail, success } from '../../utils/either'
import { mapAuthorizationResponse } from '../../utils/map-checkable-response'
export async function postFavoriteArticle (slug: string): Promise<Either<AuthorizationError, Article>> { export async function postFavoriteArticle (slug: string): Promise<Either<AuthorizationError, Article>> {
const result1 = await request.checkablePost<ArticleResponse>(`/articles/${slug}/favorite`) const result1 = await request.checkablePost<ArticleResponse>(`/articles/${slug}/favorite`)
const result2 = mapAuthorizationResponse<ArticleResponse>(result1) const result2 = mapAuthorizationResponse<ArticleResponse>(result1)

View File

@ -1,10 +1,8 @@
import type { ValidationError } from 'src/types/error'
import { Either, fail, success } from 'src/utils/either'
import { mapValidationResponse } from 'src/utils/map-checkable-response'
import { request } from '../index' import { request } from '../index'
import type { ValidationError } from '../../types/error'
import { mapValidationResponse } from '../../utils/map-checkable-response'
import { Either, fail, success } from '../../utils/either'
export interface PostLoginForm { export interface PostLoginForm {
email: string email: string
password: string password: string

View File

@ -1,10 +1,8 @@
import type { ValidationError } from 'src/types/error'
import { Either, fail, success } from 'src/utils/either'
import { mapValidationResponse } from 'src/utils/map-checkable-response'
import { request } from '../index' import { request } from '../index'
import type { ValidationError } from '../../types/error'
import { mapValidationResponse } from '../../utils/map-checkable-response'
import { Either, fail, success } from '../../utils/either'
export interface PostRegisterForm { export interface PostRegisterForm {
email: string email: string
password: string password: string

View File

@ -1,10 +1,8 @@
import type { AuthorizationError } from '../../types/error' import type { AuthorizationError } from 'src/types/error'
import { Either, fail, success } from 'src/utils/either'
import { mapAuthorizationResponse } from 'src/utils/map-checkable-response'
import { request } from '../index' import { request } from '../index'
import { mapAuthorizationResponse } from '../../utils/map-checkable-response'
import { Either, fail, success } from '../../utils/either'
export async function postFollowProfile (username: string): Promise<Either<AuthorizationError, Profile>> { export async function postFollowProfile (username: string): Promise<Either<AuthorizationError, Profile>> {
const result1 = await request.checkablePost<ProfileResponse>(`/profiles/${username}/follow`) const result1 = await request.checkablePost<ProfileResponse>(`/profiles/${username}/follow`)
const result2 = mapAuthorizationResponse<ProfileResponse>(result1) const result2 = mapAuthorizationResponse<ProfileResponse>(result1)