-
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.
added starred and published to artwork versions; can toggle starred f…
…rom sketch dashboard; can publish from profile artwork view
- Loading branch information
Showing
17 changed files
with
390 additions
and
12 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import { type ArtworkVersion } from '@prisma/client' | ||
import { type DateOrString } from '#app/definitions/prisma-helper' | ||
import { type IArtworkBranch } from '../artwork-branch/artwork-branch.server' | ||
import { type IDesignWithType } from '../design/design.server' | ||
import { type ILayerWithDesigns } from '../layer/layer.server' | ||
|
||
// Omitting 'createdAt' and 'updatedAt' from the ArtworkVersion interface | ||
// prisma query returns a string for these fields | ||
type BaseArtworkVersion = Omit<ArtworkVersion, 'createdAt' | 'updatedAt'> | ||
type BaseArtworkVersion = Omit< | ||
ArtworkVersion, | ||
'createdAt' | 'updatedAt' | 'publishedAt' | ||
> | ||
|
||
export interface IArtworkVersion extends BaseArtworkVersion { | ||
createdAt: DateOrString | ||
updatedAt: DateOrString | ||
publishedAt: DateOrString | null | ||
} | ||
|
||
export interface IArtworkVersionWithDesignsAndLayers extends IArtworkVersion { | ||
designs: IDesignWithType[] | ||
layers: ILayerWithDesigns[] | ||
} | ||
|
||
export interface IArtworkVersionWithBranch extends IArtworkVersion { | ||
branch: IArtworkBranch | ||
} |
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
117 changes: 117 additions & 0 deletions
117
app/routes/resources+/api.v1+/artwork-version.update.published.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,117 @@ | ||
import { useForm } from '@conform-to/react' | ||
import { getFieldsetConstraint } from '@conform-to/zod' | ||
import { | ||
json, | ||
type ActionFunctionArgs, | ||
type LoaderFunctionArgs, | ||
} from '@remix-run/node' | ||
import { useFetcher } from '@remix-run/react' | ||
import { AuthenticityTokenInput } from 'remix-utils/csrf/react' | ||
import { redirectBack } from 'remix-utils/redirect-back' | ||
import { useHydrated } from 'remix-utils/use-hydrated' | ||
import { PanelIconButton } from '#app/components/ui/panel-icon-button' | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger, | ||
} from '#app/components/ui/tooltip' | ||
import { type IArtworkVersion } from '#app/models/artwork-version/artwork-version.server' | ||
import { validateArtworkVersionPublishedSubmission } from '#app/models/artwork-version/artwork-version.update.server' | ||
import { ArtworkVersionPublishedSchema } from '#app/schema/artwork-version' | ||
import { validateNoJS } from '#app/schema/form-data' | ||
import { updateArtworkVersionPublishedService } from '#app/services/artwork/version/update.service' | ||
import { requireUserId } from '#app/utils/auth.server' | ||
import { useIsPending } from '#app/utils/misc' | ||
import { Routes } from '#app/utils/routes.const' | ||
|
||
// https://www.epicweb.dev/full-stack-components | ||
|
||
const route = Routes.RESOURCES.API.V1.ARTWORK_VERSION.UPDATE.PUBLISHED | ||
const schema = ArtworkVersionPublishedSchema | ||
|
||
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 createSuccess = false | ||
const { status, submission } = | ||
await validateArtworkVersionPublishedSubmission({ | ||
userId, | ||
formData, | ||
}) | ||
|
||
if (status === 'success') { | ||
const { success } = await updateArtworkVersionPublishedService({ | ||
userId, | ||
...submission.value, | ||
}) | ||
createSuccess = success | ||
} | ||
|
||
if (noJS) { | ||
throw redirectBack(request, { | ||
fallback: '/', | ||
}) | ||
} | ||
|
||
return json( | ||
{ status, submission }, | ||
{ | ||
status: status === 'error' || !createSuccess ? 422 : 201, | ||
}, | ||
) | ||
} | ||
|
||
export const ArtworkVersionTogglePublished = ({ | ||
version, | ||
}: { | ||
version: IArtworkVersion | ||
}) => { | ||
const versionId = version.id | ||
const isPublished = version.published | ||
// these icons 😂 | ||
const icon = isPublished ? 'crumpled-paper' : 'rocket' | ||
const iconText = isPublished ? 'Unpublish version' : 'Publish version' | ||
|
||
const fetcher = useFetcher<typeof action>() | ||
const lastSubmission = fetcher.data?.submission | ||
const isPending = useIsPending() | ||
let isHydrated = useHydrated() | ||
const [form] = useForm({ | ||
id: `artwork-version-toggle-published-${versionId}`, | ||
constraint: getFieldsetConstraint(schema), | ||
lastSubmission, | ||
}) | ||
|
||
return ( | ||
<fetcher.Form method="POST" action={route} {...form.props}> | ||
<AuthenticityTokenInput /> | ||
|
||
<input type="hidden" name="no-js" value={String(!isHydrated)} /> | ||
<input type="hidden" name="id" value={versionId} /> | ||
|
||
{isHydrated ? ( | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<PanelIconButton | ||
type="submit" | ||
iconName={icon} | ||
iconText={iconText} | ||
disabled={isPending} | ||
/> | ||
</TooltipTrigger> | ||
<TooltipContent>{iconText}</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
) : null} | ||
</fetcher.Form> | ||
) | ||
} |
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
Oops, something went wrong.