-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: add template related in detail (T1389) #2323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
93 changes: 93 additions & 0 deletions
93
apps/nextjs-app/src/features/app/components/space/template/RecommendTemplate.tsx
This file contains hidden or 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,93 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { getPublishedTemplateList } from '@teable/openapi'; | ||
| import { ReactQueryKeys } from '@teable/sdk/config/react-query-keys'; | ||
| import { Spin } from '@teable/ui-lib/base'; | ||
| import { cn } from '@teable/ui-lib/shadcn'; | ||
| import { useTranslation } from 'next-i18next'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| interface IRecommendTemplateProps { | ||
| filterTemplateIds?: string[]; | ||
| onTemplateClick?: (templateId: string) => void; | ||
| className?: string; | ||
| } | ||
|
|
||
| export const RecommendTemplate = (props: IRecommendTemplateProps) => { | ||
| const { onTemplateClick, className, filterTemplateIds } = props; | ||
| const { t } = useTranslation('common'); | ||
|
|
||
| const { data: templates, isLoading } = useQuery({ | ||
| queryKey: [...ReactQueryKeys.publishedTemplateList(null, '', true), 'recommend'], | ||
| queryFn: () => getPublishedTemplateList({ featured: true, take: 4 }).then((res) => res.data), | ||
| }); | ||
|
|
||
| const filteredTemplates = useMemo(() => { | ||
| return templates?.filter((template) => !filterTemplateIds?.includes(template.id))?.slice(0, 3); | ||
| }, [templates, filterTemplateIds]); | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <div className="flex items-center justify-center p-8"> | ||
| <Spin className="size-6" /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (!templates || templates.length === 0) { | ||
|
boris-w marked this conversation as resolved.
|
||
| return null; | ||
| } | ||
|
|
||
| const handleTemplateClick = (templateId: string) => { | ||
| onTemplateClick?.(templateId); | ||
| }; | ||
|
|
||
| const handleKeyDown = (e: React.KeyboardEvent, templateId: string) => { | ||
| if (e.key === 'Enter' || e.key === ' ') { | ||
| e.preventDefault(); | ||
|
boris-w marked this conversation as resolved.
|
||
| handleTemplateClick(templateId); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={cn('flex flex-col items-start justify-start gap-3 self-stretch', className)}> | ||
| <p className="text-base font-semibold text-foreground"> | ||
| {t('settings.templateAdmin.relatedTemplates')} | ||
| </p> | ||
| <div className="flex flex-col items-start justify-start gap-4 self-stretch md:flex-row"> | ||
| {filteredTemplates?.map((template) => ( | ||
| <div | ||
| key={template.id} | ||
| role="button" | ||
| tabIndex={0} | ||
| className="group relative flex h-64 w-full cursor-pointer flex-col items-start justify-start overflow-hidden rounded-lg border border-border bg-background transition-shadow hover:shadow-md focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 md:max-w-[33%] md:flex-1" | ||
| onClick={() => handleTemplateClick(template.id)} | ||
| onKeyDown={(e) => handleKeyDown(e, template.id)} | ||
| > | ||
| <div className="relative h-[218px] w-full self-stretch overflow-hidden bg-secondary"> | ||
| {template.cover?.presignedUrl ? ( | ||
| <img | ||
| src={template.cover.presignedUrl} | ||
| alt={template.name} | ||
|
boris-w marked this conversation as resolved.
|
||
| className="size-full object-cover transition-all duration-300 group-hover:scale-105" | ||
| /> | ||
| ) : ( | ||
| <div className="flex size-full items-center justify-center"> | ||
| <span className="text-sm text-muted-foreground"> | ||
| {t('settings.templateAdmin.noImage')} | ||
| </span> | ||
| </div> | ||
| )} | ||
| </div> | ||
| <div className="flex flex-col items-start justify-center gap-2 self-stretch border-t border-border bg-background p-3"> | ||
| <div className="relative flex flex-col items-start justify-start gap-1 self-stretch"> | ||
| <p className="w-full truncate text-sm font-medium text-foreground"> | ||
| {template.name} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.