adding list item with angular animations - angular-animations

I m trying to animate a list which is made with ngFor. When dynamically a new item is added to the array, i want to have the animation bellow. Somehow i cant get this rolling effect. Any ideas what am i doing wrong ?
#Component({
selector: 'widget',
templateUrl: './widget.component.html',
styleUrls: ['./widget.component.scss'],
animations: [
trigger('slideInOut', [
transition(':enter', [
style({transform: 'translateY(-100%)'}),
animate('800ms ease-in-out', style({transform: 'translateY(0%)'}))
])
])
]
})
html
<div *ngFor="let winner of widgetService.winners; let i = index"
class="winners__item" [#slideInOut]>
<img [src]="winner.imageUrl" alt="{{ winner.gameName }}">
<div class="block__container--first">
<div class="block__container--first--gameName">{{winner.gameName}}</div>
<div class="block__container--first--firstName">{{winner.firstName}}</div>
</div>
<div class="block__container--second">
<div class="block__container--second--timestamp">{{winner.timestamp}}m ago</div>
<div class="block__container--second--winning">{{winner.amount}} €</div>
</div>
</div>
[![enter image description here][1]][1]
what i have:
[![enter image description here][2]][2]
what i tried:
animations: [
trigger('slideInOut', [
transition(':enter', [
style({marginTop: '-100px'}),
animate('800ms ease-in-out', style({transform: 'translateY(0%)'}))
])
])
]

The elements jump down because the new element takes the first place. transform: translate() does not change the place behavior of the element, but only the visible position, without affecting other elements.
So to actual change the space of all elements, we need something like margin.
animations: [
trigger('slideInOut', [
transition(':enter', [
style({marginTop: '-100%'}),
animate('800ms ease-in-out', style({marginTop: '0px'}))
])
])
]
With this, the new item is placed above the list and pushes all following elements down when it moves.

Related

Next js router query all data is not coming

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.

How to solve page not found 404 - python django?

I have created an app which has the index.html which is the main page and when I run "py manage.py runserver" command it opens the index page. Then I created another app for home page and added urls, created views and everything as far as I know. But when I click "home" it navigates to "http://127.0.0.1:8000/static/home.html" and says "Page not found(404)" and "'home.html' could not be found" I will paste my code below
webapp\settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tbs',
'tbs_home'
]
webapp\urls.py:
urlpatterns = [
path('', include('tbs.urls')),
path('tbs_home', include('tbs_home.urls')),
path('admin/', admin.site.urls)
]
tbs_home\urls.py:
urlpatterns = [
path('home',views.home, name='home')
]
tbs_home\views.py:
def home(request):
return render(request, 'home.html')
templates\home.html:
{% extends 'index.html' %}
{% load static%}
{% block content%}
<h1 style = "font-family:Georgia;font:40px;font-style:normal;">Hi! {{name}}</h1>
<form action="add" method="POST">
{% csrf_token %}
Enter 1st num : <input type="text" name="num1"><br>
Enter 2nd num : <input type="text" name="num2"><br>
<input type="submit">
</form>
{% endblock %}
templates\index.html:
This is the part where "home.html" link is given in "index.html" page
<div class="col-xs-10 text-right menu-1">
<ul>
<li class="active">Home</li>
I think I've provided the necessary code snippets, thank you for your help in advance. I should be able to navigate to home page from index page when I click the home button.
in tbs_home\urls.py:
change that to :
urlpatterns = [
path('home/',views.home, name='home'),# adding comma is important
]
webapp\urls.py: urlpatterns = [path('', include('tbs.urls')),
path('tbs_home/', include('tbs_home.urls')),
path('admin/', admin.site.urls), # adding comma is important
]
Change installed apps to:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Replace the static tag with the url tag
<li class="active">Home</li>
The part in front the ':' tells django which app to look into and the part after the ':' says which url to use. The static tag points it to your staticfiles directory which you don't want
In the tbs_home\urls.py, add the app_name
app_name = 'tbh_home'
urlpatterns = [
path('home',views.home, name='home')
]
And in the webapp\urls.py, add a trailing backslash to the url like:
urlpatterns = [
path('tbs_home/', include('tbs_home.urls')),
path('admin/', admin.site.urls)
]

Final animation state is discarded at end of animation

I'm trying to animate an element at the :leave transition and I'm a bit baffled by its behaviour.
trigger('inOut', [
transition(':enter', [
style({'max-height': '0'}),
animate(250, style({'max-height': '150px'}))
], { params: { maxHeight: '150px'}}),
So I would expect my element being animated to have a max-height of 15px set at the final frame of the animation... and left there! I can see the max-height being animated but then at the end its removed and the element scales to whatever height fits its content. Struggling to imagine how this is useful, am I doing something wrong?
Update - Resolved it with this
trigger('inOut', [
state('void', style({'max-height': '0'})),
state('*', style({'max-height': '{{maxHeight}}'}), { params: { maxHeight: '0px'}}),
transition(':enter', animate(300)),
transition(':leave', animate(250))
]),
A way to solve this is to use a state for the end of the animation and (#animation.done) to trigger this state.
Here is a StackBlitz example.
app.component.html
<div [#routeAnimations]="state" (#routeAnimations.done)="onDone($event)" class="animate-div">
</div>
app.component.ts
import { trigger, style, state, animate, transition } from '#angular/animations';
#Component({
animations: [
trigger('routeAnimations', [
state('done', style({
maxHeight: '150px'
})),
transition(':enter', [
style({ 'max-height': '0' }),
animate(1000, style({ 'max-height': '150px' }))
], { params: { maxHeight: '150px' } })
])
]
})
export class AppComponent {
state = '';
onDone(event) {
this.state = 'done';
}
}

MarkoJS for loop over array of objects

I really need help with a pretty simple and trivial problem, but here it goes. I am using marko on the server side in NodeJS and am rendering my views via:
ctx.render({
});
with koa-router and koa. I need help in the html dept on how to go about for or while looping over all these to display via:
<ul>
<li>
</li>
</ul>
I have tried and tried and tried, but am too frustrated to move on, please someone save me as it feels like a Monday brain fart on a Thursday -_-
"invoices": [
{
"id": 1,
"customer_id": 1,
"line_items_total": 187,
"additional_fees": 10,
"tax_rate": 0.07,
"sub_total": 210.79
},
{
"id": 2,
"customer_id": 4,
"line_items_total": 100,
"additional_fees": 0,
"tax_rate": 0.07,
"sub_total": 107
},
{
"id": 3,
"customer_id": 2,
"line_items_total": 48.4,
"additional_fees": 0,
"tax_rate": 0.07,
"sub_total": 51.79
},
{
"id": 4,
"customer_id": 9,
"line_items_total": 286,
"additional_fees": 35,
"tax_rate": 0.07,
"sub_total": 343.47
}
]
The full project file is at: GitHub
This is under:
/routes/invoices/invoices.js
and the query can be found in:
/db/queries
which refers to:
queries.objects.getAllObjects()
in:
/routes/invoices/invoices.js
You are correct that you can loop over arrays using the following syntax:
<ul>
<li for(invoice in data.invoices)>${invoice}</li>
</ul>
Marko also allows you to loop over the properties of an object if you need to do that as well:
<ul>
<li for(invoice in data.invoices)>
<ul>
<li for(key,value in invoice)>
<strong>${key}</strong>: ${value}
</li>
</ul>
</li>
</ul>
For reference: https://markojs.com/docs/core-tags/#codeltforgtcode
L-O-L got it, for anyone referencing this in the future, a nice simple:
invoices.marko
file to get a basic understanding. Of course I could:
${invoice.id}
${invoice.customer_id}
${invoice.line_items_total}
${etc}
to list out each individual attribute/property/value of the desired .key
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Invoices</title>
</head>
<body>
<ul>
<li for(invoice in data.invoices)>${invoice}</li>
</ul>
</body>

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