Sorting through an array of dates in milliseconds, extracting objects with subcategories, and dynamically displaying them on the calendar based on the specific date

So I am currently working with a JSON object containing an array of objects structured like this:

[
    {
        "id": 0,
        "name": "Sophia Mason",
      "availability": [
        {
         "date": 1522216800000,
         "times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
        },
        {
         "date": 1522303200000,
         "times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
        },
        ...
      ],
     },
     .........
    ]

Alongside this, I have another array created using moment.js, which holds a list of days like so:

[1522216800000, 1522303200000, 1522389600000]

My objective is to filter the availability of photographers based on each day in the date array and then accurately display each photographer's schedule on a calendar.

To achieve this, I am utilizing AngularJS at the client's request, aiming for a layout similar to the example shown below:

https://i.sstatic.net/O5VSO.png

While I have successfully rendered the days using Moment, I'm facing challenges in presenting each photographer's availability per day as illustrated in the provided calendar sample.

I've spent considerable time attempting various approaches, including references from similar queries on Stack Overflow such as:

Stack

Stack

Stack

After reviewing these resources, my current train of thought resides within the controller.js file as follows:

function setPhotographers() {

    let photographer = photographers.filter((el) => {
        el.availability.some((availability) => availability.date === today)
        .map((el)=> {
            console.log(el);
            let newEl = Object.assign({}, el);
            return newEl.availability.filter(availability => availability.date === today);
        });
    });

    return photographer;

}

Despite actively learning, I find myself stuck in this process. Any insights or guidance shared would be highly appreciated! It would be immensely beneficial if you could also explain the rationale behind your solution to aid in my comprehension of the task at hand.

Thank you!

Answer №1

Using the .filter() method is definitely a step in the right direction, but it seems like the .map() function may not be necessary in this case. You can achieve the desired result of obtaining a filtered array of photographers whose availability matches the current today date with the following code:

let availablePhotographers = photographers.filter((photographer) => photographer.availability.some((timeSlot) => timeSlot.date === today))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Set up webpack on your Mac using npm

Seeking help to install webpack using npm: sudo npm install -g webpack The following error message is encountered: node-pre-gyp WARN Using needle for node-pre-gyp https download node-pre-gyp WARN Pre-built binaries not installable for <a href="/cdn- ...

Displaying dates in Material UI datepicker is not working

My current setup involves using Material UI v14.4 with React, and I have encountered an issue with the DatePicker component not displaying the dates correctly as shown in the attached screenshot. Strangely, there are no visible error messages either. Any s ...

Guide to adding directional arrow indicators on the Y and X axes of a ChartJS graph

https://i.sstatic.net/ZKkXT.png Is it possible to add directional arrows on the Y and X axis of a ChartJS graph? I'm seeking advice or tips on how to achieve this. Below is the code snippet for creating the chart. var ctx = $("#mycanvas"); ...

Monitor the elements displayed as you scroll

Thank you for taking the time to read this. I am currently working on a webpage that features a top Calendar component displaying a week, and below that is a Scroll component showing detailed information for each day of the week. Here is what my page loo ...

Combining two objects in AngularJS to create a new merged object

Is there a way to merge object1 and object2 into object3, updating values corresponding to matching keys while ignoring unmatching keys? var object1 = { "pii" : "val1", "loc" : "val2" } var object2 = { "rrb" : "val3", "voc" : "val4" } var obje ...

The scope attribute is not functioning as expected in the loopback model

After utilizing an "include" : "organization" query within the context of my request.json file, a related model, I noticed that the resulting output from the query does not include the intended relation. The structure of the model (request.json file) is ...

Using a function as a parameter in Typescript: Anticipated no arguments, received 1.ts

I'm encountering an issue when trying to pass the doSomething function into performAction. The error message I'm receiving is Expected 0 arguments, but got 1 interface SomeInterface { name: string, id: string } function doSomethingFunction( ...

What is the best approach to breaking down attributes upon import according to the theme?

Hey there! Here's the thing - I have this file called <code>colors.ts:</p> export const black = '#0C0C0C'; export const blue = '#22618E'; Whenever I need to use a color, I import it like so: import {black} from 'S ...

Using HTML as an argument in a JavaScript function

Within a variable, I have stored an entire HTML page. $body = $myhtmlpage; <a onclick="openWin('<?php echo htmlspecialchars(json_encode($body)) ?>');" href="javascript:void(0);"> Click </a> I also have this JavaScript functio ...

Tips for making a background image responsive using ng-style in AngularJS

Can anyone assist me in fixing the gap space issue in a responsive view with an attached jpg background image? Follow this link for more details: enter image description here ...

Protractor encountered an issue when attempting to synchronize with the page, displaying the error: "angularJS testability and angular testability are both undefined."

Currently, I am in the process of developing end-to-end tests and I wanted to incorporate async and await functions into my code. Here is a snippet from the configuration file: exports.config = { framework: 'jasmine', seleniumAddress: & ...

Adding CSS styling to a particular component within your Vue application using Vuetify JS

Imagine having a Test.vue file containing 2 v-text-field components. I'm looking to style only the first text field using CSS. Test.vue <template> <div class="test"> <v-text-field></v-text-field> <v-tex ...

effective methods for setting up live reload feature for an Angular application

I've been attempting to implement grunt livereload for a basic Angular application. Below is the section from my gruntfile: watch: { livereload: { files: [ '*.{html,js}', & ...

Protractor struggles with locating elements within separate div elements on a single webpage

I'm currently developing a test script using Protractor for the specified web page. https://i.stack.imgur.com/CrMzG.jpg My goal was to target each field using their unique locator. Below is the test script I have created. describe('Protractor ...

What are the advantages of using history.push or another method from react-router-dom compared to simply assigning the path to window.location.pathname?

When I need to navigate within my code, I find it more convenient to simply assign the desired path to window.location.pathname. Can this approach have any drawbacks? ...

What is the process of adding a unique model to three.js?

Despite trying numerous solutions to a common problem, I am still unable to import my 3D model in Three.js using the following code: <script src="https://threejs.org/build/three.min.js"></script> <script src="https://cdn.rawgi ...

When utilizing the React API Fetch, there may be instances where not all data is returned. However

Having some trouble with my FetchData class. I am receiving a list of data, but it's in an array format. When I try to access specific values like countries: data.Countries[0], I can get individual values based on the index. However, what I really wan ...

The ideal login page design

I apologize for my lack of knowledge in React, but I am quite new to it and have been struggling with this issue for days. I am having trouble creating a login page in ReactJS. Here is the code in my app.js: import React from 'react'; import {Ha ...

When using AngularJs and input[type=date], the date format returned is not the standard yyyy-mm-dd. Instead, it is displayed in the format 2015-06-02T18:30:00

Can someone help me with the code I've used for input type "date"? Currently, it's giving me the date in the format 2015-06-02T18:30:00.000Z, but I actually need it to be in the format 2015-06-02. <input type="date" class="form-control" ng-mo ...

What is the process for sending an HTTP post request with a React/Typescript frontend and a C#/.Net backend?

In the frontend code, there is a user login form that accepts the strings email and password. Using MobX State Management in the userstore, there is an action triggered when the user clicks the login button to submit the strings via HTTP post. @action logi ...