Laravel layout keep the nav link with different background

I am making a Dashboard and it has a layout included in all the dashboard pages and it contains links

I need to specify the active page link with different background so I made this

HTML

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>@yield('title')</title>
    <link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="{{ asset('css/dashboard_layout.css') }}">
    <script src="https://kit.fontawesome.com/40a844b83b.js" crossorigin="anonymous"></script>
    @yield('styles')
</head>

<body>
    <div class="exit-dashboard d-flex justify-content-center align-items-center">
        <a href="{{ route('home') }}" class="a-reset">
            <i class="fa-solid fa-globe"></i>
        </a>
    </div>
    <div class="d-flex">
        <div class="sidebar">
            <div class="sidebar-img text-center pt-5">
                <img src="{{ asset('images/location-hover-icon.png') }}" class="w-50">
            </div>
            <div class="sidebar-links pt-5">
                <div class="row flex-column">
                    <a href="#" class="a-reset">
                        <a href="{{ route('dashboard.newcairo.interests') }}" class="a-reset">
                            <div class="sidebar-link py-2">
                                <i class="fa-solid fa-envelope px-2"></i>
                                <h6 class="nexa-bold text-white d-inline-block">iCity New Cairo</h6>
                            </div>
                        </a>
                        <a href="{{ route('dashboard.october.interests') }}" class="a-reset">
                            <div class="sidebar-link py-2">
                                <i class="fa-solid fa-envelope px-2"></i>
                                <h6 class="nexa-bold text-white d-inline-block">iCity October</h6>
                            </div>
                        </a>
                        <a href="{{ route('dashboard.october.chillout.interests') }}" class="a-reset">
                            <div class="sidebar-link py-2">
                                <i class="fa-solid fa-envelope px-2"></i>
                                <h6 class="nexa-bold text-white d-inline-block">Chillout October</h6>
                            </div>
                        </a>
                        <a href="{{ route('dashboard.rashikma.interests') }}" class="a-reset">
                            <div class="sidebar-link py-2">
                                <i class="fa-solid fa-envelope px-2"></i>
                                <h6 class="nexa-bold text-white d-inline-block">Ras El Hikma</h6>
                            </div>
                        </a>
                    </a>
                </div>
            </div>
        </div>
        <div class="main p-5">
            <h3 class="text-white nexa-bold pb-4">@yield('tab-title')</h3>
            <div>
                @yield('content')
            </div>
        </div>
    </div>

    <script src="{{ asset('js/popper.min.js') }}"></script>
    <script src="{{ asset('js/jquery-3.6.0.min.js') }}"></script>
    <script src="{{ asset('js/bootstrap.min.js') }}"></script>
    <script src="{{ asset('js/dashboard_layout.js') }}"></script>
    @yield('scripts')
</body>

</html>

CSS

.sidebar {
    width: 250px;
    height: 100vh;
    background-color: #9E852D;
}

.main {
    width: 100%;
    height: 100vh;
    background-color: #FFF;
}

.exit-dashboard {
    width: 30px;
    height: 30px;
    position: fixed;
    right: 0;
    top: 610px;
    background-color: #B79B3A;
    color: #FFF;
    z-index: 9999999999;
}

JS

$(document).ready(function () {
    $('.sidebar-link').click(function (e) { 
        e.preventDefault();
        $('.sidebar-link').removeClass('active');
        $(this).addClass('active');
    });
});

But when I click on link it reload the page to go to the requested page and layout refreshed and everything returns to the default

What is the easiest way to handle this?

Use mitt in Vue 3 within Vuex Module Action

I have been trying to use mitt inside my vuex module but I always get the “emitter is not defined error”.

This is my main.js:

import { createApp } from "vue";
import App from "./App.vue";

import "@fortawesome/fontawesome-free/css/all.css";
import "@fortawesome/fontawesome-free/js/all.js";
import "@/assets/styles/index.scss";

import mitt from 'mitt'
const emitter = mitt()

import router from "./router";
import store from "./store";

const app = createApp(App).use(router).use(store)
app.config.globalProperties.emitter = emitter
app.mount("#app");

When I try to emit an event from a vuex module action like this:

dispatch("settingIncommingChats", socketData.incomingChats).then(
   () => {
       emitter.emit("chats_updated");
   }
);

I get this error:

Uncaught (in promise) ReferenceError: emitter is not defined
at websocket.js:34:17

Javascript get last element from nested divs

I have the following html structure:

<div>
  <div>
    <div>
        <div></div>
    </div>
    <div>
        <div></div>
    </div>
    ...
    <div>
        <div></div>
    </div> // <---- return this one
  </div>

  <div></div>
</div>

How can I use the JS DOM query to return the last div element marked in the above structure?

Better way to compare two Objects

what is the better way to do this .i am comparing two objects value from default values
if args object do not have this value get from default object

  return {
      first: {
        visible: args.first?.visible ?? defaulttest.first?.visible,
        emoji: args.first?.emoji ?? defaulttest.first?.emoji,
        style: args.first?.style ?? defaulttest.first?.style,
      },
      back: {
        visible: args.back?.visible ?? defaulttest.back?.visible,
        emoji: args.back?.emoji ?? defaulttest.back?.emoji,
        style: args.back?.style ?? defaulttest.back?.style,
      },
      page: {
        visible: args.page?.visible ?? defaulttest.page?.visible,
        emoji: args.page?.emoji ?? defaulttest.page?.emoji,
        style: args.page?.style ?? defaulttest.page?.style,
      },
      forward: {
        visible: args.forward?.visible ?? defaulttest.forward?.visible,
        emoji: args.forward?.emoji ?? defaulttest.forward?.emoji,
        style: args.forward?.style ?? defaulttest.forward?.style,
      },

      last: {
        visible: args.last?.visible ?? defaulttest.last?.visible,
        emoji: args.last?.emoji ?? defaulttest.last?.emoji,
        style: args.last?.style ?? defaulttest.last?.style,
      },
      Mdelete: {
        visible: args.Mdelete?.visible ?? defaulttest.Mdelete?.visible,
        emoji: args.Mdelete?.emoji ?? defaulttest.Mdelete?.emoji,
        style: args.Mdelete?.style ?? defaulttest.Mdelete?.style,
      },
      removeBtn: {
        visible: args.removeBtn?.visible ?? defaulttest.removeBtn?.visible,
        emoji: args.removeBtn?.emoji ?? defaulttest.removeBtn?.emoji,
        style: args.removeBtn?.style ?? defaulttest.removeBtn?.style,
      },
    };

Suggest Suitable Approach or Design Pattern for fallbacks in code

I have a below problem statement and seek better advice on Suitable Approach or Design Pattern for fallbacks in code

  • We have 3 database tables and 1 single node redis instance
  • If redis is down for any reason, We want to query directly from individual tables
  • If redis is up and does not have data from database, cache it

Our moto is application should not go down, depending on redis status and work fine.

I can write if / else logic to check redis status in all calls involved in fetching data
from individual tables but it violates single responsibility principle and code duplication.

For a cleaner maintainable code, I am seeking better advice from community 🙂

Kindly let me know if you have trouble understanding my requirement

Why does this Render Error keeps popping up despite having a return statement?

The error is here , it just returns a render error that a return statement is missing

return 
(  
    <View style={styles.container}>
       {/*  Header */}
       <SafeAreaView>
            <View style={styles.headerWrapper}>                   
               <View style={styles.headerLeft}>
                    <Feather 
                        name='chevron-left' 
                        size={12} 
                        color={colors.darktext}
                    />
               </View>
               <View style={styles.headerRight}>
                    <MaterialCommunityIcons 
                       name='star' 
                       size={12} 
                       color={colors.white}
                    />
               </View>
            </View>
       </SafeAreaView>
    </View>
);

Any help please

Loop through elements in map function in React

I’m trying to loop though an element transcribe.Transcription(sentence) which I’ve got by looping though an array and apply an if condition on the elements and apply the style based on that.

”’

const arr =  value.sort((a, b) => a.id - b.id)
return <RightWrapper>
   { arr.map(transcript => (<p key={transcript.id}style= 
   {{color:set.has(transcript.Transcription) ? 'red' : 'black'
   }} >{transcript.createdAt + "  " + transcript.Transcription + " "} </p> )) }

</RightWrapper>;

”’

If statement on independent variable does not update d3.js svg components

I have a scatter chart on some data that I define like this:

  svg.append('g')
    .attr('transform', `translate(${margin.left},0)`)
    .call(yAxis);

  g
    .selectAll('.scatter')
    .data(data)
    .join('circle')
    .attr('class', 'scatter')
    .attr('cx', (d) => xScale(d.x))
    .attr('cy', (d) => yScale(d.y))
    .attr('r', 3)
    .attr('stroke', 'gray')
    .attr('stroke-width', 0.5)
    .style('fill', (d) => colorScale(d.label as number))
    .style('fill-opacity', (d) => {
      // Get data value
        console.log("Filter is {}", filter);
      if (filter === 'umap') {
        return 0.2;
      }
      else
      {
          return 0.8;
      }
    });

I pass the filter string as a prop, and it gets updated correctly.
However, d3.js does not change its opacity.
So console.log would output a string not equal to umap.
But the if statement enters as if the condition is true.

Can someone point out to why?
Is this some typescript/javascript I do not understand correctly?

Thanks a lot in advance! I am still a beginner.

Module parse failed: Unexpected character ‘#’ in an Angular Project

I am getting this error when I try to use private fields in an Angular Project.

Error: ./src/app/_helpers/sample.js 6:11
Module parse failed: Unexpected character '#' (6:11)
File was processed with these loaders:

./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
./node_modules/@ngtools/webpack/src/ivy/index.js
./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.

sample.js file:

class Sample {

constructor() {
   this.#reloadConfig(); // 6th line
}

#reloadConfig() {
}

Best way to render a newsticker in HTML/CSS/Javascript

We have a ticker in the bottom of an HTML page that shows news, just like a news ticker on TV. We currently use requestAnimationFrame for this but we experience that it does not always animate well and I wonder if anyone knows what would be the best practice for this.

Firstly, we tried running it on a Raspberry Pi and it couldn’t render it well no matter what we tried.

Secondly, we are running it in a Windows PC in a Chrome browser and generally it works well, but if we play a high resolution video on the same page, then the rendering of the ticker becomes really laggy.

I understand that it’s competing for resources but animating a ticker should in principle not require many resources so I think there should be a solution for this.

Here is our current code, but my question is not so much about troubleshooting details in my current code but more about finding the best approach which I assume is something different than what we are doing now:

  private startTicker() {
    const ticker = document.getElementById(`RssTickerContainer_${this.props.rssTicker?.rssTicker?.url}`);
    if (!ticker || !this.state.items || this.state.items.length === 0) {
      setTimeout(() => {
        if (this.props.rssTicker?.rssTicker?.url) {
          // try to fetch rss content again after 1 second
          this.getRssFeed(this.props.rssTicker?.rssTicker?.url, true);
        }
      }, 1000);
      return;
    }
    console.log("Starting RSS ticker");
    const startPosition = this.state.leftPosition;
    let leftPosition = startPosition;
    let lastFrameCalled = performance.now();
    let fps = 0;
    this.animationFrameID = requestAnimationFrame(() => this.animateTicker(lastFrameCalled, fps, startPosition, leftPosition, ticker));
  }

  private animateTicker(lastFrameCalled: number, fps: number, startPosition: number, leftPosition: number, ticker: HTMLElement) {
    // calculate fps
    const timeSinceLastFrame = (performance.now() - lastFrameCalled) / 1000;
    lastFrameCalled = performance.now();
    fps = 1 / timeSinceLastFrame;
    const containerWidth = ticker.getBoundingClientRect().width;
    if (containerWidth <= 0) {
      // no content, component probably has unmounted
      return;
    }
    if ((leftPosition * -1) > containerWidth) {
      // when leftPosition (inversed, since has negative value) is greater than containerWidth,
      // this means that all elements has passed the screen so we restart the ticker
      console.log("Restarting RSS ticker");
      leftPosition = startPosition;
      ticker.style.left = leftPosition + "px";
      this.getRssFeed(this.props.rssTicker?.rssTicker?.url);
    } else {
      const timeToCross = 25;
      // use fps to set the new position to avoid slow animations on weaker devices
      const step = window.innerWidth / timeToCross / fps;
      leftPosition = leftPosition - step;
      ticker.style.left = leftPosition + "px";
    }
    this.animationFrameID = requestAnimationFrame(() => this.animateTicker(lastFrameCalled, fps, startPosition, leftPosition, ticker));
  }

how to make a cropped border in an input

I need to create an input with a border that will change when the input is focused.

The inputs should works in that way:
When input is not focused and is empty, the label should be inside the input:

Input without focus

When user focus the input, or input is filled, the label will move up and the border should be cropped so the label is not obscured by the border.

Input with focus

I’ve tried with adding before element on label with background, but i realized this is not the correct way because input has not background itself and depend on the subpage there can be other background color and finally the resould looked like this:

enter image description here

enter image description here

Could you please help me with this?

Map in Javscript Nodejs

I am working on an existing nodejs application and I found this code in that. Any guidance for this code? or documentation around it?

const removingMap = new Map([
    [['>=', '2021'], {
        props: ['platform'],
        drop: true
    }],
]);

Elements are going inside the nav bar css react

I am making an app using react and it has gotta nav bar. So the problem is that my h1’s and all the stuff are going inside the nav bar – when I mean that I mean that it is going through the nav bar –

    <nav class="header">
      <a href="" class="logo">
        INDUSTRIES
      </a>
      <input class="menu-btn" type="checkbox" id="menu-btn" />
      <label class="menu-icon" for="menu-btn">
        <span class="navicon"></span>
      </label>
      <ul class="menu">
        <li>
          <Link to="/">Home</Link>
        </li>
        <li>
          <Link to="/blogs">Text</Link>
        </li>
        <li>
          <Link to="/contact">Contact</Link>
        </li>
      </ul>
    </nav>

and here is this css

* {
  margin: 0;
  padding: 0;
}

a {
  color: #000;
}

/* header */

.header {
  background-color: #fff;
  box-shadow: 1px 1px 4px 0 rgba(0, 0, 0, 0.1);
  position: fixed;
  width: 100%;
}

.header ul {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
  background-color: #fff;
}

.header li a {
  display: block;
  padding: 20px 20px;
  border-right: 1px solid #f4f4f4;
  text-decoration: none;
}

.header li a:hover,
.header .menu-btn:hover {
  background-color: #f4f4f4;
}

.header .logo {
  display: block;
  float: left;
  font-size: 2em;
  padding: 10px 20px;
  text-decoration: none;
}

/* menu */

.header .menu {
  clear: both;
  max-height: 0;
  transition: max-height 0.2s ease-out;
}

/* menu icon */

.header .menu-icon {
  cursor: pointer;
  display: inline-block;
  float: right;
  padding: 28px 20px;
  position: relative;
  user-select: none;
}

.header .menu-icon .navicon {
  background: #333;
  display: block;
  height: 2px;
  position: relative;
  transition: background 0.2s ease-out;
  width: 18px;
}

.header .menu-icon .navicon:before,
.header .menu-icon .navicon:after {
  background: #333;
  content: "";
  display: block;
  height: 100%;
  position: absolute;
  transition: all 0.2s ease-out;
  width: 100%;
}

.header .menu-icon .navicon:before {
  top: 5px;
}

.header .menu-icon .navicon:after {
  top: -5px;
}

/* menu btn */

.header .menu-btn {
  display: none;
}

.header .menu-btn:checked ~ .menu {
  max-height: 240px;
}

.header .menu-btn:checked ~ .menu-icon .navicon {
  background: transparent;
}

.header .menu-btn:checked ~ .menu-icon .navicon:before {
  transform: rotate(-45deg);
}

.header .menu-btn:checked ~ .menu-icon .navicon:after {
  transform: rotate(45deg);
}

.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before,
.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
  top: 0;
}

/* 48em = 768px */

@media (min-width: 48em) {
  .header li {
    float: left;
  }
  .header li a {
    padding: 20px 30px;
  }
  .header .menu {
    clear: none;
    float: right;
    max-height: none;
  }
  .header .menu-icon {
    display: none;
  }
}

So if ya run this code, you get that the h1’s – bmw 4 series is going inside the program. How to fix that?

Can you use just react, node js and mongoose to create a chat app? Will there be a need for socket.io?

I am creating a simple chat app using react and node js. When using socket to establish a connection between server and client, I was wondering the point of using this package. Since react re-renders the page upon state change, I can fetch messages from my database and change the state, allowing for a presumably seamless chat application. Will there be any problems with such a chat application, where the chats would be displayed by fetching data from the database? Adding a new message would again update the database and the data would be fetched. So, the page would update with the new chat being displayed as it has been re-rendered due to change of state. So what is the need for socket in such an application ?