javascript – Items with LoadMore Buttom, filter and the detail of first item or clicked item in react hooks

I am building the list of items (TEST) with loadMore bottom with filter and want to have loading state in LoadMore bottom and items itself.

After Loading the item I will fetch the detail of the first item for first time and after that load the detail of the test.

Code doesNot contain the fetching of the detail

If the Item is clicked again load the detail of another test.

function TeacherTest() {
  let { moduleId, url } = useModuleContext();
  const (tests, setTests) = useState(null);
  const (loading, setLoading) = useState(true);
  const (activeTestId, setActiveTestId) = useState(null);
  const (limit, setLimit) = useState(1);
  const (offset, setOffset) = useState(0);
  const (moreTest, setMoreTest) = useState(true);
  const (loadingMore, setLoadingMore) = useState(false);
  const (filter, setFilter) = useState("all");

  const fetchTests = () => {
    console.log(offset, "offset  fetchTest");
    axios({
      method: "get",
      url: `${url}/teacher/test?limit=${limit}&offset=${offset}`,
      withCredentials: true,
    }).then((res) => {
      let newTests = res.data.tests;
      newTests.length < limit && setMoreTest(false);
      console.log(newTests === ());
      console.log(newTests);
      tests ? setTests((...tests, ...newTests)) : setTests(newTests);
    });
  };

  useMemo(() => {
    setTests(null);
    setOffset(0);
  }, (filter))

  const showMoreTest = () => {
    setOffset(offset + limit);
  };

  useEffect(() => {
    fetchTests();
  }, (url, offset, filter));

  return (
    <div className="w-100" id="dash__wrapper">
      <div className="dashboard__container mt-4">
        <div className="main_dash">
          <div className="row">
            <div className="col-md-4 col-12 mb-2 px-0">
              <div className="pt-0">
                <div className="btn btn-block p-0 my-0">
                  <form action="./quiz-setup.php">
                    <Link to={`/${moduleId}/teacher/test/add`}>
                      <button
                        className="btn btn-lightblue p-2 w-100 mb-2"
                        id="addTest"
                      >
                        <i className="fas fa-plus pr-1" />
                        Add New Test
                      </button>
                    </Link>
                  </form>
                </div>
              </div>
              <TestSchedule
                tests={tests}
                moreTest={moreTest}
                filter={filter}
                setFilter={setFilter}
                showMoreTest={showMoreTest}
                loadingMore={loadingMore}
              />
            </div>
            <div className="col-md-8">
              <TestDetail />
              <TestResult />
            </div>
            <div className="row">
              <div className="col-md-4 col-12 mb-2 pl-md-2 px-0"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}```

function TestSchedule({ tests, showMoreTest, setFilter, loadingMore, moreTest }) {
  return (
    <div className="bg-white p-3 chart_contain dash__shadow dash__border">
      <div className="w-100 clearfix mb-2">
        <h6 className="py-2" style={{ fontWeight: 600 }}>
          Test Schedule
        </h6>
        <div className="float-right">
          {/* Dropdown to select test logs */}
          <form>
            <select
              defaultValue="all"
              onChange={(e) => {
                setFilter(e.target.value);
              }}
              className="custom-select border-0"
            >
              <option value="all">All</option>
              <option value="active">Active</option>
              <option value="scheduled">Scheduled</option>
              <option value="completed">Completed</option>
            </select>
          </form>
        </div>
      </div>

      <div className="bg-light radius-10 p-2 mb-1">
        <p className="quest__name">Weekly test 12</p>
        <ul className="list-inline description-ans text-muted">
          <li className="list-inline-item">
            <i className="far fa-clock" />
            &nbsp;40 min
          </li>
          <li className="list-inline-item">
            <i className="fas fa-bullseye" />
            &nbsp;80 Marks
          </li>
          <li className="list-inline-item">
            <i className="fas fa-desktop" />
            &nbsp;40 Questions
          </li>
          <li className="list-inline-item">
            <i className="fas fa-users" />
            &nbsp;MBBS 1st Year
          </li>
        </ul>
        <div className="row control-question d-flex justify-content-between">
          <div>
            <span className="badge badge-pill badge-success">Active</span>
            <small className="text-muted">June 20, 2020 - 17:00 NPT</small>
          </div>
          <div>
            <div className="major__btn test-log">
              <a href="#">
                <button className="major__btn__type button__blue p-0 m-0">
                  <i className="fas fa-edit" />
                </button>
              </a>
              <a href="#">
                <button className="major__btn__type button__red p-0 m-0 ml-2">
                  <i className="fas fa-trash" />
                </button>
              </a>
            </div>
          </div>
        </div>
      </div>
      <div className="bg-light radius-10 p-2 mb-1">
        <p className="quest__name">Weekly test 12</p>
        <ul className="list-inline description-ans text-muted">
          <li className="list-inline-item">
            <i className="far fa-clock" />
            &nbsp;40 min
          </li>
          <li className="list-inline-item">
            <i className="fas fa-bullseye" />
            &nbsp;80 Marks
          </li>
          <li className="list-inline-item">
            <i className="fas fa-desktop" />
            &nbsp;40 Questions
          </li>
          <li className="list-inline-item">
            <i className="fas fa-users" />
            &nbsp;MBBS 1st Year
          </li>
        </ul>
        <div className="row control-question d-flex justify-content-between">
          <div>
            <span className="badge badge-pill badge-danger">Expired on</span>
            <small className="text-muted">June 20, 2020 - 17:00 NPT</small>
          </div>
          <div>
            <div className="major__btn test-log">
              <a href="#">
                <button className="major__btn__type button__blue p-0 m-0">
                  <i className="fas fa-edit" />
                </button>
              </a>
              <a href="#">
                <button className="major__btn__type button__red p-0 m-0 ml-2">
                  <i className="fas fa-trash" />
                </button>
              </a>
            </div>
          </div>
        </div>
      </div>

      {tests ?
        tests.map((t, index) => {
          // console.log(t, "From single test");
          let { duration, id, end, name } = t;
          return (
            <div key={index} className="bg-light radius-10 p-2 mb-1">
              <p className="quest__name">{name}</p>
              <ul className="list-inline description-ans text-muted">
                <li className="list-inline-item">
                  <i className="far fa-clock" />
                  &nbsp;{duration} min
                </li>
                <li className="list-inline-item">
                  <i className="fas fa-bullseye" />
                  &nbsp;80 Marks
                </li>
                <li className="list-inline-item">
                  <i className="fas fa-desktop" />
                  &nbsp;40 Questions
                </li>
                <li className="list-inline-item">
                  <i className="fas fa-users" />
                  &nbsp;MBBS 1st Year
                </li>
              </ul>
              <div className="row control-question d-flex justify-content-between">
                <div>
                  <span className="badge badge-pill badge-info">
                    Scheduled for
                  </span>
                  <small className="text-muted">
                    June 20, 2020 - 17:00 NPT
                  </small>
                </div>
                <div>
                  <div className="major__btn test-log">
                    <a href="#">
                      <button className="major__btn__type button__blue p-0 m-0">
                        <i className="fas fa-edit" />
                      </button>
                    </a>
                    <a href="#">
                      <button className="major__btn__type button__red p-0 m-0 ml-2">
                        <i className="fas fa-trash" />
                      </button>
                    </a>
                  </div>
                </div>
              </div>
            </div>
          );
        }): <div> Loading Tests </div> }

      {moreTest && (
        <div className="row">
          <button onClick={showMoreTest} className="btn btn-lightblue w-100">
            {!loadingMore ? <> 
            <i className="fas fa-chevron-down pr-1" />
            Show More
            </> : "Loading..."}
          </button>
        </div>
      )}
    </div>
  );
}

Commerce 2 how to acces a users order items quantity

There is a similar question here but how can i access the amount of a product variation the current user has been ordered (in the last order)?
Would it be similar to this?

  $product_variation = $order_item->getPurchasedEntity();
  $product_id = $product_variation->product_id->getString();
  $product = Drupalcommerce_productEntityProduct::load($product_id);
  $product_amount = $product->getamountofOrders(); //or something like this

Get items modified in last 24 hours from Site collection

  • I would like to have the report of items modified in last 24 hours from site
    collection
  • Could anyone suggest me the best approach to hang with it either by going
    with SPaudit or with SPSiteDataQuery to get detail information and how can i
    do it.

algorithms – Given $n$ unique items and an $m^{th}$ normalised value, compute $m^{th}$ permutation without factorial expansion

Well, from the clarifications made in the comments, then this could be a solution.

I haven’t checked for correctness. Specifically the requirement of choosing the closest label to the one input. I think I am taking the one immediately below the number input. Probably that can be fixed by using closest integer, instead of floor below.

Let $L=L_1$ be the input label, which is a real number. Maybe we can just assume that it is in $(0,1)$.

We begin with the full collection of numbers say $C_1={1,2,3,…,n}$ from where one will be eliminated at each step.

In the first step we compute $a_1=lfloor L_1cdot nrfloor$. We pick the $a_1$-th element $p_1$ of $C_1$ to be the first element of the permutation and remove it form $C_1$. So, define $C_2=C_1setminus{p_1}$. Define $L_2=L_1cdot n-a_1$.

Continue in this way, in the $k$-th step, for $k=2,3,…,n$, put $a_k=lfloor L_kcdot (n-k+1)rfloor$, take $p_k$ to be the $a_k$-th element of $C_k$ and define $C_{k+1}=C_ksetminus{p_k}$ and $L_{k+1}=L_kcdot(n-k+1)-a_k$.

Finish when there are no more elements in $C_k$, or maybe when there is just one which will be forced to be the last element in the permutation.


See also factorial number system. Since this is essentially what we are doing.

filter – In a grouped list, how to display items of an intersection of two groups

Provided I have a category which gives x non mutually exclusive options.
I have a list of items which can be tagged with several of these mutually non exclusive options.

  • Item 1
  • Item 2
  • Item 3
  • Group C …

A user can now select one/several of the options so they retrieve a list of items according to each options they selected and the union of these options, if needed.

  • Group A — selected
  • Group B — selected
  • Group C

I have a constraint when it comes to displaying the result: the items must be grouped under the options they are tagged with.

This is where I am faced with a choice to make in order to display the items which are tagged with several of the select options – hence are at the intersection of several groups.

The alternatives are: display each items several times, one under each group they belong to, like so:

Or display a group for each intersection of groups

  • Group A
  • Group B
  • Group A + B

Solution 1 result in a duplication of the content (the item), solution 2, a duplication of the meta-information (the categories).

Now, this was an imaginary explanation. My real case implies 5 categories each with between 3-5 options and two nested grouping based on 2 of these categories. As a result, whichever solution comes with a big overload of duplicated information – just think of the possible combination of groups.
Nonetheless, I would like to have your opinions and knowledge on which would be the worse of two evils out of these two solutions ?

I might add that the value proposition I am working with for this content is partly, the number of items of content. Hence, albeit being more readable, I believe that solution 1 could be perceived as bearing disingenuity as it increase that number. Solution 2 would be worse in terms of readability though.

Of course, I am also investigating alternatives to grouping altogether but would like to put this problem out there for reflexion and see if someone comes with different angles than mine.

2010 Workflow: Copy Item (Document) from another list to current list (current item’s list)

I have a workflow which starts by copying some documents into a drafts folder. The thing is, after the workflow is finished the copied document needs to be copied back into the list(folder) from which it came. I want the copy to replace the original in the list. How can I specify this?

enter image description here

links – Creating Hyperlinks of Google Drive Items in Alphabetic Order

The original post that I got the google script editor code from was here:
Get share link of multiple files in Google Drive to put in spreadsheet
It works perfectly fine, but what I want to do is show the actual google drive link in the excel file (not the name of the file that has a hyperlink attached to it. I managed to do this by deleting #”‘ + f.getName() + ‘”# from the code, but the problem is, because they are no longer listed by file name (e.g. LG1, LG11, LG5), but by drive links (e.g.http….), the links can’t be sorted with the sort feature on sheets. Does anyone know how I can deal with this?

I will post the code below so

function myFunction() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var s=ss.getActiveSheet();
  var c=s.getActiveCell();
  var fldr=DriveApp.getFolderById("<id>");
  var files=fldr.getFiles();
  var names=(),f,str;
  while (files.hasNext()) {
    f=files.next();
    str='=hyperlink("' + f.getUrl() + '")';
    names.push((str));
  }
  s.getRange(c.getRow(),c.getColumn(),names.length).setFormulas(names);
}

PS: The reason I am trying to do this is because VLOOKUP doesn’t seem to work properly in excel when you try lookup cells with hyperlinks attached as it just takes the placeholder string (e.g. LG1) and gives you that without the hyperlink (e.g. http…) that was attached to it.
Another potential solution would be knowing how to sort the initial folder in the first place to my liking (haven’t managed to get that to work though)

dnd 5e – Should magic items which allow to cast spells be considered as material components?

For using Counterspell, a spell needs to contain some kind of component, otherwise it cant be countered.

https://twitter.com/jeremyecrawford/status/642086415040294912?lang=en

When casting spells from magical items the spell is cast at the lowest possible spell level, doesn’t expend any of the user’s spell slots, and requires no components, unless the item’s description says otherwise. DMG p141.

spells you cast from items can be countered

Does the Counterspell work against wands?

So, does it mean that the magic items are considered as the material components of the spell?

plugins – WordPress Plug-In to create database for members to choose items from and build their own page?

I am trying to create a site where a member can log in to their account and create their own page filled with their favorite products of a certain category.

Is it possible for me to create a master list with all of the possible products to choose from and then a member to go in and pick from categorized drop downs the items they want and drag and drop it to their member page?

I would like for the master list to link to the websites where the items can be found so that i dont have to download all of the images of every product and was hoping the link of the product could automate the image.

This would basically be like an amazon “favorites” page but from items that come from many different websites so that members have the products all in one place.

Is this something that would be possible for me to do with a wordpress plug-in?

Thank you for your help!

sharepoint online – Adding List Items

Stack Exchange Network


Stack Exchange network consists of 177 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange