From a3f09f25f1ab917af586a69e87cf2efd36b17503 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 2 Sep 2024 19:01:50 +0200 Subject: [PATCH] update screener --- src/lib/components/shadcn/button/index.ts | 67 ++++---- .../stock-screener/[strategyId]/+page.svelte | 162 +++++++++++++----- 2 files changed, 154 insertions(+), 75 deletions(-) diff --git a/src/lib/components/shadcn/button/index.ts b/src/lib/components/shadcn/button/index.ts index 52506df0..7cc95b54 100644 --- a/src/lib/components/shadcn/button/index.ts +++ b/src/lib/components/shadcn/button/index.ts @@ -3,47 +3,48 @@ import type { Button as ButtonPrimitive } from "bits-ui"; import Root from "./button.svelte"; const buttonVariants = tv({ - base: "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", - variants: { - variant: { - default: "bg-primary text-primary-foreground hover:bg-primary/90", - destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90", - outline: - "border border-input bg-background hover:bg-accent hover:text-accent-foreground", - secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80", - ghost: "hover:bg-accent hover:text-accent-foreground", - link: "text-primary underline-offset-4 hover:underline", - }, - size: { - default: "h-10 px-4 py-2", - sm: "h-9 rounded-md px-3", - lg: "h-11 rounded-md px-8", - icon: "h-10 w-10", - }, - }, - defaultVariants: { - variant: "default", - size: "default", - }, + base: "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", + variants: { + variant: { + default: "bg-primary text-primary-foreground sm:hover:bg-[#09090B]", + destructive: + "bg-destructive text-destructive-foreground sm:hover:bg-[#09090B]", + outline: + "border border-input bg-background hover:bg-accent hover:text-accent-foreground", + secondary: "bg-secondary text-secondary-foreground sm:hover:bg-[#09090B]", + ghost: "hover:bg-accent hover:text-accent-foreground", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-10 px-4 py-2", + sm: "h-9 rounded-md px-3", + lg: "h-11 rounded-md px-8", + icon: "h-10 w-10", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, }); type Variant = VariantProps["variant"]; type Size = VariantProps["size"]; type Props = ButtonPrimitive.Props & { - variant?: Variant; - size?: Size; + variant?: Variant; + size?: Size; }; type Events = ButtonPrimitive.Events; export { - Root, - type Props, - type Events, - // - Root as Button, - type Props as ButtonProps, - type Events as ButtonEvents, - buttonVariants, -}; \ No newline at end of file + Root, + type Props, + type Events, + // + Root as Button, + type Props as ButtonProps, + type Events as ButtonEvents, + buttonVariants, +}; diff --git a/src/routes/stock-screener/[strategyId]/+page.svelte b/src/routes/stock-screener/[strategyId]/+page.svelte index fb68e4f5..aeb37da6 100644 --- a/src/routes/stock-screener/[strategyId]/+page.svelte +++ b/src/routes/stock-screener/[strategyId]/+page.svelte @@ -4,7 +4,8 @@ import { screenWidth, strategyId, numberOfUnreadNotification, getCache, setCache} from '$lib/store'; import toast from 'svelte-french-toast'; import { abbreviateNumber } from '$lib/utils'; - + import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js"; + import { Button } from "$lib/components/shadcn/button/index.js"; //const userConfirmation = confirm('Unsaved changes detected. Leaving now will discard your strategy. Continue?'); export let data; @@ -24,6 +25,7 @@ ); + const getStockScreenerData = async (rules) => { const ruleNames = rules?.map(rule => rule?.name)?.sort()?.join(','); const cachedData = getCache(ruleNames, 'getStockScreenerData'); @@ -509,6 +511,9 @@ async function handleRule(newRule) { } } + +} + async function updateStockScreenerData() { try { const newData = await getStockScreenerData(ruleOfList); @@ -519,7 +524,7 @@ async function updateStockScreenerData() { ) ); - displayRules = allRows.filter(row => ruleOfList.some(rule => rule.name === row.rule)); + displayRules = allRows?.filter(row => ruleOfList?.some(rule => rule.name === row.rule)); filteredData = filterStockScreenerData(); displayResults = filteredData?.slice(0, 50); } catch (error) { @@ -529,9 +534,6 @@ async function updateStockScreenerData() { }); } } - -} - async function handleResetAll() { ruleOfList = []; @@ -635,14 +637,11 @@ async function handleSave(printToast) { } } -async function handleUpdateRule(rule) { - ruleName = rule.name; -} $: { if (ruleOfList) { - const ruleToUpdate = ruleOfList.find(rule => rule.name === ruleName); + const ruleToUpdate = ruleOfList?.find(rule => rule.name === ruleName); if (ruleToUpdate) { const valueMap = { payoutRatio: valuePayoutRatio, @@ -714,13 +713,13 @@ $: { shortOutStandingPercent: valueShortOutStandingPercent, }; - ruleToUpdate.value = valueMap[ruleToUpdate.name] ?? ruleToUpdate.value; ruleToUpdate.condition = ruleCondition[ruleToUpdate.name]; ruleOfList = [...ruleOfList]; } - displayRules = allRows.filter(row => ruleOfList.some(rule => rule.name === row.rule)); + console.log('yes here') + displayRules = allRows?.filter(row => ruleOfList.some(rule => rule.name === row.rule)); filteredData = filterStockScreenerData(); if (ruleOfList?.some(item => item?.name === 'ratingRecommendation')) { @@ -1074,6 +1073,43 @@ function handleChangeValue(value) { } +async function preSelectStrategy(state:string) { + //To-do: Piece of shit code needs to be optimized better + if(state === 'dividendGrowth') { + + ruleOfList = [ + { + "condition": "over", + "name": "dividendGrowth", + "value": 5 + }, + { + "condition": "over", + "name": "dividendYield", + "value": 1 + }, + { + "condition": "under", + "name": "payoutRatio", + "value": 60 + }, + { + "condition": "over", + "name": "growthRevenue", + "value": 5 + } + + ]; + ruleOfList?.forEach(row => { + ruleName = row?.name + ruleCondition[ruleName] = row?.condition; + handleChangeValue(row?.value); + }) + await updateStockScreenerData(); + } +} + + @@ -1121,13 +1157,49 @@ function handleChangeValue(value) {
-
+
+

Stock Screener

- + {ruleOfList?.length !== 0 ? filteredData?.length : 0} Matches Found +
+
+ +
+ + + + + + + Popular Strategies + + + + preSelectStrategy('dividendGrowth')} class="cursor-pointer"> + Dividend Growth + + + + + + +
+
+ + + +
@@ -1135,10 +1207,12 @@ function handleChangeValue(value) {
@@ -1192,49 +1266,53 @@ function handleChangeValue(value) {
-
ruleName = row?.rule} class="dropdown dropdown-end"> - - -