-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arrange when image is on canvas for pixel data and whether to hide on…
… canvas draw; rearranged some files for modularity
- Loading branch information
Showing
32 changed files
with
1,041 additions
and
636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { type IAssetImageGeneration } from './image/image.generate.server' | ||
|
||
export interface IAssetGenerationByType { | ||
assetImages: IAssetImageGeneration[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { type IAssetImage } from './image.server' | ||
|
||
export interface IAssetImageSrcGeneration { | ||
id: IAssetImage['id'] | ||
src: string | ||
} | ||
|
||
export interface IAssetImageDrawGeneration { | ||
x: number | ||
y: number | ||
width: number | ||
height: number | ||
} | ||
|
||
export interface IAssetImageGeneration extends IAssetImageDrawGeneration { | ||
src: string | ||
export interface IAssetImageGeneration | ||
extends IAssetImageSrcGeneration, | ||
IAssetImageDrawGeneration { | ||
hideOnDraw: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/models/asset/image/image.update.hide-on-draw.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { type IntentActionArgs } from '#app/definitions/intent-action-args' | ||
import { type IUser } from '#app/models/user/user.server' | ||
import { EditAssetImageHideOnDrawSchema } from '#app/schema/asset/image' | ||
import { ValidateAssetSubmissionStrategy } from '#app/strategies/validate-submission.strategy' | ||
import { validateEntitySubmission } from '#app/utils/conform-utils' | ||
import { prisma } from '#app/utils/db.server' | ||
import { type IAssetImage, type IAssetImageFileData } from './image.server' | ||
import { stringifyAssetImageAttributes } from './utils' | ||
|
||
export const validateEditHideOnDrawAssetImageSubmission = async ({ | ||
userId, | ||
formData, | ||
}: IntentActionArgs) => { | ||
const strategy = new ValidateAssetSubmissionStrategy() | ||
|
||
return await validateEntitySubmission({ | ||
userId, | ||
formData, | ||
schema: EditAssetImageHideOnDrawSchema, | ||
strategy, | ||
}) | ||
} | ||
|
||
export interface IAssetImageUpdateHideOnDrawSubmission { | ||
userId: IUser['id'] | ||
id: IAssetImage['id'] | ||
hideOnDraw: boolean | ||
} | ||
|
||
interface IAssetImageUpdateHideOnDrawData { | ||
attributes: IAssetImageFileData | ||
} | ||
|
||
export const updateAssetImageHideOnDraw = ({ | ||
id, | ||
data, | ||
}: { | ||
id: IAssetImage['id'] | ||
data: IAssetImageUpdateHideOnDrawData | ||
}) => { | ||
const { attributes } = data | ||
const jsonAttributes = stringifyAssetImageAttributes(attributes) | ||
return prisma.asset.update({ | ||
where: { id }, | ||
data: { | ||
attributes: jsonAttributes, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
app/routes/resources+/api.v1+/asset.image.update.hide-on-draw.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { | ||
json, | ||
type ActionFunctionArgs, | ||
type LoaderFunctionArgs, | ||
} from '@remix-run/node' | ||
import { useFetcher } from '@remix-run/react' | ||
import { redirectBack } from 'remix-utils/redirect-back' | ||
import { useHydrated } from 'remix-utils/use-hydrated' | ||
import { FetcherIconButton } from '#app/components/templates/form/fetcher-icon-button' | ||
import { type IAssetImage } from '#app/models/asset/image/image.server' | ||
import { validateEditHideOnDrawAssetImageSubmission } from '#app/models/asset/image/image.update.hide-on-draw.server' | ||
import { EditAssetImageHideOnDrawSchema } from '#app/schema/asset/image' | ||
import { validateNoJS } from '#app/schema/form-data' | ||
import { assetImageUpdateHideOnDrawService } from '#app/services/asset.image.update.hide-on-draw.service' | ||
import { requireUserId } from '#app/utils/auth.server' | ||
import { Routes } from '#app/utils/routes.const' | ||
|
||
// https://www.epicweb.dev/full-stack-components | ||
|
||
const route = Routes.RESOURCES.API.V1.ASSET.IMAGE.UPDATE.HIDE_ON_DRAW | ||
const schema = EditAssetImageHideOnDrawSchema | ||
|
||
// auth GET request to endpoint | ||
export async function loader({ request }: LoaderFunctionArgs) { | ||
await requireUserId(request) | ||
return json({}) | ||
} | ||
|
||
export async function action({ request }: ActionFunctionArgs) { | ||
const userId = await requireUserId(request) | ||
const formData = await request.formData() | ||
const noJS = validateNoJS({ formData }) | ||
|
||
let updateSuccess = false | ||
let errorMessage = '' | ||
const { status, submission } = | ||
await validateEditHideOnDrawAssetImageSubmission({ | ||
userId, | ||
formData, | ||
}) | ||
|
||
if (status === 'success') { | ||
const { success, message } = await assetImageUpdateHideOnDrawService({ | ||
userId, | ||
...submission.value, | ||
}) | ||
updateSuccess = success | ||
errorMessage = message || '' | ||
} | ||
|
||
if (noJS) { | ||
throw redirectBack(request, { | ||
fallback: '/', | ||
}) | ||
} | ||
|
||
return json( | ||
{ status, submission, message: errorMessage }, | ||
{ | ||
status: status === 'error' || !updateSuccess ? 404 : 200, | ||
}, | ||
) | ||
} | ||
|
||
export const AssetImageUpdateHideOnDraw = ({ | ||
image, | ||
formLocation = '', | ||
}: { | ||
image: IAssetImage | ||
formLocation?: string | ||
}) => { | ||
const assetId = image.id | ||
const field = 'hideOnDraw' | ||
const isHiddenOnDraw = image.attributes[field] || false | ||
const icon = isHiddenOnDraw ? 'eye-none' : 'eye-open' | ||
const iconText = `${isHiddenOnDraw ? 'Show' : 'Show'} on draw` | ||
const fetcherKey = `asset-image-update-${field}-${assetId}` | ||
const formId = `${fetcherKey}${formLocation ? `-${formLocation}` : ''}` | ||
|
||
let isHydrated = useHydrated() | ||
const fetcher = useFetcher<typeof action>({ | ||
key: fetcherKey, | ||
}) | ||
|
||
return ( | ||
<FetcherIconButton | ||
fetcher={fetcher} | ||
route={route} | ||
schema={schema} | ||
formId={formId} | ||
icon={icon} | ||
iconText={iconText} | ||
tooltipText={iconText} | ||
isHydrated={isHydrated} | ||
> | ||
<div className="hidden"> | ||
<input type="hidden" name="id" value={assetId} /> | ||
</div> | ||
</FetcherIconButton> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/services/artwork/version/generator/build.container.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { type IArtworkVersionWithChildren } from '#app/models/artwork-version/artwork-version.server' | ||
|
||
export const getArtworkVersionContainer = ({ | ||
version, | ||
}: { | ||
version: IArtworkVersionWithChildren | ||
}) => { | ||
const { width, height } = version | ||
return { | ||
width, | ||
height, | ||
top: 0, | ||
left: 0, | ||
margin: 0, | ||
canvas: { | ||
width, | ||
height, | ||
}, | ||
} | ||
} |
Oops, something went wrong.