Skip to content

Commit

Permalink
co-locate remaining logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeragamba committed Sep 2, 2024
1 parent 1612644 commit 5e35fa8
Show file tree
Hide file tree
Showing 135 changed files with 245 additions and 269 deletions.
2 changes: 2 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions packages/client/src/Api/Endpoints/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/client/src/Api/Errors/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/client/src/Api/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/client/src/Lib/AgeGate/AgeGateHooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from "react"
import { AgeGateContext, AgeGateState } from "./AgeGateContext.ts"
import { AgeGateContext, AgeGateState } from "./AgeGateContext"

export const useAgeGate = (): AgeGateState => {
return useContext(AgeGateContext)
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/Lib/AgeGate/AgeGateProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC, ReactNode, useState } from "react"
import { AgeGateContext } from "./AgeGateContext.ts"
import { AgeGateContext } from "./AgeGateContext"

export interface AgeGateProviderProps {
children: ReactNode
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/Lib/AgeGate/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./AgeGateContext.ts"
export * from "./AgeGateHooks.ts"
export * from "./AgeGateProvider.tsx"
export * from "./AgeGateContext"
export * from "./AgeGateHooks"
export * from "./AgeGateProvider"
7 changes: 3 additions & 4 deletions packages/client/src/Lib/Auth/AuthApi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as webauthn from "@github/webauthn-json/browser-ponyfill"
import { RegistrationPublicKeyCredential } from "@github/webauthn-json/browser-ponyfill"
import z from "zod"
import { isServerApiError, ServerApi } from "../ServerApi"

import { UserData } from "../../Models"
import { authTokenStore } from "../../Api/AuthTokenStore.ts"
import { isServerApiError, ServerApi } from "../../Api"
import { UserDataSchema, UserResSchema } from "../../Api/Schemas"
import { authTokenStore } from "../ServerApi/AuthTokenStore"
import { UserData, UserDataSchema, UserResSchema } from "../Users"
import {
PasskeyCreateChallengeSchema,
PasskeyData,
Expand Down
9 changes: 4 additions & 5 deletions packages/client/src/Lib/Auth/AuthQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import {
UseQueryResult,
} from "@tanstack/react-query"

import { queryKeys } from "../../Queries/QueryKeys.ts"
import { ServerApiError } from "../../Api"
import { queryClient, queryKeys } from "../Queries"
import { ServerApiError } from "../ServerApi"
import { UserData } from "../Users"
import { authApiClient, RegisterPassKeyParams } from "./AuthApi"
import { PasskeyData } from "./Passkeys"
import { queryClient } from "../QueryClient.ts"
import { UserData } from "../../Models"
import { authApiClient, RegisterPassKeyParams } from "./AuthApi.ts"

export const usePasswordLogin$ = () => {
const queryClient = useQueryClient()
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/Lib/Auth/Passkeys/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./PasskeySchema.ts"
export * from "./PasskeySchema"
4 changes: 2 additions & 2 deletions packages/client/src/Lib/Auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./Passkeys"
export * from "./AuthApi.ts"
export * from "./AuthQueries.ts"
export * from "./AuthApi"
export * from "./AuthQueries"
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/client/src/Lib/Galleries/GalleryApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GalleryResSchema } from "./GalleryDataSchema"
import { ServerApi } from "../../Api"
import { ServerApi } from "../ServerApi"
import { GalleryData } from "./GalleryData"
import { PagedPostData, PagedPostDataResSchema } from "../Posts"

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/Lib/Galleries/GalleryHooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from "react"
import { GalleryConfig, GalleryContext } from "./GalleryContext.ts"
import { GalleryConfig, GalleryContext } from "./GalleryContext"

export const useGalleryContext = (): GalleryConfig => {
return useContext(GalleryContext)
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/Lib/Galleries/GalleryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
defaultGalleryConfig,
GalleryConfig,
GalleryContext,
} from "./GalleryContext.ts"
} from "./GalleryContext"

export interface GalleryContextProviderProps {
config: Partial<GalleryConfig>
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/Lib/Galleries/GalleryQueries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery, UseQueryResult } from "@tanstack/react-query"

import { queryKeys } from "../../Queries/QueryKeys"
import { queryKeys } from "../Queries/QueryKeys"
import { galleryApiClient } from "./GalleryApi"
import { GalleryData } from "./GalleryData"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useRef } from "react"

import { noop } from "../Lib"
import { noop } from "../Noop"

export const useHotkey = (hotkey: string, action: () => void): void => {
const actionRef = useRef<() => void>(noop)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCurrentUser$ } from "../Lib/Auth"
import { useCurrentUser$ } from "../Auth"

export const useIsAdmin = (): boolean => {
const { data: currentUser } = useCurrentUser$()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PostData, useImagePreloader } from "../Lib"
import { useImagePreloader } from "../Images"
import { PostData } from "../Posts"

interface PostPreloaderProps {
post: PostData
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./UseDragActive"
export * from "./UseFeatureFlag"
export * from "../SiteMeta/UseFeatureFlag"
export * from "./UseFilesDropped"
export * from "./UseHotkey"
export * from "./UseInViewport"
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/Lib/Images/ImageManager/Actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createAction } from "@reduxjs/toolkit"

import { ImageData } from "../ImageData.ts"
import { ImageData } from "../ImageData"

export type SetImagesPayload = ImageData[]
export const setImages = createAction<SetImagesPayload>("setImages")
Expand Down
20 changes: 10 additions & 10 deletions packages/client/src/Lib/Images/ImageManager/ChangesReducer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import crypto from "node:crypto"
import { beforeEach, describe, expect, it } from "vitest"
import { freeze } from "../../index"
import {
AddImageChangeRecord,
EditImageChangeRecord,
ImageChangeRecord,
RemoveImageChangeRecord,
} from "../ImageChangeRecord"
import { ImageData } from "../ImageData"

import {
addImage,
Expand All @@ -10,16 +18,8 @@ import {
RemoveImagePayload,
setImages,
SetImagesPayload,
} from "./Actions.ts"
import { changesReducer } from "./ChangesReducer.ts"
import { freeze } from "../../index.ts"
import { ImageData } from "../ImageData"
import {
AddImageChangeRecord,
EditImageChangeRecord,
ImageChangeRecord,
RemoveImageChangeRecord,
} from "../ImageChangeRecord.ts"
} from "./Actions"
import { changesReducer } from "./ChangesReducer"

describe("ChangesReducer", () => {
let oldState: ImageChangeRecord[]
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/Lib/Images/ImageManager/ChangesReducer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createReducer } from "@reduxjs/toolkit"
import { ImageChangeRecord } from "../ImageChangeRecord"

import * as Actions from "./Actions.ts"
import { ImageChangeRecord } from "../ImageChangeRecord.ts"
import * as Actions from "./Actions"

export const changesReducer = createReducer<ImageChangeRecord[]>(
[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import crypto from "node:crypto"
import { beforeEach, describe, expect, it, vi } from "vitest"
import { freeze } from "../../index"
import { ImageData } from "../ImageData"

import {
addImage,
Expand All @@ -8,10 +10,8 @@ import {
EditImagePayload,
setImages,
SetImagesPayload,
} from "./Actions.ts"
} from "./Actions"
import { imagesReducer } from "./ImagesReducer"
import { freeze } from "../../index"
import { ImageData } from "../ImageData"

describe("ImageReducer", () => {
let oldState: ImageData[]
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/Lib/Images/ImageManager/ImagesReducer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createReducer } from "@reduxjs/toolkit"
import { reorderItems } from "../../Hooks"
import { ImageData } from "../ImageData"

import * as Actions from "./Actions.ts"
import { reorderItems } from "../../../Hooks"
import { ImageData } from "../ImageData.ts"
import * as Actions from "./Actions"

export const imagesReducer = createReducer<ImageData[]>([], ({ addCase }) => {
addCase(Actions.setImages, (_images, { payload }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useReducer } from "react"
import { ImageChangeRecord } from "../ImageChangeRecord"
import { ImageData } from "../ImageData"

import * as Actions from "./Actions.ts"
import { rootReducer } from "./rootReducer.ts"
import { ImageData } from "../ImageData.ts"
import { ImageChangeRecord } from "../ImageChangeRecord.ts"
import * as Actions from "./Actions"
import { rootReducer } from "./rootReducer"

export type UseImageManagerProps = {
images?: ImageData[]
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/Lib/Images/ImageManager/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./UseImageManager.ts"
export * from "./UseImageManager"
8 changes: 4 additions & 4 deletions packages/client/src/Lib/Images/ImageManager/rootReducer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Reducer } from "@reduxjs/toolkit"
import { ImageChangeRecord } from "../ImageChangeRecord"
import { ImageData } from "../ImageData"

import { changesReducer } from "./ChangesReducer.ts"
import { imagesReducer } from "./ImagesReducer.ts"
import { ImageData } from "../ImageData.ts"
import { ImageChangeRecord } from "../ImageChangeRecord.ts"
import { changesReducer } from "./ChangesReducer"
import { imagesReducer } from "./ImagesReducer"

export type State = {
images: ImageData[]
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/Lib/Images/ImageQueries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useQuery, useQueryClient, UseQueryResult } from "@tanstack/react-query"
import { errorHandler } from "../Errors/ErrorHandler"

import { queryKeys } from "../../Queries/QueryKeys"
import { queryKeys } from "../Queries/QueryKeys"
import { imageApi } from "./ImageApi"
import { errorHandler } from "../../Errors/ErrorHandler"
import { ImageData } from "./ImageData"

export const useImage$ = (src: string): UseQueryResult<HTMLImageElement> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ViewMetricsData } from "../../Models"
import { ViewMetricsResSchema } from "../Schemas/ViewMetricsDataSchema"
import { ServerApi } from "../ServerApi"
import { ViewMetricsData } from "./ViewMetricsData"
import { ViewMetricsResSchema } from "./ViewMetricsDataSchema"

export class MetricsApi extends ServerApi {
fetchViews(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useQuery } from "@tanstack/react-query"

import { queryKeys } from "./QueryKeys"
import { metricsApiClient } from "../Api"
import { queryKeys } from "../Queries"
import { metricsApiClient } from "./MetricsApi"

export const useViewMetrics$ = (params: {
startDate?: Date | null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PostData } from "../../Lib/Posts/PostData.ts"
import { ViewsData } from "../../Models/ViewsData"
import { PostViewsResSchema } from "../Schemas/PostViewsDataSchema"
import { PostData } from "../Posts"
import { ServerApi } from "../ServerApi"
import { PostViewsResSchema } from "./PostViewsDataSchema"
import { ViewsData } from "./ViewsData"

class PostViewsApi extends ServerApi {
public async fetchViews(params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import {
useQuery,
UseQueryResult,
} from "@tanstack/react-query"

import { queryKeys } from "./QueryKeys"
import { PostData } from "../Lib"
import { ViewsData } from "../Models"
import { postViewsApi } from "../Api"
import { PostData } from "../Posts"
import { queryKeys } from "../Queries"
import { postViewsApi } from "./PostViewsApi"
import { ViewsData } from "./ViewsData"

export const usePostViews$ = (params: {
postId: PostData["id"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as uuid from "uuid"

import { postViewsApi } from "../../Api"
import { noop } from "../Noop"
import { PostData } from "../Posts"
import { postViewsApi } from "./PostViewsApi"

const VIEWER_ID_KEY = "viewerId"
const SESSION_VIEWS_KEY = (postId: string) => `viewed.${postId}`
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions packages/client/src/Lib/Metrics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export * from "./MetricsApi"
export * from "./MetricsQueries"
export * from "./PostViewsApi"
export * from "./PostViewsDataSchema"
export * from "./PostViewsQueries"
export * from "./ViewMetricsData"
export * from "./ViewMetricsDataSchema"
export * from "./ViewsData"
export * from "./ViewHooks"
5 changes: 2 additions & 3 deletions packages/client/src/Lib/Posts/PostData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { addDays, setHours, setMinutes } from "date-fns"

import { EditableImage, ImageData } from "../Images/ImageData.ts"
import { TagData } from "../Tags/TagData.ts"
import { ImageChangeRecord } from "../Images"
import { EditableImage, ImageChangeRecord, ImageData } from "../Images"
import { TagData } from "../Tags"

export interface PostData {
id: string
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/Lib/Posts/PostDataSchema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import z from "zod"

import { ImageDataSchema } from "../Images/ImageDataSchema.ts"
import { PagedResMetaDataSchema } from "../../Api/Schemas/PagedResMetaDataSchema.ts"
import { TagDataSchema } from "../Tags/TagDataSchema.ts"
import { ImageDataSchema } from "../Images"
import { PagedResMetaDataSchema } from "../ServerApi"
import { TagDataSchema } from "../Tags"

export const PostDataSchema = z.object({
id: z.string().uuid(),
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/Lib/Posts/PostHooks.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from "react"
import { PostContext } from "./PostContext.tsx"
import { PostContext } from "./PostContext"

export const usePostContext = () => {
const context = useContext(PostContext)
Expand Down
10 changes: 4 additions & 6 deletions packages/client/src/Lib/Posts/PostQuries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import {
useQueryClient,
UseQueryResult,
} from "@tanstack/react-query"

import { queryKeys } from "../../Queries/QueryKeys.ts"
import { pagedQueryOptions } from "../../Queries/QueryUtils.ts"
import { EditablePost, PostData } from "./PostData"
import { EditableImage, ImageChangeRecord } from "../Images"
import { postsApi } from "./PostsApi"
import { GalleryData } from "../Galleries"
import { EditableImage, ImageChangeRecord } from "../Images"
import { pagedQueryOptions, queryKeys } from "../Queries"
import { TagData } from "../Tags"
import { EditablePost, PostData } from "./PostData"
import { PagedPostData } from "./PostDataSchema"
import { postsApi } from "./PostsApi"

type PostParams = { postId: string; galleryId?: string; tagId?: string }

Expand Down
7 changes: 3 additions & 4 deletions packages/client/src/Lib/Posts/PostsApi.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { AxiosProgressEvent } from "axios"

import { getPostUrl } from "../PostUtil.ts"
import { ServerApi } from "../../Api"
import { EditablePost, PostData, postToFormData } from "./PostData"
import { EditableImage, ImageChangeRecord } from "../Images"
import { getPostUrl } from "../PostUtil"
import { ServerApi } from "../ServerApi"
import { EditablePost, PostData, postToFormData } from "./PostData"
import {
PagedPostData,
PagedPostDataResSchema,
Expand Down
Loading

0 comments on commit 5e35fa8

Please sign in to comment.