mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-15 00:01:10 +02:00
♻️ refactor: remove duplicated code (Quick Wins)
- Delete unused Input.svelte from Picture app (70 LOC) - Remove sleep() from shared-api-client, import from shared-utils - Fix NodeJS.Timeout type for browser compatibility Part of consolidation effort - see docs/CONSOLIDATION_OPPORTUNITIES.md Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
0a6a1dcd1a
commit
1348fca84d
6 changed files with 9 additions and 78 deletions
|
|
@ -1,69 +0,0 @@
|
|||
<script lang="ts">
|
||||
interface Props {
|
||||
type?: 'text' | 'email' | 'password' | 'number' | 'tel' | 'url';
|
||||
value?: string;
|
||||
placeholder?: string;
|
||||
label?: string;
|
||||
error?: string;
|
||||
disabled?: boolean;
|
||||
required?: boolean;
|
||||
class?: string;
|
||||
id?: string;
|
||||
name?: string;
|
||||
autocomplete?: AutoFill;
|
||||
onchange?: (e: Event) => void;
|
||||
oninput?: (e: Event) => void;
|
||||
}
|
||||
|
||||
let {
|
||||
type = 'text',
|
||||
value = $bindable(''),
|
||||
placeholder = '',
|
||||
label = '',
|
||||
error = '',
|
||||
disabled = false,
|
||||
required = false,
|
||||
class: className = '',
|
||||
id = '',
|
||||
name = '',
|
||||
autocomplete,
|
||||
onchange,
|
||||
oninput,
|
||||
}: Props = $props();
|
||||
|
||||
const inputId = id || name || `input-${Math.random().toString(36).substr(2, 9)}`;
|
||||
|
||||
const baseStyles =
|
||||
'flex h-10 w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50';
|
||||
|
||||
const errorStyles = error ? 'border-red-500 focus:ring-red-600' : '';
|
||||
|
||||
const inputClass = `${baseStyles} ${errorStyles} ${className}`;
|
||||
</script>
|
||||
|
||||
{#if label}
|
||||
<label for={inputId} class="mb-2 block text-sm font-medium text-gray-700">
|
||||
{label}
|
||||
{#if required}
|
||||
<span class="text-red-500">*</span>
|
||||
{/if}
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
<input
|
||||
{type}
|
||||
bind:value
|
||||
{placeholder}
|
||||
{disabled}
|
||||
{required}
|
||||
{name}
|
||||
{autocomplete}
|
||||
id={inputId}
|
||||
class={inputClass}
|
||||
{onchange}
|
||||
{oninput}
|
||||
/>
|
||||
|
||||
{#if error}
|
||||
<p class="mt-1 text-sm text-red-600">{error}</p>
|
||||
{/if}
|
||||
|
|
@ -15,6 +15,9 @@
|
|||
"build": "tsc",
|
||||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@manacore/shared-utils": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import {
|
|||
getErrorCodeFromStatus,
|
||||
isRetryableError,
|
||||
parseErrorResponse,
|
||||
sleep,
|
||||
} from './utils';
|
||||
import { sleep } from '@manacore/shared-utils';
|
||||
|
||||
const DEFAULT_TIMEOUT = 30000;
|
||||
const DEFAULT_RETRIES = 0;
|
||||
|
|
|
|||
|
|
@ -59,13 +59,6 @@ export async function parseErrorResponse(response: Response): Promise<string> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleep utility for retry delays
|
||||
*/
|
||||
export function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if error is retryable (network issues, 5xx errors)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ export function debounce<T extends (...args: any[]) => any>(
|
|||
fn: T,
|
||||
delay: number
|
||||
): (...args: Parameters<T>) => void {
|
||||
let timeoutId: NodeJS.Timeout | null = null;
|
||||
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
return (...args: Parameters<T>) => {
|
||||
if (timeoutId) {
|
||||
|
|
|
|||
4
pnpm-lock.yaml
generated
4
pnpm-lock.yaml
generated
|
|
@ -4472,6 +4472,10 @@ importers:
|
|||
version: 5.9.3
|
||||
|
||||
packages/shared-api-client:
|
||||
dependencies:
|
||||
'@manacore/shared-utils':
|
||||
specifier: workspace:*
|
||||
version: link:../shared-utils
|
||||
devDependencies:
|
||||
typescript:
|
||||
specifier: ^5.9.3
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue