Skip to content

Commit

Permalink
Move utils, types and constants to shared folder
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Nov 26, 2024
1 parent 1ca4e0c commit 670c55b
Show file tree
Hide file tree
Showing 382 changed files with 732 additions and 1,142 deletions.
1 change: 0 additions & 1 deletion frontend/.storybook/decorators/with-rtl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useI18n } from "#imports"

import { ref, watch, onMounted, reactive, h } from "vue"

import { useEffect } from "@storybook/preview-api"
Expand Down
6 changes: 3 additions & 3 deletions frontend/.storybook/decorators/with-theme.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { watch, onMounted, reactive, h } from "vue"
import { useEffect, useGlobals } from "@storybook/preview-api"

import { EffectiveColorMode } from "~/types/ui"
import { useEffect, useGlobals } from "@storybook/preview-api"

import { useDarkMode } from "~/composables/use-dark-mode"
import { EffectiveColorMode } from "#shared/types/ui"
import { useUiStore } from "~/stores/ui"
import { useDarkMode } from "~/composables/use-dark-mode"

import VThemeSelect from "~/components/VThemeSelect/VThemeSelect.vue"

Expand Down
3 changes: 1 addition & 2 deletions frontend/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { VIEWPORTS } from "~/constants/screens"

import { VIEWPORTS } from "#shared/constants/screens"
import { WithUiStore } from "~~/.storybook/decorators/with-ui-store"
import { WithRTL } from "~~/.storybook/decorators/with-rtl"
import { WithTheme } from "~~/.storybook/decorators/with-theme"
Expand Down
2 changes: 1 addition & 1 deletion frontend/i18n/locales/scripts/axios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const axios = require("axios")

const { userAgent } = require("../../../src/constants/user-agent")
const { userAgent } = require("../../../shared/constants/user-agent")

module.exports = module.exports = axios.create({
headers: { "User-Agent": userAgent },
Expand Down
1 change: 0 additions & 1 deletion frontend/i18n/locales/scripts/bulk-download.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { pipeline } = require("stream/promises")

const { createWriteStream } = require("fs")

const AdmZip = require("adm-zip")
Expand Down
2 changes: 1 addition & 1 deletion frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineNuxtConfig } from "nuxt/config"

import { disallowedBots } from "./src/constants/disallowed-bots"
import { disallowedBots } from "./shared/constants/disallowed-bots"
import locales from "./i18n/locales/scripts/valid-locales.json"

import type { LocaleObject } from "@nuxtjs/i18n"
Expand Down
1 change: 0 additions & 1 deletion frontend/server/plugins/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useRuntimeConfig, useAppConfig } from "#imports"

import { defineNitroPlugin } from "nitropack/runtime"
import * as Sentry from "@sentry/node"

import { logger } from "~~/server/utils/logger"

export default defineNitroPlugin((nitroApp) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { consola } from "consola"

import { LOCAL, PRODUCTION, STAGING } from "~/constants/deploy-env"
import { LOCAL, PRODUCTION, STAGING } from "#shared/constants/deploy-env"

/**
* This logger is used only in the Nitro server.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { ALL_MEDIA, AUDIO, IMAGE, VIDEO, MODEL_3D } from "~/constants/media"
import { ACTIVE_LICENSES } from "~/constants/license"
import { deepFreeze } from "~/utils/deep-freeze"

import type { SearchType } from "~/constants/media"
import {
ALL_MEDIA,
AUDIO,
IMAGE,
VIDEO,
MODEL_3D,
} from "#shared/constants/media"
import { ACTIVE_LICENSES } from "#shared/constants/license"
import type { SearchType } from "#shared/constants/media"
import { deepFreeze } from "#shared/utils/deep-freeze"

export interface FilterItem {
code: string
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import type {
SearchType,
SupportedMediaType,
SupportedSearchType,
} from "~/constants/media"
import type { ReportReason } from "~/constants/content-report"
import type { FilterCategory } from "~/constants/filters"
import { ResultKind } from "~/types/result"
import { RequestKind } from "~/types/fetch-state"
import { Collection } from "~/types/search"
import { License } from "~/constants/license"
} from "#shared/constants/media"
import type { ReportReason } from "#shared/constants/content-report"
import type { FilterCategory } from "#shared/constants/filters"
import type { License } from "#shared/constants/license"
import type { ResultKind } from "#shared/types/result"
import type { RequestKind } from "#shared/types/fetch-state"
import type { Collection } from "#shared/types/search"

export type AudioInteraction = "play" | "pause" | "seek"
export type AudioInteractionData = Exclude<
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type SupportedSearchType, IMAGE, AUDIO } from "~/constants/media"
import type { AudioDetail, ImageDetail } from "~/types/media"
import type { ResultKind, Results } from "~/types/result"
import { type SupportedSearchType, IMAGE, AUDIO } from "#shared/constants/media"
import type { AudioDetail, ImageDetail } from "#shared/types/media"
import type { ResultKind, Results } from "#shared/types/result"

export type SingleResultProps = {
kind: ResultKind
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FeatureState } from "~/constants/feature-flag"
import type { FeatureState } from "#shared/constants/feature-flag"
import { UiState } from "~/stores/ui"

const baseCookieOptions = {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {
FeatureState,
FlagStatus,
Storage,
} from "~/constants/feature-flag"
import type { DeployEnv } from "~/constants/deploy-env"
} from "#shared/constants/feature-flag"
import type { DeployEnv } from "#shared/constants/deploy-env"

export type FlagName = keyof (typeof featureData)["features"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ErrorCode } from "~/constants/errors"
import type { SupportedSearchType } from "~/constants/media"
import type { ErrorCode } from "#shared/constants/errors"
import type { SupportedSearchType } from "#shared/constants/media"

/**
* Describes the kind of API request that was made.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// The source code of this package is parsed to create the media properties
// documentation by the script `scripts/document-media.js`.

import type { SupportedMediaType } from "~/constants/media"
import type { License, LicenseVersion } from "~/constants/license"
import type { SupportedMediaType } from "#shared/constants/media"
import type { License, LicenseVersion } from "#shared/constants/license"
import {
SENSITIVITY_RESPONSE_PARAM,
Sensitivity,
} from "~/constants/content-safety"
import { AUDIO, IMAGE } from "~/constants/media"
} from "#shared/constants/content-safety"
import { AUDIO, IMAGE } from "#shared/constants/media"

export interface Tag {
name: string
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ALL_MEDIA, AUDIO, IMAGE } from "~/constants/media"
import { AudioDetail, ImageDetail } from "~/types/media"
import { ALL_MEDIA, AUDIO, IMAGE } from "#shared/constants/media"
import type { AudioDetail, ImageDetail } from "#shared/types/media"

export type ResultKind = "search" | "related" | "collection"
export type ImageResults = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INCLUDE_SENSITIVE_QUERY_PARAM } from "~/constants/content-safety"
import { INCLUDE_SENSITIVE_QUERY_PARAM } from "#shared/constants/content-safety"

export type Collection = "tag" | "creator" | "source"
export type SearchStrategy = "default" | Collection
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/
import enJson from "~~/i18n/locales/en.json"

import type { Media } from "~/types/media"
import type { LicenseElement } from "#shared/constants/license"
import {
getElements,
getFullLicenseName,
isPublicDomain,
} from "~/utils/license"
import type { LicenseElement } from "~/constants/license"
} from "#shared/utils/license"
import type { Media } from "#shared/types/media"

import type { Composer } from "vue-i18n"

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* Contains utilities related to content safety.
*/

import { hash, rand as prng } from "~/utils/prng"
import { log } from "~/utils/console"
import {
USER_REPORTED,
PROVIDER_SUPPLIED,
TEXT_FILTERED,
Sensitivity,
} from "~/constants/content-safety"
} from "#shared/constants/content-safety"
import { hash, rand as prng } from "#shared/utils/prng"
import { log } from "~/utils/console"

/**
* Get an array of randomly selected sensitive content flags for an item with
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clientSideErrorCodes, NO_RESULT } from "~/constants/errors"
import type { FetchingError } from "~/types/fetch-state"
import { clientSideErrorCodes, NO_RESULT } from "#shared/constants/errors"
import type { FetchingError } from "#shared/types/fetch-state"

const NON_RETRYABLE_ERROR_CODES = [429, 500, 404] as const
const isNonRetryableErrorStatusCode = (statusCode: number | undefined) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { MediaType } from "~/constants/media"
import type { PaginatedSearchQuery } from "~/types/search"

import { MODEL_3D } from "~/constants/media"
import type { MediaType } from "#shared/constants/media"
import { MODEL_3D } from "#shared/constants/media"
import type { PaginatedSearchQuery } from "#shared/types/search"

/**
* Describes the query format used by the URL builder functions of additional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import type {
License,
LicenseVersion,
LicenseElement,
} from "~/constants/license"
} from "#shared/constants/license"
import {
CC_LICENSES,
DEPRECATED_CC_LICENSES,
PUBLIC_DOMAIN_MARKS,
} from "~/constants/license"
import { camelCase } from "~/utils/case"
} from "#shared/constants/license"
import { camelCase } from "#shared/utils/case"

import type { Composer } from "vue-i18n"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SupportedMediaType } from "~/constants/media"
import { SupportedMediaType } from "#shared/constants/media"

import type { LocationQueryValue } from "vue-router"

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ import {
FilterItem,
Filters,
mediaFilterKeys,
} from "~/constants/filters"
} from "#shared/constants/filters"
import {
ALL_MEDIA,
mediaTypes,
SearchType,
SupportedSearchType,
supportedSearchTypes,
} from "~/constants/media"
import { INCLUDE_SENSITIVE_QUERY_PARAM } from "~/constants/content-safety"
import { deepClone } from "~/utils/clone"

import {
} from "#shared/constants/media"
import { INCLUDE_SENSITIVE_QUERY_PARAM } from "#shared/constants/content-safety"
import { deepClone } from "#shared/utils/clone"
import { firstParam } from "#shared/utils/query-utils"
import type {
SearchFilterKeys,
PaginatedSearchQuery,
SearchFilterQuery,
} from "~/types/search"

import { firstParam } from "~/utils/query-utils"
} from "#shared/types/search"

import type { LocationQuery } from "vue-router"

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 2 additions & 5 deletions frontend/src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import {
useRuntimeConfig,
} from "#imports"
import { meta as commonMeta } from "#shared/constants/meta"
import { favicons } from "#shared/constants/favicons"
import { useUiStore } from "~/stores/ui"
import { useFeatureFlagStore } from "~/stores/feature-flag"
import { useLayout } from "~/composables/use-layout"
import { useDarkMode } from "~/composables/use-dark-mode"
import { meta as commonMeta } from "~/constants/meta"
import { favicons } from "~/constants/favicons"
import VSkipToContentButton from "~/components/VSkipToContentButton.vue"
const { updateBreakpoint } = useLayout()
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Displays the cover art for the audio in a square aspect ratio.
*/
import { useI18n } from "#imports"
import { toRefs, ref, onMounted } from "vue"
import { rand, hash } from "~/utils/prng"
import { lerp, dist, bezier, Point } from "~/utils/math"
import type { AudioDetail } from "~/types/media"
import { rand, hash } from "#shared/utils/prng"
import { lerp, dist, bezier, Point } from "#shared/utils/math"
import type { AudioDetail } from "#shared/types/media"
import { useSensitiveMedia } from "~/composables/use-sensitive-media"
const props = defineProps<{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meta, type StoryObj } from "@storybook/vue3"
import { h } from "vue"

import { Meta, type StoryObj } from "@storybook/vue3"
import { getAudioObj } from "~~/test/unit/fixtures/audio"

import { AudioDetail } from "~/types/media"
import type { AudioDetail } from "#shared/types/media"

import VAudioThumbnail from "~/components/VAudioThumbnail/VAudioThumbnail.vue"

Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/VAudioTrack/VAudioControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
* Displays the control for switching between the playing and paused states of
* a media file.
*/
import { computed } from "vue"
import { AudioLayout, AudioStatus, statusVerbMap } from "~/constants/audio"
import type { ButtonConnections } from "~/types/button"
import { computed } from "vue"
import {
AudioLayout,
AudioStatus,
statusVerbMap,
} from "#shared/constants/audio"
import type { ButtonConnections } from "#shared/types/button"
import { useHydrating } from "~/composables/use-hydrating"
import VIconButton from "~/components/VIconButton/VIconButton.vue"
Expand Down
34 changes: 17 additions & 17 deletions frontend/src/components/VAudioTrack/VAudioTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@
* Displays the waveform and basic information about the track, along with
* controls to play, pause or seek to a point on the track.
*/
import { firstParam, useI18n, useRoute } from "#imports"
import { useI18n, useRoute } from "#imports"
import { computed, onUnmounted, ref, watch } from "vue"
import { AUDIO } from "#shared/constants/media"
import {
activeAudioStatus,
AudioLayout,
AudioSize,
AudioStatus,
} from "#shared/constants/audio"
import { firstParam } from "#shared/utils/query-utils"
import type {
AudioInteraction,
AudioInteractionData,
} from "#shared/types/analytics"
import type { AudioDetail } from "#shared/types/media"
import type { AudioTrackClickEvent } from "#shared/types/events"
import { useActiveMediaStore } from "~/stores/active-media"
import { useMediaStore } from "~/stores/media"
import { useActiveAudio } from "~/composables/use-active-audio"
import { defaultRef } from "~/composables/default-ref"
import { useSeekable } from "~/composables/use-seekable"
Expand All @@ -16,21 +31,6 @@ import {
useMatchSingleResultRoutes,
} from "~/composables/use-match-routes"
import { useActiveMediaStore } from "~/stores/active-media"
import { useMediaStore } from "~/stores/media"
import { AUDIO } from "~/constants/media"
import {
activeAudioStatus,
AudioLayout,
AudioSize,
AudioStatus,
} from "~/constants/audio"
import type { AudioInteraction, AudioInteractionData } from "~/types/analytics"
import type { AudioDetail } from "~/types/media"
import type { AudioTrackClickEvent } from "~/types/events"
import VAudioControl from "~/components/VAudioTrack/VAudioControl.vue"
import VWaveform from "~/components/VAudioTrack/VWaveform.vue"
import VFullLayout from "~/components/VAudioTrack/layouts/VFullLayout.vue"
Expand Down
Loading

0 comments on commit 670c55b

Please sign in to comment.