Is there a way to use a fields value in the Model to set a style attribute dynamically?

I have created a CSHTML email template file to send alerts when a specific event is about to end (i.e. sends an alert 10-minutes before end, then at 5-minutes before end, etc.). I want to highlight the type of event (since there can be more than one) by color to differentiate the messages. What I currently have is this:

<strong style="color: {event color}">@alert.event</strong> is scheduled to end: <strong>@endEasternTime

I would like to be able to set the {event color} based on the value in @alert.event, but I’m not sure that I can. I tried to create a script in the file, but I’m not sure how to get its return value into the style tag:

<script>
    // Get the root element
    var r = document.querySelector(':root');

    // Create a function for getting a variable value
    function getEventColor(event) {
        // Get the styles (properties and values) for the root
        var rs = getComputedStyle(r);

        // Get the color associated with the event (default is the border color)
        return (event === "event1"
            ? rs.getPropertyValue('--evt1Color')
            : (event === "event2"
                ? rs.getPropertyValue('--evt2Color')
                : (event === "event3"
                    ? rs.getPropertyValue('--evt3Color')
                    : rs.getPropertyValue('--bdrColor')
                    )
                )
            );
    }
</script>

Note that I have created HTML variables in the file to match up the colors to other styles in the file (such as border-color) — for space considerations and clarity, I’m not going to show that here.

Is there a way to do this? If not using the inline CSS above, can I update a class or id on the fly using something like the script method above and, if so, what’s the best way. I appreciate any help.

Using a getter in array but getter won’t get the updated version (JAVA)

So basically I have this in one of my files:

public class Player {

private String[] PlayerWeaps;

public Player(){
    PlayerWeaps = new String[5];

}

public void addWeap(int index,String name){
    PlayerWeaps[index] = name;
}

public String[] getPlWeaps(){
    return this.PlayerWeaps;
}

And whenever I call it on my other file as

public class GM{
  private Player player; 
  public GM(){
   this.player = new Player();
   }

  public void run(){
   for(int i=0;i<5;i++){
    System.out.println("Weapons: " + player.getPlWeaps(i));  //this guy return's null
   }
  }
}

I also tried assigning player.getPlWeaps first but it doesn’t work too.

note: I’m self studying JAVA so I’m really not sure if theres something I have missed

How to get key from destructed object sweetalert2

Below code pops up a modal in the view that user select one of the options and then shows the selected option, I also need the id of selected option. e.g I need to get “4” if user select “John”. I am not sure how can I get it

        async function accept() {
            const { value: student } = await Swal.fire({
                input: 'select',
                width: 260,
                inputOptions: {
                    1: 'Peter',
                    2: 'Sam',
                    3: 'Tom',
                    4: 'John'
                },
                inputPlaceholder: 'Select student',
                showCancelButton: true,
            })
            if (student) {
                Swal.fire(`You selected: ${student}`)
                console.log('Id: ' ?????)
            }
        }

Format currency input field with dollar sign & commas

I have a revenue input field in a javascript/jquery form:

  1. Need a dollar sign :before
  2. add commas as the currency increases

I have a dollar sign showing via css, but issues centering it and ensuring the field entry point is next to it without overlapping. Unsure how to do the commas. Any suggestions or tips are welcome!

HTML:

  <form id="rev-calculator">
  <label for="price">Monthly Revenue</label>
  <div class="fields">
    <input type="number" name="price" id="price" min="0" max="10000000000" required data-type="number"> </input>
    <br>
  </form>

CSS:

  <style>
      .body {
        text-align: left;
      }
      
      .fields {
        margin: 0 10px 0 0;
      }
      
      .fields:before {
        content: "$";
        text-align: center;
        position: relative;
        left:30px;
      }
      
      #price {
        border-radius: 5px;
        margin: 15px;
        padding: 10px;
        color: black;
      }
    </style>

JS:

<script>
  $('#rev-calculator').on('click', 'button', function(e) {
    e.preventDefault();
    var price = $("#price").val();
    console.log(price);
  })
</script>

codepen: https://codepen.io/kedarPE/pen/JjroYyb

input field

Typescript JSX with Generics – Parameter implicitly has an ‘any’ type

When using JSX syntax with Generics, Typescript is able to infer properties normally, except the type of function parameters.

Example code:

interface Dictionary {
  a: JSX.IntrinsicElements['a'];
  button: JSX.IntrinsicElements['button'];
}

type Props<T extends 'a' | 'button'> = Dictionary[T] & {
  as: T;
};

function Test<T extends 'a' | 'button'>(args: Props<T>) {
  return null;
}

<Test as="a" href="#" onClick={(arg) => {}} />; // Parameter 'arg' implicitly has an 'any' type.

Test({
  as: 'a',
  href: '#',
  onClick: (arg) => {}, // No error
});

TS Playground

If I place the mouse over the onClick property, it can tell the type of the onClick (React.MouseEventHandler<HTMLAnchorElement>), but still cannot infer the parameter’s type.

Tiny slider is tweaking at first image change and then go smooth. Thanks

like in topic, i have tiny slider who is tweaking at first change of image like 2 times and then go smooth and all is good, but first load gives tweak of try 2 change image.
Maybe u can figure it out? Really thanks for time, and i am fresh in webdev so dont be rude at me 😛

$(function() {
  const wrapper = $('#slider');

  setInterval(function() {
    const firstChild = $(wrapper).children()[0];
    $(firstChild)
      .fadeOut(1000)
      .next('a')
      .fadeIn(1000)
      .end()
      .appendTo('#slider');
  }, 3000);
});
img {
  max-width: 100%;
}

#slider:after {
  content: "";
  display: table;
  clear: both;
}

#slider img {
  float: left;
  margin: 0 -100% 0 0;
}

#slider {
  width: 200px;
  background-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<figure id="slider">
  <a target="_blank" href="http://www.google.pl">
    <img src="https://i1.kwejk.pl/k/obrazki/2020/11/kwzgq1D7NOtJnNRp.jpg" />
  </a>
  <a target="_blank" href="http://www.google.pl">

    <img src="https://media.istockphoto.com/vectors/adorable-hedgehog-in-modern-flat-style-vector-vector-id930758362?k=20&m=930758362&s=612x612&w=0&h=UjgzuyypJq1tNI3RVKqlB1DjS1He72xtlw47DNWvFi8=" />
  </a>
  <a target="_blank" href="http://www.google.pl">

    <img src="https://img.redro.pl/plakaty/african-hedgehog-rolling-over-while-looking-at-camera-happy-400-195157167.jpg" />
  </a>
</figure>

Pushing elements and printing them as UL doesn’t work

I’m stuck. Trying to push input values into an array, which actually works, but then I want to get them out into an unordered list, and they don’t show up. What am I doing wrong?

const inputBtn = document.querySelector("#input-btn");
let myLeads = [];
const inputEl = document.querySelector("#input-el");
const ulEl = document.querySelector("#ul-el");

inputBtn.addEventListener("click", function() {
  myLeads.push(inputEl.value);
  console.log(myLeads);
});

for (let i = 0; i < myLeads.length; i++) {
  ulEl.innerHTML += "<li>" + myLeads[i] + "</li>";
}
<input type="text" id="input-el" />
<button id="input-btn">SAVE INPUT</button>
<ul id="ul-el"></ul>

stop creation of LICENSE.txt files

When I run yarn build I get a .LICENSE.txt for every .js file in addition to my .js files. I would like it to stop making those files

I am basing my current solution off of this link
Webpack – omit creation of LICENSE.txt files

The .LICENSE is still being created. This is my webpack.config.js code

const commonConfig = require('./webpack-config/webpack.common.config.js');
const developmentConfig = require('./webpack-config/webpack.development.config.js');
const productionConfig = require('./webpack-config/webpack.production.config.js');
const TerserPlugin = require('terser-webpack-plugin');

// - Webpack configurations
// merge configurations
module.exports = merge(
  // entryPlus plugin allows us to use dynamic entries
  {
    entry: entryPlus(entryObjectsArray),
  },
  // include config needed across all builds
  commonConfig,
  developmentConfig,
  productionConfig,
  {
    optimization: {
      minimizer: [new TerserPlugin({
        extractComments: false,
      })],
    }
  }
  
);

Electron: Unable to load preload script: Resources/app.asar/src/preload.js

I have an electron app that builds and runs in development, but when packaging the app with electron-builder, the preload script is not packaged in the right location.

This is a well documented issue and there are very similar questions here and here for example, but none of the replies or solutions are working in my case.

From my electron.js file:

function createWindow() {
    const mainWindow = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            preload: path.join(app.getAppPath(), 'src/preload.js'),
            contextIsolation: true,
        },
    });

    // In production, set the initial browser path to the local bundle generated
    // by the Create React App build process.
    // In development, set it to localhost to allow live/hot-reloading.
    const appURL = app.isPackaged
        ? url.format({
            pathname: path.join(__dirname, 'index.html'),
            protocol: 'file:',
            slashes: true,
        })
        : 'http://localhost:3000';
    mainWindow.loadURL(appURL);

    mainWindow.webContents.openDevTools();
}

My preload script:

const { contextBridge, shell } = require('electron')

contextBridge.exposeInMainWorld(
    'electron',
    {
        openBrowserWindow: (url) => shell.openExternal(url)
    }
)

And my Electron app package.json:

    "build": {
        "extends": null,
        "appId": "com.app",
        "productName": "App",
        "directories": {
            "output": "dist"
        },
        "mac": {
            "target": {
                "target": "pkg",
                "arch": [
                    "universal"
                ]
            },
            "darkModeSupport": "true",
            "extendInfo": "app"
        },
        "pkg": {
            "installLocation": "/Applications",
            "overwriteAction": "upgrade"
        },
        "files": [
            "**",
            "../app/src/*",
            "src/preload.js"
        ],
        "extraResources": [
            "../app/src/*",
            "src/preload.js"
        ],
        "extraFiles": [
            "../app/src/*",
            "src/preload.js"
        ]
    }

Above I have tried to make sure the “src/preload.js” file is copied over in different ways, but I still get the error:

Unable to load preload script: …app/Contents/Resources/app.asar/src/preload.js

Error: Cannot find module ‘…app/Contents/Resources/app.asar/src/preload.js’

The preload script is in fact copied over, but it is not part of the app.asar file. It is copied in to a src folder outside of the Resources folder which contains the app.asar file:

enter image description here

How do I correctly configure electron-builder so this file is in the right location and can be accessed at package runtime?

Parallel execution with redux dispatch and error handling

I would want to execute in parallel two API calls inside my thunk. However, I need to properly handle the errors. I have prepared simplified version of my async functions. Sections I want to parallelize are commented.

async function addCredentialA() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      if (Math.random() < 0.5)
        return resolve({status: '200'})
      else
        return reject({status: '500'})
    }, 1000)
  });
}

async function addCredentialB() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      if (Math.random() < 0.3)
        return resolve({status: '200'})
      else
        return reject({status: '500'})
    }, 2000)
  });
}

async function addCredentials(sendRequestA: boolean, sendRequestB: boolean) {
  try {
    // This should be parallel
    if (sendRequestA) {
      try {
        await addCredentialA()
        console.log('Successfully added credential A')
      } catch (e) {
        console.log('Something wrong with credential A', e)
        throw e
      }
    } 

    // This should be parallel
    if (sendRequestB) {
      try {
        await addCredentialB()
        console.log('Successfully added credential B')
      } catch (e) {
        console.log('Something wrong with credential B', e)
        throw e
      }
    } 

    console.log('Succesfully added two credentials')
  } catch (e) {
    console.log('There was problem with adding credentials')
    console.log(e)
  }
}

addCredentials(true, true)

TypeScript playground