Skip to content

Commit 4493f30

Browse files
committed
refactor step selection modal
1 parent 5537a86 commit 4493f30

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

web/src/lib/modals/AddWorkflowStepModal.svelte

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import type { PluginActionResponseDto, PluginFilterResponseDto } from '@immich/sdk';
3-
import { Icon, Modal, ModalBody, Text } from '@immich/ui';
3+
import { Modal, ModalBody, Text } from '@immich/ui';
44
import { mdiFilterOutline, mdiPlayCircleOutline } from '@mdi/js';
55
import { t } from 'svelte-i18n';
66
@@ -18,62 +18,61 @@
1818
const handleSelect = (type: StepType, item: PluginFilterResponseDto | PluginActionResponseDto) => {
1919
onClose({ type, item });
2020
};
21+
22+
const getModalTitle = () => {
23+
if (type === 'filter') {
24+
return $t('add_filter');
25+
} else if (type === 'action') {
26+
return $t('add_action');
27+
} else {
28+
return $t('add_workflow_step');
29+
}
30+
};
31+
32+
const getModalIcon = () => {
33+
if (type === 'filter') {
34+
return mdiFilterOutline;
35+
} else if (type === 'action') {
36+
return mdiPlayCircleOutline;
37+
} else {
38+
return false;
39+
}
40+
};
2141
</script>
2242

23-
<Modal title={$t('add_workflow_step')} icon={false} onClose={() => onClose()}>
43+
{#snippet stepButton(title: string, description?: string, onclick?: () => void)}
44+
<button
45+
type="button"
46+
{onclick}
47+
class="flex items-start gap-3 p-3 rounded-lg text-left bg-light-100 hover:border-primary border text-dark"
48+
>
49+
<div class="flex-1">
50+
<Text color="primary" class="font-medium">{title}</Text>
51+
{#if description}
52+
<Text size="small" class="mt-1">{description}</Text>
53+
{/if}
54+
</div>
55+
</button>
56+
{/snippet}
57+
58+
<Modal title={getModalTitle()} icon={getModalIcon()} onClose={() => onClose()}>
2459
<ModalBody>
2560
<div class="space-y-6">
2661
<!-- Filters Section -->
2762
{#if filters.length > 0 && (!type || type === 'filter')}
28-
<div class="flex items-center gap-2 mb-3">
29-
<div class="h-6 w-6 rounded-md bg-warning-100 flex items-center justify-center">
30-
<Icon icon={mdiFilterOutline} size="16" class="text-warning" />
31-
</div>
32-
<h3 class="text-sm font-semibold">Filters</h3>
33-
</div>
3463
<div class="grid grid-cols-1 gap-2">
3564
{#each filters as filter (filter.id)}
36-
<button
37-
type="button"
38-
onclick={() => handleSelect('filter', filter)}
39-
class="flex items-start gap-3 p-3 rounded-lg border bg-light-100 hover:border-warning-500 dark:hover:border-warning-500 text-left"
40-
>
41-
<div class="flex-1">
42-
<p class="font-medium text-sm">{filter.title}</p>
43-
{#if filter.description}
44-
<p class="text-xs text-light-500 mt-1">{filter.description}</p>
45-
{/if}
46-
</div>
47-
</button>
65+
{@render stepButton(filter.title, filter.description, () => handleSelect('filter', filter))}
4866
{/each}
4967
</div>
5068
{/if}
5169

5270
<!-- Actions Section -->
5371
{#if actions.length > 0 && (!type || type === 'action')}
54-
<div>
55-
<div class="flex items-center gap-2 mb-3">
56-
<div class="h-6 w-6 rounded-md bg-success-50 flex items-center justify-center">
57-
<Icon icon={mdiPlayCircleOutline} size="16" class="text-success" />
58-
</div>
59-
<h3 class="text-sm font-semibold">Actions</h3>
60-
</div>
61-
<div class="grid grid-cols-1 gap-2">
62-
{#each actions as action (action.id)}
63-
<button
64-
type="button"
65-
onclick={() => handleSelect('action', action)}
66-
class="flex items-start gap-3 p-3 rounded-lg border bg-light-100 hover:border-success-500 dark:hover:border-success-500 text-left"
67-
>
68-
<div class="flex-1">
69-
<p class="font-medium text-sm">{action.title}</p>
70-
{#if action.description}
71-
<Text size="small" class="text-light-500 mt-1">{action.description}</Text>
72-
{/if}
73-
</div>
74-
</button>
75-
{/each}
76-
</div>
72+
<div class="grid grid-cols-1 gap-2">
73+
{#each actions as action (action.id)}
74+
{@render stepButton(action.title, action.description, () => handleSelect('action', action))}
75+
{/each}
7776
</div>
7877
{/if}
7978
</div>

web/src/routes/(user)/utilities/workflows/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
{#each workflows as workflow (workflow.id)}
204204
<Card class="border border-light-200">
205205
<CardHeader
206-
class={`flex flex-col px-8 py-6 gap-4 sm:flex-row sm:items-center sm:gap-6 ${
206+
class={`flex flex-row px-8 py-6 gap-4 sm:items-center sm:gap-6 ${
207207
workflow.enabled
208208
? 'bg-linear-to-r from-green-50 to-white dark:from-green-800/50 dark:to-green-950/45'
209209
: 'bg-neutral-50 dark:bg-neutral-900'
@@ -222,7 +222,7 @@
222222
</div>
223223

224224
<div class="flex items-center gap-4">
225-
<div class="text-right">
225+
<div class="text-right hidden sm:block">
226226
<Text size="tiny">{$t('created_at')}</Text>
227227
<Text size="small" class="font-medium">
228228
{formatTimestamp(workflow.createdAt)}

0 commit comments

Comments
 (0)