Next js router query all data is not coming - node.js

I made a request to my backend and brought all the categories to the homepage. From there I redirected to a page called [category_slug].jsx.
I'm getting data with useEffect and I'm pulling it from the context api
categories.map((category) => (
<Link
href={{ pathname: `/categories/${category.category_slug}`, query: category }}
className="text-sm hover:underline hover:opacity-60"
key={category.id}
>
{category.name}
</Link>
))
Also, I used this method before to make the page with the videos and it worked then.
All data comes to that page, but the videos come with 2 empty strings, but it should not come as such.
{
"id": "9",
"name": "test2",
"category_slug": "test2",
"description": "testt2",
"videos": [
"",
""
],
"image": "",
"created": "2022-12-07T02:07:05.838815Z",
"updated": "2022-12-07T02:07:05.838840Z"
}
My [id] page:
import React from "react";
const CategoryPage = () => {
const router = useRouter()
const category = router.query;
console.log(category)
// captilaze first letter and lowercase the rest
const capitalize = (s) => {
if (typeof s !== "string") return "";
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
};
return (
<>
{ /* <CustomHead title={capitalize(category.name)} />*/}
<div className="my-10 mx-auto flex min-h-screen px-24 py-10 ">
<div className="flex w-full flex-col bg-white p-10">
{ /* <h1 className="text-2xl font-bold up capitalize">{category.name}</h1>*/}
<div className="mt-10 grid grid-cols-1 place-items-center gap-2 md:grid-cols-3">
</div>
</div>
</div>
</>
);
};
export default CategoryPage;
Please excuse me if I didn't express myself very well.

Related

[Shopware6]: How to reuse the customer selection component in administration?

I'm trying to create a custom-field that is an entity-single-select for customers, exactly like the one in the sw-order module as seen here
sw-order-create-details-header > sw-entity-single-select
Is there some way for me, to configure the look of my custom-field to be the same as the extended select-field in the sw-order module?
With that i mean, inclusive of firstName, lastName, address and customernumber?
(Without creating a a new component)
What i have so far is this:
protected $customFields = [
[
'name' => 'referrer_set',
'config' => [
'label' => [
'en-GB' => 'Referrer',
'de-DE' => 'Referrer',
],
],
'customFields' => [
[
'active' => true,
'name' => 'refferer_set',
'type' => CustomFieldTypes::ENTITY,
'config' => [
'componentName' => 'sw-entity-single-select',
'entity' => CustomerDefinition::ENTITY_NAME,
'placeholder' => "Wurde empfohlen von ...",
'highlightSearchTerm' => true,
'allowEntityCreation' => false,
'show-clearable-button' => true,
'labelProperty' => 'firstName',
'label' => [
'en-GB' => 'Empfohlen von',
'de-DE' => 'Empfohlen von',
],
],
],
],
'relations' => [
[
'entityName' => CustomerDefinition::ENTITY_NAME,
],
],
],
];
Unfortunately this isn't quite so trivial to achieve.
You could override the component which is responsible for rendering custom fields sw-form-field-renderer.
Inside the override you check if it is your specific custom field that should be rendered. In the template of the override you then set the content of the slot result-item, which is a corresponding to each option in the dropdown. You'll additionally have to extend the binds of the component with a criteria to add the billing address of the customer as an association.
The override:
import template from './sw-form-field-renderer.html.twig';
const { Component } = Shopware;
const { Criteria } = Shopware.Data;
Component.override('sw-form-field-renderer', {
template,
computed: {
isMyCustomField() {
return this.config.componentName === 'sw-entity-single-select' && this.$attrs.name === 'refferer_set';
},
bind() {
const bind = this.$super('bind');
if (this.isMyCustomField) {
const criteria = new Criteria;
criteria.addAssociation('defaultBillingAddress.country');
bind.criteria = criteria;
}
return bind;
},
},
});
The template sw-form-field-renderer.html.twig:
{% block sw_form_field_renderer_scope_slots %}
{% parent %}
<template
v-if="isMyCustomField"
#result-item="{ item, index, labelProperty, searchTerm, highlightSearchTerm, isSelected, setValue, getKey }"
>
<!-- copy/paste from sw-order-create-details-header -->
<li
is="sw-select-result"
:selected="isSelected(item)"
v-bind="{ item, index }"
class="sw-order-create-details-header__customer-result"
#item-select="setValue"
>
<div class="sw-order-create-details-header__customer-result-item has-many-childrens">
<div>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'firstName') || getKey(item, `translated.firstName`)"
:search-term="searchTerm"
/>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'lastName') || getKey(item, `translated.lastName`)"
:search-term="searchTerm"
/>
</div>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'customerNumber') || getKey(item, `translated.customerNumber`)"
:search-term="searchTerm"
class="text-truncate"
/>
</div>
<div
v-if="getKey(item, 'company') || getKey(item, `translated.company`)"
class="sw-order-create-details-header__customer-result-item"
>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'company') || getKey(item, `translated.company`)"
:search-term="searchTerm"
/>
</div>
<div class="sw-order-create-details-header__customer-result-item text-gray-500">
{{ item.defaultBillingAddress.street }} <br>
{{ item.defaultBillingAddress.zipcode }} {{ item.defaultBillingAddress.city }} <br>
{{ item.defaultBillingAddress.country.name }}
</div>
</li>
</template>
{% endblock %}

Material-UI - TypeScript - Autocomplete with getOptionLabel and renderOption

I am trying to display member and company using MUI Autocomplete.
I have suggestion array to show as options
[
{
"__typename": "Member",
"id": "ckwa91sfy0sd241b4l8rekas9jx",
"name": "my name 2",
"companyName": ""
},
{
"__typename": "Member",
"id": "ckwac4ijl25dsd80b4l8fpsrc64o",
"name": "my name",
"companyName": ""
},
{
"__typename": "Member",
"id": "ckwa8z6z7004dsd2b4l81m6ras9c",
"name": "my name 1",
"companyName": "A COMPANY"
}
]
I use this to display
<Autocomplete
id="free-solo-demo"
freeSolo
options={
suggestion &&
suggestion.map(
(suggestion: any) =>
suggestion.name
)
}
onChange={(event, value) =>
HandleUserProfile(value)
}
renderInput={(params) => (
<TextField
{...params}
placeholder="Search..."
onChange={handleChange}
/>
)}
/>
By using this I am getting options if only I search with member name.
I want to search with both company and member and need to customize UI of option.
I tried this
<Autocomplete
id="free-solo-demo"
freeSolo
options={suggestion}
getOptionLabel={(option) => `${option.name} ${option.companyName}`}
renderOption={(option)=>{
return <h1>{`${option.name}: ${option.companyName}`}</h1>
}}
onChange={(event, value) =>
HandleUserProfile(value)
}
renderInput={(params) => (
<TextField
{...params}
placeholder="Search..."
onChange={handleChange}
/>
)}
/>
but It is not working.
it shows error TypeScript error in ... Property 'name' does not exist on type 'never'. TS2339
First, you should make sure the name field doesn't have any duplicated values, that's why you should use the mandatory id field to select one.
And also you need to build a custom filter function or use createFilterOptions hook from Autocomplete component.
https://mui.com/components/autocomplete/#custom-filter
import Autocomplete, { createFilterOptions } from '#mui/material/Autocomplete';
...
const filterOptions = createFilterOptions({
stringify: ({ name, companyName }) => `${name} ${companyName}`
});
<Autocomplete
options={suggestion}
getOptionLabel={option => option.name}
filterOptions={filterOptions}
...
/>;

How to render data in groups to ejs

I want to display data that has been grouped into the EJS?
I have the following data:
"results": {
"Angular CLI": [
{
"category_name": "Angular CLI",
"article_title": "Mengenal Framework Angular CLI"
}
],
"Tips dan Trik": [
{
"category_name": "Tips dan Trik",
"article_title": "Tutorial : Cara Membuat Repositori Github Private"
},
{
"category_name": "Tips dan Trik",
"article_title": "Mengenal Fitur Media Query pada CSS"
}
]
}
Following on the EJS file:
<% results.forEach(function(data) { %>
<div>
<p><%= data %></p>
</div>
<% }); %>
But it does not display data at all.
EDIT :
Dear all, thank you for giving some explanation. So that I can find a solution to this problem.
<% for (let category in results) { %>
<b><%= category %></b>
<% results[category].forEach((data, key) => { %>
<p><%= data.article_title %></p>
<% }) %>
<% } %>
Provided your object is something like this below
var obj = {"results": {
"Angular CLI": [
{
"category_name": "Angular CLI",
"article_title": "Mengenal Framework Angular CLI"
}
],
"Tips dan Trik": [
{
"category_name": "Tips dan Trik",
"article_title": "Tutorial : Cara Membuat Repositori Github Private"
},
{
"category_name": "Tips dan Trik",
"article_title": "Mengenal Fitur Media Query pada CSS"
}
]
}
As your obj.results is object and not array, you could iterate through all properties of obj.results object and display values like this
<% for (var prop in obj.results) { %>
<div>
<p><%= prop%> : <%= results[prop] %></p>
</div>
<% }); %>
Let me know if I misunderstood your issue

ejs forEach function not working for json data in node

forEach is not a function when I am iterating json file in ejs using nodejs giving some error while iterating.. below is three section what i have done in .ejs file, json and nodeJS
Here is my JSON Data
<pre>
{
"MenuName": "Main Menu Here",
"widget": {
"window": {
"data": "Click Here",
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"window": {
"data": "Click Here",
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"window": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
}
</pre>
This is my ejs
<html>
<head>
<title><%= title %></title>
</head>
<body>
<h1> My Name Is <%= title %></h1>
<h1> My Name Is <%= printIt.MenuName %></h1>
<ul>
<% printIt.widget.forEach(function(item){%>
<li><%= item.window.data%></li>
<% }); %>
</ul>
</body>
</html>
</pre>
in NodeJS
<pre>
app.locals.printIt = require("./sample.json");
</pre>
I can able to print
My Name Is <%= title %> and My Name Is <%= printIt.MenuName %>
What i missed here..?
First of all, your JSON data will keep only single record of widget window and which is last one. Because window key will overwrite previous hold value.
Update your script with this one
<ul>
<% for(var item in printIt.widget){%>
<li><%= printIt.widget[item].data%></li>
<% } %>
</ul>
Hope this will help to solve your query !!

Pulling Tweets into a Spotify app

I'm building a little Spotify app that displays tweets from the current Artist playing. I'm using Bocoup's jQuery Twitter plugin to grab and display the tweets: http://code.bocoup.com/jquery-twitter-plugin/
MANIFEST.JSON
{
"BundleType": "Application",
"AppIcon": {
"18x18": "tutorial.png"
},
"AppName": {
"en": "News"
},
"SupportedLanguages": [
"en"
],
"RequiredPermissions": [
"http://twitter.com"
"http://*.twitter.com"
"http://*.twimg.com"
],
"VendorIdentifier": "com.News",
"RequiredInterface": "1",
"BundleVersion": "0.2",
"BundleIdentifier": "News",
"AppName": "News",
"AppDescription": "Twitter updates from the Artist playing."
}
From the Index file:
<script type="text/javascript">
$(document).ready(function() {
$('#tweets').twitter({from: 'mediatemple', replies: false})
launch();
});
</script>
</head>
<body>
<div id="info">
</div>
<div id="news">
</div>
<div id="tweets">
</div>
</body>
Nothing displays in Spotify when I open my app, but if I open the index.html file in a browser, the tweets appear. What am I missing?
The RequiredPermissions JSON needs commas.
try:
"RequiredPermissions": [
"http://twitter.com",
"http://*.twitter.com",
"http://*.twimg.com"
],
Things fail silently if there is a problem in the manifest. Always use a JSON linter (http://jsonlint.com/) to verify at least the format is proper JSON.
UPDATE: After any changes to manifest.json you must restart Spotify.

Resources