Skip to content

Commit

Permalink
Initial solution
Browse files Browse the repository at this point in the history
  • Loading branch information
elsoazemelet committed Feb 14, 2025
1 parent 1cc32de commit e5e333c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const BaseConfigSchema = z.object({
patch: z.string()
})
.optional(),
configType: z.enum(["profile", "preset"]),
configType: z.enum(["profile", "preset", "snippet"]),
configs: z.any(),
owner: z.string().optional(),
virtualPath: z.string().optional()
Expand Down
6 changes: 5 additions & 1 deletion src/routes/ConfigCardEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
$: handleCompatibleConfigsChange($compatible_config_types);
function handleCompatibleConfigsChange(types: string[]) {
compatible = types.includes(data.type);
if (data.configType === "snippet") {
compatible = true;
} else {
compatible = types.includes(data.type);
}
}
function handleToggle() {
Expand Down
52 changes: 32 additions & 20 deletions src/routes/ConfigurationSave.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts" context="module">
export enum ConfigurationSaveType {
MODULE = 0,
ELEMENT = 1
ELEMENT = 1,
SNIPPET = 2
}
enum ConfigurationSaveState {
Expand Down Expand Up @@ -104,25 +105,36 @@

<container class="flex w-full">
{#if state === ConfigurationSaveState.SELECT}
<div class="grid grid-cols-[1fr_1fr_auto] gap-2 w-full">
<button
class="flex w-full dark:bg-primary-700 dark:hover:bg-secondary items-center justify-center {selected ===
ConfigurationSaveType.ELEMENT
? 'border-white'
: 'border-transparent'} border-opacity-75 border-2"
on:click={() => handleSelectionChange(ConfigurationSaveType.ELEMENT)}
>
{element} Element
</button>
<button
class="flex w-full dark:bg-primary-700 dark:hover:bg-secondary items-center justify-center {selected ===
ConfigurationSaveType.MODULE
? 'border-white'
: 'border-transparent'} border-opacity-75 border-2"
on:click={() => handleSelectionChange(ConfigurationSaveType.MODULE)}
>
{module} Module
</button>
<div class="flex flex-row gap-2 w-full">
<div class="grid grid-flow-col w-full gap-2">
<button
class="flex w-full dark:bg-primary-700 dark:hover:bg-secondary items-center justify-center {selected ===
ConfigurationSaveType.ELEMENT
? 'border-white'
: 'border-transparent'} border-opacity-75 border-2"
on:click={() => handleSelectionChange(ConfigurationSaveType.ELEMENT)}
>
{element} Element
</button>
<button
class="flex w-full dark:bg-primary-700 dark:hover:bg-secondary items-center justify-center {selected ===
ConfigurationSaveType.MODULE
? 'border-white'
: 'border-transparent'} border-opacity-75 border-2"
on:click={() => handleSelectionChange(ConfigurationSaveType.MODULE)}
>
{module} Module
</button>
<button
class="flex w-full dark:bg-primary-700 dark:hover:bg-secondary items-center justify-center {selected ===
ConfigurationSaveType.SNIPPET
? 'border-white'
: 'border-transparent'} border-opacity-75 border-2"
on:click={() => handleSelectionChange(ConfigurationSaveType.SNIPPET)}
>
Snippet
</button>
</div>
<div class="flex flex-col gap-2 w-20">
<button
class="px-4 py-1 dark:bg-primary-700 dark:hover:bg-secondary"
Expand Down
21 changes: 14 additions & 7 deletions src/routes/EditorLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,24 @@
}
async function createNewLocalConfigWithTheSelectedModulesConfigurationFromEditor(
type: "profile" | "preset",
type: "profile" | "preset" | "snippet",
name: string
) {
const configResponse = await parentIframeCommunication({
windowPostMessageName: "getCurrenConfigurationFromEditor",
dataForParent: { configType: type }
});
configResponse.data.name = name;
if (configResponse.ok) {
try {
const configResponse = await parentIframeCommunication({
windowPostMessageName: "getCurrenConfigurationFromEditor",
dataForParent: { configType: type }
});
configResponse.data.name = name;
const config = BaseConfigSchema.parse(configResponse.data);
config.createdAt = new Date();
const cm = get(config_manager);
cm?.saveConfig(config, true).then((e) => {
filter_value.set(new FilterValue());
});
} catch (e) {
console.error(e);
}
}
Expand Down Expand Up @@ -281,6 +284,10 @@
createNewLocalConfigWithTheSelectedModulesConfigurationFromEditor("profile", name);
break;
}
case ConfigurationSaveType.SNIPPET: {
createNewLocalConfigWithTheSelectedModulesConfigurationFromEditor("snippet", name);
break;
}
}
provideSelectedConfigForEditor(undefined);
Expand Down

0 comments on commit e5e333c

Please sign in to comment.