Skip to content
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

fix(template): duplicate issue #8541

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/app/src/app/components/Create/CreateBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,12 @@ export const CreateBox: React.FC<CreateBoxProps> = ({

const recentlyUsedTemplates = recentTemplates.slice(0, 4);
const hasRecentlyUsedTemplates = recentlyUsedTemplates.length > 0;
const recentlyUsedTemplatesIds = recentlyUsedTemplates.map(t => t.id);

const featuredTemplates = FEATURED_IDS.map(id =>
officialTemplates.find(
t => t.id === id && !recentlyUsedTemplatesIds.includes(t.id)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not exclude templates from this list, because templates are combined now and there is a risky that one recent template exclude the combination template

)
officialTemplates.find(t => t.id === id)
)
.filter(Boolean)
.slice(0, hasRecentlyUsedTemplates ? 6 : 9);
.slice(0, hasRecentlyUsedTemplates ? 8 : 12);

let filteredTemplates = officialTemplates.concat(teamTemplates);

Expand Down Expand Up @@ -373,6 +370,7 @@ const CreateBoxConfig: React.FC<{
}) => {
const { hasLogIn, activeTeam } = useAppState();
const actions = useActions();
const [loading, setLoading] = useState(false);

const mediaQuery = window.matchMedia('screen and (max-width: 950px)');
const mobileScreenSize = mediaQuery.matches;
Expand Down Expand Up @@ -409,6 +407,8 @@ const CreateBoxConfig: React.FC<{
...(customVMTier ? { vm_tier: customVMTier } : {}),
});

setLoading(true);

actions.editor
.forkExternalSandbox({
sandboxId,
Expand Down Expand Up @@ -439,11 +439,12 @@ const CreateBoxConfig: React.FC<{
'*'
);
}
})
.finally(() => {
if (closeModal) {
closeModal();
}
});

if (closeModal) {
closeModal();
}
};

return (
Expand Down Expand Up @@ -504,6 +505,7 @@ const CreateBoxConfig: React.FC<{
createFromTemplate(selectedTemplate, params);
}}
onClose={() => closeModal()}
loading={loading}
/>
</ModalContent>
</ModalBody>
Expand Down
15 changes: 12 additions & 3 deletions packages/app/src/app/components/Create/CreateBox/CreateBoxForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface CreateBoxFormProps {
template: SandboxToFork;
initialPrivacy?: PrivacyLevel;
collectionId: string | undefined;
loading: boolean;
setCollectionId: (collectionId: string | undefined) => void;
onCancel: () => void;
onSubmit: (params: CreateParams) => void;
Expand All @@ -37,6 +38,7 @@ export const CreateBoxForm: React.FC<CreateBoxFormProps> = ({
template,
initialPrivacy,
collectionId,
loading,
setCollectionId,
onCancel,
onSubmit,
Expand Down Expand Up @@ -337,7 +339,9 @@ export const CreateBoxForm: React.FC<CreateBoxFormProps> = ({
defaultValue={editor}
onChange={({ target: { value } }) => setEditor(value)}
>
<option value="csb">VS Code for the web (CodeSandbox.io)</option>
<option value="csb">
VS Code for the web (CodeSandbox.io)
</option>
<option value="vscode">
VS Code Desktop (CodeSandbox extension)
</option>
Expand All @@ -358,11 +362,16 @@ export const CreateBoxForm: React.FC<CreateBoxFormProps> = ({
Cancel
</Button>
{hasLogIn ? (
<Button type="submit" variant="primary" autoWidth>
<Button type="submit" variant="primary" autoWidth loading={loading}>
Create {label}
</Button>
) : (
<Button autoWidth onClick={() => signInClicked()} type="button">
<Button
autoWidth
onClick={() => signInClicked()}
type="button"
loading={loading}
>
Sign in to create {label}
</Button>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/app/components/Create/TemplateList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const TemplateList = ({
<TemplateGrid>
{templates.map(template => (
<TemplateCard
key={template.id}
key={template.id + template.browserSandboxId}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing duplicated templates

template={template}
onSelectTemplate={onSelectTemplate}
onOpenTemplate={onOpenTemplate}
Expand Down
Loading