SVG sprite(symbol) is not generated by svg-loader after webpack upgrade

I have a project where i need to generate svg sprite(symbol) in case the build is in development mode using webpack. This was working fine till i had old version (3.x.x) version of webpack.

I have now upgraded the the webpack to version 5. and accordingly updated the dependencies and changed a bit of the structure. now it is not generating the sprite. i have tried a lot of things but nothing works.

here is my old code:

if(!isProd){
  rules.push({
    test: /.svg$/,
    include: path.join(__dirname, './library/basics/Icons'),
    loaders: [
      'svg-sprite-loader?' +
        JSON.stringify({
          name: 'icon-[name]',
          prefixize: true,
        }),
      'svgo-loader?' +
        JSON.stringify({
          plugins: [
            {removeTitle: true},
            {convertPathData: false},
            {removeUselessStrokeAndFill: true},
          ],
        }),
    ],
  })

and the dependencies for this were as mentioned below

    "svg-sprite-loader": "0.3.1",
    "svgo": "^1.1.1",
    "svgo-loader": "^2.2.0",

    "webpack": "3.12.0",
    "webpack-dev-server": "2.11.2"

Now I have updated the webpack code to this

if(!isProd){
    test: /.svg$/,
    include: path.join(__dirname, "./library/basics/Icons"),
    use: [
      {
        loader: "svg-sprite-loader",
        options: { name: "icon-[name]", prefixize: true },
      },
      {
        loader: "svgo-loader",
        options: {
          removeTitle: true,
          convertPathData: false,
          removeUselessStrokeAndFill: true,
        },
      },
    ],
  }

And updated dependencies

   "svg-sprite-loader": "^6.0.11",
   "svgo": "^1.3.2",
   "svgo-loader": "^4.0.0",

   "webpack": "^5.39.1",
   "webpack-cli": "^5.0.1",
   "webpack-dev-server": "^4.11.1",

Here is my Unchanged javscript code :

  var general = null;
  var  tickets = null;
  general = require.context('./General', true, /.*.svg$/)
  general.keys().forEach(general)

  tickets = require.context('./Tickets', true, /.*.svg$/)
  tickets.keys().forEach(tickets)

Insert special text through all regex matches

I have this regex

/<(w+)>(?!w)(?!(</(1)>))/gm

and for instance I have a text like this

RegExr was created by gskinner.com.

Edit the Expression & Text to see matches. Roll over matches or the expression for details. PCRE & JavaScript flavors of RegEx are supported. Validate your expression with Tests mode.

The side bar includes a Cheatsheet, full Reference, and Help. You can also Save & Share with the Community and view patterns you create or favorite in My Patterns.
amir
Explore results with the Tools below. Replace & List output custom results. Details lists capture groups. Explain describes your expression in plain English.
<p>sdf,m.,.msdf</p><p><p><p><p></p>
<b></b>
<p><b><g>
<img>
<br><p><hr>
<p>

all in all ,this regex match with stand alone tag like the last <p>
I want to insert / character before the last character in each matches.
what I want is a match case like <p> becomes </p>

How to make dynamic combobox in ExtJS or Javascript?

I have a combobox include true, false and all stuation on ExtJS. If I choose true on combobox send 1 to API and I choose false on combobox send 2,3 etc. to API. My code run static like below :

try {
    var comboStoreConfig = X.store.comboStoreConfig();
    comboStoreConfig.displayField = "name";
    comboStoreConfig.valueField = "id";
    comboStoreConfig.useDbData = false;
    comboStoreConfig.staticData = [];
    comboStoreConfig.initialValue = config.initialValue;

    comboStoreConfig.staticData.push({"id": 1, "ad":"True"});
    comboStoreConfig.staticData.push({"id": 2, "ad":"False"});
    comboStoreConfig.staticData.push({"id": 0, "ad":"All"});

    return X.store.createStoreToCombo(config, comboStoreConfig);
} catch (e) {
 //throw exception
}

How can I make dynamic combobox ? For example when I choose “false” on combobox the id must go to API like 2,3 etc.

Chartjs add dataset class stops drag plugin from working

Having some trouble figuring out what i’ve done wrong. I created a Dataset class so i could just call const set = new Dataset(..) and then push these into the chart datasets as i went along.

If i add my data via the class then the drag of the graph data stops working, when dragging it will put the start of the data way off to the start of the chart. Yet the data is correctly displayed.

Best i can tell is that what is being passed into the onDrag callback should be an array of values, but when its not working it’s just a single value.

I’ve created a fiddle showing what it should do https://jsfiddle.net/e4ohu2f5/3/
and this is what it does https://jsfiddle.net/e4ohu2f5/2/ the class data is the “tuesday” slot.

I think the class is correct? Its the first time i’ve really done anything with javascript classes.
Any pointers would be good.

class Dataset {
  constructor(xAxislabels, label) {
    this.label = label;
    this.xAxisLabels = xAxislabels;
    this.data = Array(xAxislabels.length).fill([]);
    this.fill = false;
    this.backgroundColor = [
      'rgba(153, 102, 255, 0.2)',
    ];
    this.borderColor = [
      'rgb(153, 102, 255)',
    ];
    this.borderSkipped = false;
    this.borderWidth = 1;
    this.pointHitRadius = 25;
    this.tension = 0.4;
    this.dragData = true;
    this.tooltip = {
      callbacks: {
        label: function(item) {
          if (!item.parsed._custom) {
            console.log("dynamic couldn't parse the item?");
            return;
          }
          const date = DATE.fromSeconds(item.parsed._custom.barStart / 1000).toLocaleString();
          const time_start = DATE.fromSeconds(item.parsed._custom.barStart / 1000).toLocaleString(
            DATE.TIME_24_SIMPLE
          );
          const time_stop = DATE.fromSeconds(item.parsed._custom.barEnd / 1000).toLocaleString(
            DATE.TIME_24_SIMPLE
          );
          return `${item.dataset.label} ${date} ${time_start} - ${time_stop}`
        }
      }
    };
  }

  // Setter
  setData(xAxisLabel, data) {
    const pos = this.xAxisLabels.indexOf(xAxisLabel);
    console.log("pos: ", pos);
    this.data[pos] = data;
  }
}

let myData = new Dataset(["Sun 19th Feb 2023", "Mon 20th Feb 2023", "Tue 21st Feb 2023", "Wed 22nd Feb 2023", "Thu 23rd Feb 2023", "Fri 24th Feb 2023", "Sat 25th Feb 2023"], 'task_descript');

myData.setData('Tue 21st Feb 2023', ["10:30", "11:30"]);

const options = {
  type: "bar",
  data: {
    labels: [
      "Sun 19th Feb 2023",
      "Mon 20th Feb 2023",
      "Tue 21st Feb 2023",
      "Wed 22nd Feb 2023",
      "Thu 23rd Feb 2023",
      "Fri 24th Feb 2023",
      "Sat 25th Feb 2023"
    ],
    datasets: [myData, 
    {
        label: "",
        data: [
          ["08:25", "08:39"],
          ["09:45", "09:55"],
          [],
          [],
          [],
          [],
          []
        ],
        backgroundColor: ['rgba(153, 50, 255, 0.2)'],
        borderColor: ['rgb(153, 102, 255)'],
        borderWidth: 1,
        pointHitRadius: 25,
        tension: 0.4,
        dragData: true,
        tooltip: {
          callbacks: {
            label: function(item) {
/*               if (!item.parsed._custom) {
                console.log("couldn't parse the item?");
                return;
              } */
              const date = DATE.fromSeconds(
                item.parsed._custom.barStart / 1000
              ).toLocaleString();
              const time_start = DATE.fromSeconds(
                item.parsed._custom.barStart / 1000
              ).toLocaleString(DATE.TIME_24_SIMPLE);
              const time_stop = DATE.fromSeconds(
                item.parsed._custom.barEnd / 1000
              ).toLocaleString(DATE.TIME_24_SIMPLE);
              return `${item.dataset.label} ${date} ${time_start} - ${time_stop}`;
            }
          }
        }
      },
      {
        label: "",
        data: [
          ["08:39", "08:59"],
          ["08:39", "09:00"]
        ],
        backgroundColor: "blue",
        borderWidth: 1,
        pointHitRadius: 25,
        tension: 0.4,
        dragData: true,
        tooltip: {
          callbacks: {
            label: function(item) {
              if (!item.parsed._custom) {
                console.log("Tis couldn't parse the item?");
                return;
              }
              const date = DATE.fromSeconds(
                item.parsed._custom.barStart / 1000
              ).toLocaleString();
              const time_start = DATE.fromSeconds(
                item.parsed._custom.barStart / 1000
              ).toLocaleString(DATE.TIME_24_SIMPLE);
              const time_stop = DATE.fromSeconds(
                item.parsed._custom.barEnd / 1000
              ).toLocaleString(DATE.TIME_24_SIMPLE);
              return `${item.dataset.label} ${date} ${time_start} - ${time_stop}`;
            }
          }
        }
      },
      {
        label: "",
        data: [
          ["10:39", "15:59"],
          ["11:00", "11:30"]
        ],
        borderSkipped: false,
        backgroundColor: ['rgba(30, 130, 76, 0.2)'],
        borderColor: ['red'],
        borderWidth: 1,
        pointHitRadius: 25,
        tension: 0.4,
        dragData: true,
        tooltip: {
          callbacks: {
            label: function(item) {
              if (!item.parsed._custom) {
                console.log("couldn't parse the item?");
                return;
              }
              const date = DATE.fromSeconds(
                item.parsed._custom.barStart / 1000
              ).toLocaleString();
              const time_start = DATE.fromSeconds(
                item.parsed._custom.barStart / 1000
              ).toLocaleString(DATE.TIME_24_SIMPLE);
              const time_stop = DATE.fromSeconds(
                item.parsed._custom.barEnd / 1000
              ).toLocaleString(DATE.TIME_24_SIMPLE);
              return `${item.dataset.label} ${date} ${time_start} - ${time_stop}`;
            }
          }
        }
      }
    ]
  },
  options: {
    indexAxis: "y",
    onHover: function(e) {
      const point = e.chart.getElementsAtEventForMode(e, 'nearest', {
        intersect: true
      }, false)
      if (point.length) e.native.target.style.cursor = 'grab'
      else e.native.target.style.cursor = 'default'
    },
    scales: {
      y: {
        stacked: true
      },
      x: {
        parsing: false,
        stacked: false,
        position: "top",
        type: "time",
        time: {
          unit: "hour"
        },
        min: "07:00",
        max: "19:00"
      }
    },
    plugins: {
      legend: {
        display: false
      },
      dragData: {
        round: 1,
        showTooltip: true,
        onDragStart: function(e, element) {
          // console.log(e);
          // console.log("element: ", element);
        },
        onDrag: function(e, datasetIndex, index, value) {
          e.target.style.cursor = "grabbing";
          // prohibit values < 0
          // if (value < 0) return false
          console.log(value);
          //console.log(e, datasetIndex, index, value);
        },
        onDragEnd: function(e, datasetIndex, index, value) {
          e.target.style.cursor = "default";
          // console.log(datasetIndex, index, value)
        }
      }
    }
  }
}

let ctx = document.getElementById("chartJSContainer").getContext("2d");
const myChart = new Chart(ctx, options);

console.log(myChart.config)```

Backend recondition [closed]

So I recently finished front end development, and am looking to start learning backend but I don’t really know what to or where to start?

Am kinda tired of asking my friends to do my backend.

Disable Past and Future Dates using React-FlatPicker

I’ve two date pickers From and To

Requirement:

From : Months <= 12PastMonthsFromNow should be DISABLE

To : Months > MonthsFromNow should be DISABLE

Only enable past 12 months from now.

Example:

 From         To 

 Apr-2022     Mar-2023 [Correct] 
 Mar-2022     Mar-2023 [In Correct]

CODES: https://codesandbox.io/s/flatpicker-with-current-time-forked-7j9yxs?file=/src/flatPicker.tsx

I have successfully achieved this using minDate and maxDate.

PROBLEM: FromDate not displayed on load with minDate configured.

If commented // minDate: moment(new Date()).subtract(11, "month").toISOString() fromDate data shows up.

 options={{
          enableTime: false,
          dateFormat: "M-Y",
          altFormat: "M-Y",
          maxDate: new Date().toISOString()
          // minDate: moment(new Date()).subtract(11, "month").toISOString()
          //FromDate shows data if minDate is commented
        }}

enter image description here
Please help.

Discord voice system js

My problem that if ‘Owner’ of voice channel leaves before someone else, then if in voice channel size of member = 0
nothing happens. I think that because my db, i’m quite bad in mongodb.

I have 3 files:
joinvoice.js:

const { SlashCommandBuilder, ChannelType, ButtonInteraction, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionFlagsBits, ModalBuilder, TextInputBuilder, TextInputStyle, CommandInteraction, Client, joinVoiceChannel } = require("discord.js");
const UserVoice = require("../../Models/UserVoice");
const VoiceSchema = require("../../Models/VoiceSchema");

const voiceCooldown = new Map();

module.exports = {
    name: "voiceStateUpdate",

    async execute(oldVoiceState, newVoiceState) {
        const VoiceData = await VoiceSchema.findOne({ GuildID: newVoiceState.guild.id });
        const UserData = await UserVoice.findOne({ UserID: newVoiceState.member.id });

        if (newVoiceState.channel && newVoiceState.channel.id === VoiceData?.ChannelID) {
            const now = Date.now();
            const cooldownTime = 60 * 1000;
            if (voiceCooldown.has(newVoiceState.member.id)) {
                const expirationTime = voiceCooldown.get(newVoiceState.member.id) + cooldownTime;
                if (now < expirationTime) {
                    const remainingTime = (expirationTime - now) / 1000;
                    return newVoiceState.member.send(`Please wait ${remainingTime.toFixed(1)} seconds before creating another voice channel.`);
                }
            }

            let voice_channel = await newVoiceState.guild.channels.create({
                name: UserData?.ChannelName || `${newVoiceState.member.displayName}-voice`,
                type: ChannelType.GuildVoice,
                parent: newVoiceState.channel.parent
            }).then(async (channel) => {
                await newVoiceState.member.voice.setChannel(channel);
                await UserVoice.findOneAndUpdate(
                    { UserID: newVoiceState.member.id },
                    {
                        ChannelID: newVoiceState.channel.id
                    },
                    {
                        new: true,
                        upsert: true,
                    }
                );

                voiceCooldown.set(newVoiceState.member.id, Date.now());
            });
        } else if (oldVoiceState?.channel?.id === UserData?.ChannelID || newVoiceState?.channel?.id !== UserData?.ChannelID) {
            const channel = oldVoiceState.guild.channels.cache.get(UserData?.ChannelID);
            if (channel && channel.members.size === 0) {
              await channel.delete();
              await UserVoice.findOneAndDelete({ UserID: newVoiceState.member.id });
            }
        }
    },
};

and 2 mongo:
UserVoice.js this one storing custom name of voice channel and id of the channel:

const { model, Schema } = require("mongoose");

let UserVoice = new Schema({
    UserID: String,
    ChannelID: String,
    ChannelName: String,
});

module.exports = model("UserVoice", UserVoice);

VoiceSchema.js this one is for channel Join to create:

const { model, Schema } = require("mongoose");

let VoiceSchema = new Schema({
    GuildID: String,
    ChannelID: String,
});

module.exports = model("VoiceSchema", VoiceSchema);

Ty for help! ^_^

I want to display attributes of a geojson file as labels using MapLibre GL JS [closed]

I want to display labels on a map by combining the “JINKO_string” attribute and the “S_NAME” attribute of the following geojson file using MapLibre GL JS. However, in the following source code, the labels are not displayed.

MapLibre GL JS

            map.addLayer({
                'id': 'jinko_label',
                'type': 'symbol',
                'source': 'geojson-jinko-point',
                'minzoom': 12,
                'maxzoom': 15,
                'layout': {
                    'text-field': ["format",
                        ["to-string", ['get', 'JINKO_string']], {},
                        "人n", {},
                        ['get', 'S_NAME'], {}
                    ],
                    'text-anchor': 'top',
                    'text-allow-overlap': true,
                    'text-size': 12,
                    'text-offset': [0, -1]
                }
            });

geojson

{
"type": "FeatureCollection",
"name": "r2ka01-47_point_JGD2011_number_",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "S_NAME": "宮ケ丘(番地)", "JINKO_string": "5" }, "geometry": { "type": "Point", "coordinates": [ 141.308858, 43.0521 ] } },
{ "type": "Feature", "properties": { "S_NAME": "円山", "JINKO_string": "0" }, "geometry": { "type": "Point", "coordinates": [ 141.31413, 43.048525 ] } },
{ "type": "Feature", "properties": { "S_NAME": "円山西町(番地)", "JINKO_string": "0" }, "geometry": { "type": "Point", "coordinates": [ 141.303387, 43.034392 ] } },
{ "type": "Feature", "properties": { "S_NAME": "円山西町(番地)", "JINKO_string": "0" }, "geometry": { "type": "Point", "coordinates": [ 141.300766, 43.046475 ] } },
{ "type": "Feature", "properties": { "S_NAME": "宮の森", "JINKO_string": "0" }, "geometry": { "type": "Point", "coordinates": [ 141.298753, 43.047026 ] } },
{ "type": "Feature", "properties": { "S_NAME": "宮の森", "JINKO_string": "0" }, "geometry": { "type": "Point", "coordinates": [ 141.305065, 43.053913 ] } },
{ "type": "Feature", "properties": { "S_NAME": "字新城", "JINKO_string": "10" }, "geometry": { "type": "Point", "coordinates": [ 123.945188, 24.234269 ] } },
{ "type": "Feature", "properties": { "S_NAME": "字波照間", "JINKO_string": "470" }, "geometry": { "type": "Point", "coordinates": [ 123.782372, 24.058521 ] } },
{ "type": "Feature", "properties": { "S_NAME": "字与那国", "JINKO_string": "1,676" }, "geometry": { "type": "Point", "coordinates": [ 122.988939, 24.455406 ] } }
]
}

In the following source code, labels for the “S_NAME” attribute are displayed. I also want to display labels for the “JINKO_string” attribute.

MapLibre GL JS

            map.addLayer({
                'id': 'jinko_label',
                'type': 'symbol',
                'source': 'geojson-jinko-point',
                'minzoom': 12,
                'maxzoom': 15,
                'layout': {
                    'text-field': ['get', 'S_NAME'],
                    'text-anchor': 'top',
                    'text-allow-overlap': true,
                    'text-size': 12,
                    'text-offset': [0, -1]
                }
            });

Why can’t I redirect to delete route in expressjs and js? [closed]

I am trying to make an admin panel for my restaurant website. The system generates a user snippet(admin_panel_user_display_snippet) for every user on the database and replaces the values with their places. I also added a form to delete the user from the database.

The form’s action gets replaced with the /delete-user-John"(let's say the user's name is John). When you get routed to the form’s action; the system deletes the user. But there is a mistake.

I cannot get redirected to /delete-user-John. I get an error called

Cannot POST to /delete-user-john

What am I doing wrong?

var user_card_name_result;
var data_food_snippet_display_replaced = data.replace("#admin-panel-display-user-div-2{display: none;}", "#admin-panel-display-user-div-2{display: flex;}");
var admin_panel_user_display_snippet_12 = "";
var admin_panel_user_display_snippet = "<div id='admin-panel-display-user-div-2'><div id='admin-panel-display-user-name-div'><div id='admin-panel-display-user-name-header-div'><h1 id='admin-panel-display-user-name-header'>Name And Surname</h1></div><div id='admin-panel-display-user-name-info-div'><p id='admin-panel-display-user-name-info'>adminpanelusername</p></div></div><div id='admin-panel-display-user-email-div'><div id='admin-panel-display-user-email-header-div'><h1 id='admin-panel-display-user-email-header'>Email</h1></div><div id='admin-panel-display-user-email-info-div'><p id='admin-panel-display-user-email-info'>[email protected]</p></div></div><div id='admin-panel-display-user-password-div'><div id='admin-panel-display-user-password-header-div'><h1 id='admin-panel-display-user-password-header'>Password</h1></div><div id='admin-panel-display-user-password-info-div'><p id='admin-panel-display-user-password-info'>adminpanelpassword</p></div></div><div id='admin-panel-display-user-phone-div'><div id='admin-panel-display-user-phone-header-div'><h1 id='admin-panel-display-user-phone-header'>Phone Number</h1></div><div id='admin-panel-display-user-phone-header-div'><p id='admin-panel-display-user-phone-info'>adminpanelphone</p></div></div><div id='admin-panel-display-user-credit-card-div'><div id='admin-panel-display-user-credit-card-header-div'><h1 id='admin-panel-display-user-credit-card-header'>Credit Card</h1></div><div id='admin-panel-display-user-phone-header-div'><p id='admin-panel-display-user-phone-info'>adminpanelcreditcard</p></div></div><div id='admin-panel-display-user-cvc-div'><div id='admin-panel-display-user-cvc-header-div'><h1 id='admin-panel-display-user-cvc-header'>CVC</h1></div><div id='admin-panel-display-user-cvc-info-div'><p id='admin-panel-display-user-cvc-info'>adminpanelcvc</p></div></div><div id='admin-panel-display-user-address-div'><div id='admin-panel-display-user-address-header-div'><h1 id='admin-panel-display-user-address-header'>Address</h1></div><div id='admin-panel-display-user-address-info-div'><p id='admin-panel-display-user-address-info'>adminpaneladdress</p></div></div><div id='admin-panel-display-user-exp-div'><div id='admin-panel-display-user-exp-header-div'><h1 id='admin-panel-display-user-address-header'>Exp.</h1></div><div id='admin-panel-display-user-exp-info-div'><p id='admin-panel-display-user-address-info'>adminpanelexp</p></div></div><div id='admin-panel-display-user-card-name-div'><div id='admin-panel-display-user-card-name-header-div'><h1 id='admin-panel-display-user-card-name-header'>Card Name</h1></div><div id='admin-panel-display-user-card-name-info-div'><p id='admin-panel-display-user-card-name-info'>adminpanelcardname</p></div></div><div id='admin-panel-display-user-delete-user-div'><form action='/delete-user-usernametodeletecomeshere' method='post'><div id='admin-panel-display-user-delete-user-button-div'><button type='submit' id='admin-panel-display-user-delete-user-button'>X</button></div></form></div></div><div style='height: 1vw;'' id='s-div'></div>";

for (var i = 0; i < user_count; i++) {
  console.log(user_name_result[i]);
  var name = JSON.stringify(user_name_result[i]).slice(14, -2);
  var email = JSON.stringify(user_email_result[i]).slice(15, -2);
  var password = JSON.stringify(user_password_result[i]).slice(13, -2);
  var phone = JSON.stringify(user_phone_result[i]).slice(15, -2);
  var credit_card = JSON.stringify(user_credit_card_result[i]).slice(16, -2);
  var cvc = JSON.stringify(user_cvc_result[i]).slice(8, -2);
  var address = JSON.stringify(user_address_result[i]).slice(18, -2);
  var exp = JSON.stringify(user_exp_result[i]).slice(13, -2);
  var card_name = JSON.stringify(user_card_name_result[i]).slice(14, -2);
  var admin_panel_user_display_snippet_2 = admin_panel_user_display_snippet.replace("adminpanelusername", name);
  var admin_panel_user_display_snippet_3 = admin_panel_user_display_snippet_2.replace("[email protected]", email);
  var admin_panel_user_display_snippet_4 = admin_panel_user_display_snippet_3.replace("adminpanelpassword", password);
  var admin_panel_user_display_snippet_5 = admin_panel_user_display_snippet_4.replace("adminpanelphone", phone);
  var admin_panel_user_display_snippet_6 = admin_panel_user_display_snippet_5.replace("adminpanelcreditcard", credit_card);
  var admin_panel_user_display_snippet_7 = admin_panel_user_display_snippet_6.replace("adminpanelcvc", cvc);
  var admin_panel_user_display_snippet_8 = admin_panel_user_display_snippet_7.replace("adminpaneladdress", address);
  var admin_panel_user_display_snippet_9 = admin_panel_user_display_snippet_8.replace("adminpanelexp", exp);
  var admin_panel_user_display_snippet_10 = admin_panel_user_display_snippet_9.replace("adminpanelcardname", card_name);
  var admin_panel_user_display_snippet_11 = admin_panel_user_display_snippet_10.replace("usernametodeletecomeshere", name);

  admin_panel_user_display_snippet_12 = admin_panel_user_display_snippet_12 + admin_panel_user_display_snippet_11;

  app.post("/delete-user-" + name, function(req, res) {
    console.log("delete_user_route", name);
  });
}

var data_user_display_admin = data_food_snippet_display_replaced.replace(admin_panel_user_display_snippet, admin_panel_user_display_snippet_12);
res.write(data_user_display_admin);
res.end();
}
#admin-panel-display-user-div-2 {
  width: 100%;
  border: 2px solid #C94277;
  display: flex;
  justify-content: center;
  align-items: center;
}

#admin-panel-display-user-name-div {
  width: 10%;
}

#admin-panel-display-user-name-header-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-name-header {
  font-family: sans-serif;
  color: #C94277;
  font-size: 0.7vw;
  text-decoration: underline;
}

#admin-panel-display-user-name-info-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-name-info {
  font-family: sans-serif;
  color: gray;
  font-size: 0.6vw;
}

#admin-panel-display-user-email-div {
  width: 10%;
}

#admin-panel-display-user-email-header-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-email-header {
  font-family: sans-serif;
  color: #C94277;
  font-size: 0.7vw;
  text-decoration: underline;
}

#admin-panel-display-user-email-info-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-email-info {
  font-family: sans-serif;
  color: gray;
  font-size: 0.6vw;
}

#admin-panel-display-user-password-div {
  width: 10%;
}

#admin-panel-display-user-password-header-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-password-header {
  font-family: sans-serif;
  color: #C94277;
  font-size: 0.7vw;
  text-decoration: underline;
}

#admin-panel-display-user-password-info-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-password-info {
  font-family: sans-serif;
  color: gray;
  font-size: 0.6vw;
}

#admin-panel-display-user-phone-div {
  width: 10%;
}

#admin-panel-display-user-phone-header-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-phone-header {
  font-family: sans-serif;
  color: #C94277;
  font-size: 0.7vw;
  text-decoration: underline;
}

#admin-panel-display-user-phone-header {
  font-family: sans-serif;
  color: #C94277;
  font-size: 0.7vw;
  text-decoration: underline;
}

#admin-panel-display-user-phone-info {
  font-family: sans-serif;
  color: gray;
  font-size: 0.6vw;
}

#admin-panel-display-user-credit-card-div {
  width: 10%;
}

#admin-panel-display-user-credit-card-header-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-credit-card-header {
  font-family: sans-serif;
  color: #C94277;
  font-size: 0.7vw;
  text-decoration: underline;
}

#admin-panel-display-user-cvc-div {
  width: 10%;
}

#admin-panel-display-user-cvc-header-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-cvc-header {
  font-family: sans-serif;
  color: #C94277;
  font-size: 0.7vw;
  text-decoration: underline;
}

#admin-panel-display-user-cvc-info-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-cvc-info {
  font-family: sans-serif;
  color: gray;
  font-size: 0.6vw;
}

#admin-panel-display-user-address-div {
  width: 10%;
}

#admin-panel-display-user-address-header-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-address-header {
  font-family: sans-serif;
  color: #C94277;
  font-size: 0.7vw;
  text-decoration: underline;
}

#admin-panel-display-user-address-info-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-address-info {
  font-family: sans-serif;
  color: gray;
  font-size: 0.6vw;
}

#admin-panel-display-user-exp-div {
  width: 10%;
}

#admin-panel-display-user-exp-header-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-exp-info-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-address-info {
  font-family: sans-serif;
  color: gray;
  font-size: 0.6vw;
}

#admin-panel-display-user-card-name-div {
  width: 10%;
}

#admin-panel-display-user-card-name-header {
  font-family: sans-serif;
  color: #C94277;
  font-size: 0.7vw;
  text-decoration: underline;
  padding-left: 21%;
}

#admin-panel-display-user-card-name-info-div {
  width: 100%;
  text-align: center;
}

#admin-panel-display-user-card-name-info {
  font-family: sans-serif;
  color: gray;
  font-size: 0.6vw;
}

#admin-panel-display-user-delete-user-div {
  width: 10%;
}

#admin-panel-display-user-delete-user-button-div {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#admin-panel-display-user-delete-user-button {
  width: 1vw;
  height: 1vw;
  background-color: rgb(196, 35, 35);
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 2px solid rgb(196, 35, 35);
}
<div id='admin-panel-display-user-div-2'>
  <div id='admin-panel-display-user-name-div'>
    <div id='admin-panel-display-user-name-header-div'>
      <h1 id='admin-panel-display-user-name-header'>Name And Surname</h1>
    </div>
    <div id='admin-panel-display-user-name-info-div'>
      <p id='admin-panel-display-user-name-info'>adminpanelusername</p>
    </div>
  </div>
  <div id='admin-panel-display-user-email-div'>
    <div id='admin-panel-display-user-email-header-div'>
      <h1 id='admin-panel-display-user-email-header'>Email</h1>
    </div>
    <div id='admin-panel-display-user-email-info-div'>
      <p id='admin-panel-display-user-email-info'>[email protected]</p>
    </div>
  </div>
  <div id='admin-panel-display-user-password-div'>
    <div id='admin-panel-display-user-password-header-div'>
      <h1 id='admin-panel-display-user-password-header'>Password</h1>
    </div>
    <div id='admin-panel-display-user-password-info-div'>
      <p id='admin-panel-display-user-password-info'>adminpanelpassword</p>
    </div>
  </div>
  <div id='admin-panel-display-user-phone-div'>
    <div id='admin-panel-display-user-phone-header-div'>
      <h1 id='admin-panel-display-user-phone-header'>Phone Number</h1>
    </div>
    <div id='admin-panel-display-user-phone-header-div'>
      <p id='admin-panel-display-user-phone-info'>adminpanelphone</p>
    </div>
  </div>
  <div id='admin-panel-display-user-credit-card-div'>
    <div id='admin-panel-display-user-credit-card-header-div'>
      <h1 id='admin-panel-display-user-credit-card-header'>Credit Card</h1>
    </div>
    <div id='admin-panel-display-user-phone-header-div'>
      <p id='admin-panel-display-user-phone-info'>adminpanelcreditcard</p>
    </div>
  </div>
  <div id='admin-panel-display-user-cvc-div'>
    <div id='admin-panel-display-user-cvc-header-div'>
      <h1 id='admin-panel-display-user-cvc-header'>CVC</h1>
    </div>
    <div id='admin-panel-display-user-cvc-info-div'>
      <p id='admin-panel-display-user-cvc-info'>adminpanelcvc</p>
    </div>
  </div>
  <div id="admin-panel-display-user-address-div">
    <div id='admin-panel-display-user-address-header-div'>
      <h1 id='admin-panel-display-user-address-header'>Address</h1>
    </div>
    <div id='admin-panel-display-user-address-info-div'>
      <p id="admin-panel-display-user-address-info">adminpaneladdress</p>
    </div>
  </div>
  <div id='admin-panel-display-user-exp-div'>
    <div id='admin-panel-display-user-exp-header-div'>
      <h1 id='admin-panel-display-user-address-header'>Exp.</h1>
    </div>
    <div id='admin-panel-display-user-exp-info-div'>
      <p id='admin-panel-display-user-address-info'>adminpanelexp</p>
    </div>
  </div>
  <div id='admin-panel-display-user-card-name-div'>
    <div id='admin-panel-display-user-card-name-header-div'>
      <h1 id='admin-panel-display-user-card-name-header'>Card Name</h1>
    </div>
    <div id='admin-panel-display-user-card-name-info-div'>
      <p id="admin-panel-display-user-card-name-info">adminpanelcardname</p>
    </div>
  </div>
  <div id='admin-panel-display-user-delete-user-div'>
    <form action='/delete-user-usernametodeletecomeshere' method='post'>
      <div id='admin-panel-display-user-delete-user-button-div'><button type='submit' id='admin-panel-display-user-delete-user-button'>X</button></div>
    </form>
  </div>
</div>

How can i align my table that a within a table dropdown data to cross pond with table title

I have table within a table were my other table is data that hold by dropdown , when the page load my data must be hidden only appear when you click on it. How can I align data that is hold by drop down to cross pond with title header of a table. The design of table should look like my output the one I provide. This what I have try:

  const dropdownHeaders = document.querySelectorAll('.dropdown');
    dropdownHeaders.forEach(header => {
        header.addEventListener('click', () => {
            const dropdownContent = header.querySelector('.dropdown-content');
            dropdownContent.classList.toggle('show');
        });
    });

    window.addEventListener('click', (event) => {
        dropdownHeaders.forEach(header => {
            const dropdownContent = header.querySelector('.dropdown-content');
            if (event.target !== header && event.target.parentNode !== header && event.target !== dropdownContent && !dropdownContent.contains(event.target)) {
                dropdownContent.classList.remove('show');
            }
        });
    });
    #mytable {
        float: right;
        background-color: white;
        border-collapse: collapse;
        margin-right: 45px;
        margin-left: -40px;
    }

    .fixTableHead {
        overflow-y: auto;
        height: 420px;
        margin-top: 6%;
    }

    .fixTableHead thead th {
        position: sticky;
        top: 0;
    }

    td {
        text-align: left;
        color: #898C9A;
        height: 85px;
        border: none;
        cursor: pointer;
    }

    th {
        background-color: rgb(255, 255, 255);
        border: none;
        height: 72px;
        text-align: left;
        font-weight: normal;
        color: #898C9A;
        cursor: pointer;
    }

    .tb {
        box-shadow: 0px 3px 10px 0px rgb(236, 240, 241);
    }

    .tb:hover {
        background-color: #7C99AA;
        color: white;
    }

    .tb:hover td {
        color: white;
    }

    input[type=text] {
        float: center;
        padding: 4px 20px;
        margin-top: 8px;
        margin-right: 16px;
        font-size: 2px;
    }

    .input-icons i {
        position: absolute;
        color: #898C9A;
        margin: 113px 180px 180px 95px;
        z-index: 3;
        cursor: pointer;

    }

    .input-icons {
        width: 40;
        margin-bottom: -30px;
    }

    .icon {
        padding: 5px;
        color: #898C9A;
        min-width: 100px;
        text-align: left;
        margin-left: 10px;

    }

    #input-field {
        width: 15%;
        padding: 8px 12px;
        text-align: left;
        font-style: italic;
        color: #898C9A;
        background-color: #F8F8FB;
        transform: translate(25%, 25%);
        margin-top: 100px;
        padding-left: 55px;
        border: 0;
        cursor: pointer;
        outline: none;

    }

    .input.field:hover {
        color: white;
    }

    .select {
        width: 50px;
        height: 20px;
        cursor: pointer;
        margin-left: 0.5vw;
        accent-color: #7C99AA;
    }

    .dropdown-action {
        width: 97.6%;
        background-color: #D8D9DD;
        color: #898C9A;
        padding: 0.4em 0.3em;
        border-radius: 0.25em 0.25em 0em 0em;
        cursor: pointer;
        display: flex;
        align-items: left;

    }

    .dropdown {
        position: relative;
        display: inline-block;
        width: 2269.2%;
        height: 25px;
        background-color: #D8D9DD;
        color: #898C9A;
        margin-top: 50px;
        text-align: left;
    }

    .dropdown-content {
        display: none;
        position: absolute;
        width: 56.7%;
        top: 100%;
    }

    .dropdown:hover .dropdown-content {
        display: block;
    }
    table {
  width: 100%;
}
<body>
    <div class="fixTableHead">
        <table id="mytable" style="width:94%" class="table table-striped mt32 customers-list">
            <thead>
                <tr class="tb">
                    <th style="width: 4vw;"></th>
                    <th style="width:2.5vw;">#</th>
                    <th>student name</th>
                    <th>surname</th>
                    <th>course</th>
                    <th>start date</th>
                    <th>end date</th>
                    <th>pass mark</th>
                    <th>remark</th>
                </tr>
            </thead>
            <tr class="tbTable">
                <th class="dropdown" colspan="9">
                    <span><i class="mdi mdi-menu-down">Student</i></span>
                    <div class="dropdown-content">
                        <table  style="width:94%" class="table table-striped mt32 customers-list">
                            <tr id="record-1" class="tb rowSelect">
                                <td><input class="select" id="select_0" type="checkbox" record="record-1" name="chk"></td>
                                <td>1</td>
                                <td>Lucky</td>
                                <td>Daniel</td>
                                <td>Software Development</td>
                                <td>26 Jan 2022</td>
                                <td>06 Jun 2023</td>
                                <td></td>
                                <td>NO</td>
                            </tr>
                            <tr id="record-3" class="tb rowSelect">
                                <td><input class="select" id="select_1" type="checkbox" record="record-3" name="chk"></td>
                                <td>2</td>
                                <td>Deon</td>
                                <td>James</td>
                                <td>Networking</td>
                                <td>26 Jan 2022</td>
                                <td>20 Nov 2023</td>
                                <td></td>
                                <td>Yes</td>
                            </tr>
                        </table>
                    </div>
                </th>
            </tr>
        </table>
    </div>
</body>

Redux Toolkit: Fetch data from the backend after user logging in

I’m trying to display private user data after they log in. However, upon logging in, I receive an error in the console:

GET http://localhost:8000/api/v1/chat 401 (Unauthorized)

The data is only displayed after I manually refresh the browser.

Here’s my code for the Sidebar component:

const Sidebar = () => {
  const { data, isLoading } = useGetChatQuery();
  console.log(useGetChatQuery()); // -> `status: 'pending'`, and then `status: 'rejected'` -> but after manually refreshing, `status: 'fulfilled'`

  console.log(data); // -> "Bad Token" (as I set it in the backend for wrong tokens) -> after manually refreshing: "Some data"
 
  if (!data || isLoading) return <div>is loading</div>; // so it keeps showing this until I refresh, then it shows "Something" below.

  return <div id="sidebar-mid">Something</div>;
};

And here’s my apiChat RTK query file:


import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import Userfront from "@userfront/react";

export const apiChat = createApi({
  reducerPath: "apiChat",
  baseQuery: fetchBaseQuery({
    baseUrl: process.env.REACT_APP_BASE_URL,
  }),
  tagTypes: ["getChat"],
  endpoints: (build) => ({
    getChat: build.query({
      query(args) {
        return {
          url: `/api/v1/chat`,
          headers: {
            Authorization: `Bearer ${Userfront.accessToken()}`,
          },
        };
      },
      providesTags: ["getChat"],
    }),
  }),
});

export const { useGetChatQuery } = apiChat;

Any advice on how to resolve this issue would be greatly appreciated. Thank you!

Why do my readAsDataURL return the same exact string for 2 different pages of a pdf

export async function convertFromPdf(f: any) {
  const pdfjsLib = require("pdfjs-dist/webpack");

  const pdf = await pdfjsLib.getDocument(f).promise;
  const pdfPages = await toImageData(pdf);

  const pages = await Promise.all(
    pdfPages.map(async (x) => {
      if (!x) return null;

      const canvas = document.createElement("canvas");
      canvas.width = x.width;
      canvas.height = x.height;
      const ctx = canvas.getContext("2d");
      ctx?.putImageData(x, 0, 0);

      const blob = await new Promise<Blob | null>((resolve) => {
        canvas.toBlob((blob) => resolve(blob));
      });

      if (!blob) return null;

      const reader = new FileReader();
      reader.readAsDataURL(blob);

      return await new Promise<string>((resolve) => {
        reader.onloadend = () => resolve(reader.result as string);
      });
    })
  );

  return pages.filter((x) => x !== null) as string[];
}

async function toImageData(pdf: any) {
  const pdfPages = [];
  for (let i = 1; i <= pdf.numPages; i++) {
    const page = await pdf.getPage(i);
    const viewport = page.getViewport({ scale: 1.5 });
    const canvas = document.createElement("canvas");
    canvas.width = viewport.width;
    canvas.height = viewport.height;
    const ctx = canvas.getContext("2d");
    const renderContext = { canvasContext: ctx, viewport: viewport };

    await page.render(renderContext).promise;
    pdfPages.push(ctx?.getImageData(0, 0, canvas.width, canvas.height));
  }
  return pdfPages;
}

So I’m using the function above to convert pdf to image files (png). But somehow in certain cases, reader.readAsDataURL(blob) returns the same exact string for 2 different pages of the pdf. This is definitely bad because I want to make use of the url differently later on the UI part of things, but this will confuse the UI when doing certain selection as both will get selected as they both have the same url. Why does this happen?

Golang HTTP gin-gonic server creating TOTP. No idea how the client can create a QR tag. JavaScript?

I am developing a Open-Source server (https://authserv.io). The server can do all kind of authentication stuff (with focus to e-mail). Now I am writing a HTTP endpoint, where a user can create a TOTP secret. So far this looks like this:

package main

import (
    "bytes"
    "image"
    "image/png"
    "net/http"

    "github.com/gin-contrib/sessions"
    "github.com/gin-gonic/gin"
    "github.com/go-kit/log/level"
    "github.com/pquerna/otp/totp"
    "github.com/segmentio/ksuid"
    "github.com/spf13/viper"
    "golang.org/x/text/cases"
    "golang.org/x/text/language"
    "golang.org/x/text/language/display"
    "golang.org/x/text/message"
)

const (
    cookieAccount = "account"
    cookieTOTP    = "totp"
)

func totpGETHandler(ctx *gin.Context) {
    var (
        buf  bytes.Buffer
        img  image.Image
        guid = ksuid.New().String()
    )

    session := sessions.Default(ctx)

    cookieValue := session.Get(cookieTOTP)
    if cookieValue != nil {
        if cookieValue.(bool) {
            session.Delete(cookieAuthStatus)
            session.Delete(cookieAccount)
            session.Delete(cookieTOTP)

            session.Save()

            ctx.String(http.StatusOK, "You have already registered TOTP")

            return
        }
    }

    cookieValue = session.Get(cookieAuthStatus)
    if cookieValue == nil || AuthResult(cookieValue.(uint8)) != authResultOK {
        HandleErr(guid, errNotLoggedIn, ctx)

        return
    }

    session.Delete(cookieAuthStatus)

    cookieValue = session.Get(cookieAccount)
    if cookieValue == nil {
        HandleErr(guid, errNoAccount, ctx)

        return
    }

    account := cookieValue.(string)

    session.Delete(cookieAccount)

    key, err := totp.Generate(totp.GenerateOpts{
        Issuer:      viper.GetString("totp_issuer"),
        AccountName: account,
    })

    if err != nil {
        HandleErr(guid, err, ctx)

        return
    }

    // Convert TOTP key into a PNG
    img, err = key.Image(200, 200)
    if err != nil {
        HandleErr(guid, err, ctx)

        return
    }

    png.Encode(&buf, img)

    ctx.String(http.StatusOK, "Generated key: %s", key.String())
}

Now I am stuck how to continue.

Variant 1:

I could store the image as a temporary file and render a HTML template. After that removing the file. But this seems ugly, as the image is already in memory and it only needs to be transferred to the client somehow.

Variant 2:

Sending the string to the client and use JavaScript to create a QR code from it. This would be part of a HTML template either, which would be perfect.

Unfortunately I have not that much experience with Web-technologies at the client side, as I used to be a 100% backend developer.

So I only can ask for some ideas/help to point me to the right direction.