diff --git a/src/routes/options-flow/+page.svelte b/src/routes/options-flow/+page.svelte index 8e28182f..93f97c33 100644 --- a/src/routes/options-flow/+page.svelte +++ b/src/routes/options-flow/+page.svelte @@ -19,6 +19,8 @@ let syncWorker: Worker | undefined; let ruleName = ''; + let searchTerm = ''; + let filteredRows = []; let shouldLoadWorker = writable(false); const allRules = { @@ -92,6 +94,7 @@ async function handleResetAll() { function changeRule(state: string) { + searchTerm = ''; ruleName = state; handleAddRule() @@ -134,27 +137,31 @@ function handleAddRule() { async function handleRule(newRule) { const existingRuleIndex = ruleOfList.findIndex(rule => rule.name === newRule.name); + if (existingRuleIndex !== -1) { const existingRule = ruleOfList[existingRuleIndex]; - if (existingRule.value === newRule.value && existingRule.condition === newRule.condition) { - toast.error('Rule already exists!', { - style: 'border-radius: 200px; background: #333; color: #fff;' + if (existingRule.name === newRule.name) { + // Remove the rule instead of showing an error + ruleOfList.splice(existingRuleIndex, 1); + ruleOfList = [...ruleOfList]; // Trigger reactivity + Object.keys(allRules).forEach(ruleName => { + ruleCondition[ruleName] = allRules[ruleName].defaultCondition; + valueMappings[ruleName] = allRules[ruleName].defaultValue; }); + displayRules = allRows?.filter(row => ruleOfList.some(rule => rule.name === row.rule)); } else { ruleOfList[existingRuleIndex] = newRule; ruleOfList = [...ruleOfList]; // Trigger reactivity - toast.success('Rule updated', { - style: 'border-radius: 200px; background: #333; color: #fff;' - }); } } else { ruleOfList = [...ruleOfList, newRule]; + /* toast.success('Rule added', { style: 'border-radius: 200px; background: #333; color: #fff;' }); + */ - shouldLoadWorker.set(true); - + shouldLoadWorker.set(true); } } @@ -609,6 +616,12 @@ function debounce(fn, delay) { const debouncedHandleInput = debounce(handleInput, 300); +$: { + if(searchTerm) + { + filteredRows = allRows?.filter((row) => row?.label?.toLowerCase()?.includes(searchTerm?.toLowerCase())); + } +} @@ -730,7 +743,7 @@ const debouncedHandleInput = debounce(handleInput, 300);
-
+ + + + + + diff --git a/src/routes/stock-screener/[strategyId]/+page.svelte b/src/routes/stock-screener/[strategyId]/+page.svelte index 5bc3be4e..c5c57243 100644 --- a/src/routes/stock-screener/[strategyId]/+page.svelte +++ b/src/routes/stock-screener/[strategyId]/+page.svelte @@ -279,27 +279,26 @@ function handleAddRule() { async function handleRule(newRule) { const existingRuleIndex = ruleOfList.findIndex(rule => rule.name === newRule.name); + if (existingRuleIndex !== -1) { const existingRule = ruleOfList[existingRuleIndex]; - if (existingRule.value === newRule.value && existingRule.condition === newRule.condition) { - toast.error('Rule already exists!', { - style: 'border-radius: 200px; background: #333; color: #fff;' - }); + if (existingRule.name === newRule.name) { + // Remove the rule instead of showing an error + ruleOfList.splice(existingRuleIndex, 1); + ruleOfList = [...ruleOfList]; // Trigger reactivity } else { ruleOfList[existingRuleIndex] = newRule; ruleOfList = [...ruleOfList]; // Trigger reactivity - toast.success('Rule updated', { - style: 'border-radius: 200px; background: #333; color: #fff;' - }); } } else { ruleOfList = [...ruleOfList, newRule]; + /* toast.success('Rule added', { style: 'border-radius: 200px; background: #333; color: #fff;' }); + */ await updateStockScreenerData(); - //await handleSave(false); } } @@ -1222,7 +1221,7 @@ function handleInput(event) {
Add Filters -
+ +