-
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.
action to create a new artboard branch version and clone the current …
…version designs and layers
- Loading branch information
Showing
32 changed files
with
685 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createContainerComponent } from './utils' | ||
|
||
// copied from v0.dev | ||
// container for group of buttons | ||
// - box-content so that border and padding is added on top of specified height and width | ||
// specified height, width will depend on how many buttons | ||
// gap-2 for separation between buttons | ||
// rounded-md for rounded corners | ||
// border and background color | ||
const NavbarButtonGroup = createContainerComponent({ | ||
defaultTagName: 'div', | ||
defaultClassName: | ||
'box-content flex h-6 items-center gap-2 rounded-md border border-primary bg-primary-foreground p-1', | ||
displayName: 'NavbarButtonGroup', | ||
}) | ||
|
||
export { NavbarButtonGroup } |
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
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 @@ | ||
export * from './nav-actions' |
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,88 @@ | ||
import { type PopoverProps } from '@radix-ui/react-popover' | ||
import { Link, useParams } from '@remix-run/react' | ||
import { useState } from 'react' | ||
import { Button } from '#app/components/ui/button' | ||
import { | ||
Command, | ||
CommandEmpty, | ||
CommandGroup, | ||
CommandInput, | ||
CommandItem, | ||
} from '#app/components/ui/command' | ||
import { Icon } from '#app/components/ui/icon' | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from '#app/components/ui/popover' | ||
import { type IEntityWithSlug } from '#app/schema/entity' | ||
import { cn } from '#app/utils/misc' | ||
import { capitalize } from '#app/utils/string-formatting' | ||
|
||
interface EntitySelectorProps extends PopoverProps { | ||
entities: IEntityWithSlug[] | ||
entitySingular?: string | ||
entityPlural?: string | ||
placeholder?: string | ||
slugParam?: string | ||
baseUrl: string | ||
} | ||
|
||
export function ComboboxNav({ | ||
entities, | ||
entitySingular = 'entity', | ||
entityPlural = 'entities', | ||
placeholder = 'Select...', | ||
slugParam, | ||
baseUrl, | ||
...props | ||
}: EntitySelectorProps) { | ||
const [open, setOpen] = useState(false) | ||
const params = useParams() | ||
const paramsSlug = slugParam ? params[slugParam] : params.slug | ||
const currentEntity = entities.find(entity => entity.slug === paramsSlug) | ||
|
||
return ( | ||
<Popover open={open} onOpenChange={setOpen} {...props}> | ||
<PopoverTrigger asChild> | ||
<Button | ||
variant="outline" | ||
role="combobox" | ||
aria-label={placeholder} | ||
aria-expanded={open} | ||
className="flex-1 justify-between md:max-w-[200px] lg:max-w-[300px]" | ||
> | ||
{currentEntity?.name || placeholder} | ||
<Icon | ||
name="caret-sort" | ||
className="ml-2 h-4 w-4 shrink-0 opacity-50" | ||
/> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent className="w-[300px] p-0"> | ||
<Command> | ||
<CommandInput placeholder={`Search ${entityPlural}...`} /> | ||
<CommandEmpty>No {entityPlural} found.</CommandEmpty> | ||
<CommandGroup heading={capitalize(entityPlural)}> | ||
{entities.map(entity => ( | ||
<CommandItem key={entity.id} onSelect={() => setOpen(false)}> | ||
<Link prefetch="intent" to={`${baseUrl}/${entity.slug}`}> | ||
{entity.name} | ||
</Link> | ||
<Icon | ||
name="check" | ||
className={cn( | ||
'ml-auto h-4 w-4', | ||
currentEntity?.id === entity.id | ||
? 'opacity-100' | ||
: 'opacity-0', | ||
)} | ||
/> | ||
</CommandItem> | ||
))} | ||
</CommandGroup> | ||
</Command> | ||
</PopoverContent> | ||
</Popover> | ||
) | ||
} |
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
65 changes: 65 additions & 0 deletions
65
app/models/artboard-version/artboard-version.create.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,65 @@ | ||
import { type IntentActionArgs } from '#app/definitions/intent-action-args' | ||
import { NewArtboardVersionSchema } from '#app/schema/artboard-version' | ||
import { ValidateArtboardBranchParentSubmissionStrategy } from '#app/strategies/validate-submission.strategy' | ||
import { validateEntitySubmission } from '#app/utils/conform-utils' | ||
import { prisma } from '#app/utils/db.server' | ||
import { type IArtboardBranch } from '../artboard-branch/artboard-branch.server' | ||
import { type IUser } from '../user/user.server' | ||
import { type IArtboardVersion } from './artboard-version.server' | ||
|
||
export interface IArtboardVersionCreatedResponse { | ||
success: boolean | ||
message?: string | ||
createdArtboardVersion?: IArtboardVersion | ||
} | ||
|
||
export const validateNewArtboardVersionSubmission = async ({ | ||
userId, | ||
formData, | ||
}: IntentActionArgs) => { | ||
const strategy = new ValidateArtboardBranchParentSubmissionStrategy() | ||
|
||
return await validateEntitySubmission({ | ||
userId, | ||
formData, | ||
schema: NewArtboardVersionSchema, | ||
strategy, | ||
}) | ||
} | ||
|
||
export const createArtboardVersion = async ({ | ||
data, | ||
}: { | ||
data: { | ||
ownerId: IUser['id'] | ||
branchId: IArtboardBranch['id'] | ||
name: string | ||
slug: string | ||
description: string | ||
width?: number | ||
height?: number | ||
background?: string | ||
} | ||
}) => { | ||
return await prisma.artboardVersion.create({ | ||
data, | ||
}) | ||
} | ||
|
||
/** | ||
* Increment the version string by one. | ||
* For example, "v0" becomes "v1", "v1" becomes "v2", etc. | ||
* @param {string} name - The current version string. | ||
* @returns {string} - The incremented version string. | ||
*/ | ||
export const incrementVersionNameString = (name: string): string => { | ||
// Assuming the prefix is always 'v' | ||
const versionPrefix = name.slice(0, 1) | ||
// Get the numeric part of the version | ||
const versionNumber = parseInt(name.slice(1)) | ||
if (isNaN(versionNumber)) { | ||
throw new Error(`Invalid version name string: ${name}`) | ||
} | ||
// Increment the version number and return the new version string | ||
return `${versionPrefix}${versionNumber + 1}` | ||
} |
21 changes: 21 additions & 0 deletions
21
app/models/artboard-version/artboard-version.delete.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,21 @@ | ||
import { prisma } from '#app/utils/db.server' | ||
import { type IArtboardVersion } from './artboard-version.server' | ||
|
||
export interface IArtboardVersionDeletedResponse { | ||
success: boolean | ||
message?: string | ||
} | ||
|
||
export const deleteArtboardVersions = ({ | ||
ids, | ||
}: { | ||
ids: IArtboardVersion['id'][] | ||
}) => { | ||
return prisma.artboardVersion.deleteMany({ | ||
where: { | ||
id: { | ||
in: ids, | ||
}, | ||
}, | ||
}) | ||
} |
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
Oops, something went wrong.