Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
Resin
Client
Commits
a003d055
Commit
a003d055
authored
3 years ago
by
Etienne LOUPIAS
Browse files
Options
Downloads
Patches
Plain Diff
fix(posts): load more posts with tag
parent
916739f9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!229
feat(data-consent): add data sharing consent when creating and editing a...
,
!225
fix(posts): load more posts with tag
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/post/components/post-list/post-list.component.ts
+13
-9
13 additions, 9 deletions
src/app/post/components/post-list/post-list.component.ts
src/app/post/services/post.service.ts
+14
-15
14 additions, 15 deletions
src/app/post/services/post.service.ts
with
27 additions
and
24 deletions
src/app/post/components/post-list/post-list.component.ts
+
13
−
9
View file @
a003d055
...
@@ -56,11 +56,14 @@ export class PostListComponent implements OnInit {
...
@@ -56,11 +56,14 @@ export class PostListComponent implements OnInit {
...
this
.
selectedLocationTagSlug
,
...
this
.
selectedLocationTagSlug
,
...
this
.
selectedPublicTagsSlug
,
...
this
.
selectedPublicTagsSlug
,
];
];
// Reset posts
this
.
resetPosts
();
// Apply search
// Apply search
this
.
getPosts
(
this
.
filters
);
this
.
getPosts
(
1
,
this
.
filters
);
}
else
{
}
else
{
// Init default news list
// Init default news list
this
.
allPosts
=
[];
this
.
allPosts
=
[];
this
.
filters
=
[];
this
.
postService
.
getPosts
(
1
).
subscribe
((
news
)
=>
{
this
.
postService
.
getPosts
(
1
).
subscribe
((
news
)
=>
{
this
.
fillArticles
(
news
);
this
.
fillArticles
(
news
);
});
});
...
@@ -84,7 +87,7 @@ export class PostListComponent implements OnInit {
...
@@ -84,7 +87,7 @@ export class PostListComponent implements OnInit {
this
.
allPosts
=
[...
headLineTag
,
...
_
.
difference
(
this
.
allPosts
,
headLineTag
)];
this
.
allPosts
=
[...
headLineTag
,
...
_
.
difference
(
this
.
allPosts
,
headLineTag
)];
}
}
public
getPosts
(
filters
?:
Tag
[]):
void
{
public
getPosts
(
page
:
number
,
filters
?:
Tag
[]):
void
{
// Parse filter
// Parse filter
let
parsedFilters
=
null
;
let
parsedFilters
=
null
;
if
(
filters
)
{
if
(
filters
)
{
...
@@ -97,11 +100,8 @@ export class PostListComponent implements OnInit {
...
@@ -97,11 +100,8 @@ export class PostListComponent implements OnInit {
}
}
}
}
// Reset posts
this
.
resetPosts
();
this
.
isLoading
=
true
;
this
.
isLoading
=
true
;
this
.
postService
.
getPosts
(
1
,
parsedFilters
).
subscribe
((
news
)
=>
{
this
.
postService
.
getPosts
(
page
,
parsedFilters
).
subscribe
((
news
)
=>
{
this
.
fillArticles
(
news
);
this
.
fillArticles
(
news
);
});
});
}
}
...
@@ -135,9 +135,13 @@ export class PostListComponent implements OnInit {
...
@@ -135,9 +135,13 @@ export class PostListComponent implements OnInit {
private
loadMore
():
void
{
private
loadMore
():
void
{
if
(
this
.
pagination
&&
this
.
pagination
.
page
<
this
.
pagination
.
pages
)
{
if
(
this
.
pagination
&&
this
.
pagination
.
page
<
this
.
pagination
.
pages
)
{
this
.
isLoading
=
true
;
this
.
isLoading
=
true
;
this
.
postService
.
getPosts
(
this
.
pagination
.
next
).
subscribe
((
news
)
=>
{
if
(
this
.
filters
)
{
this
.
fillArticles
(
news
);
this
.
getPosts
(
this
.
pagination
.
next
,
this
.
filters
);
});
}
else
{
this
.
postService
.
getPosts
(
this
.
pagination
.
next
).
subscribe
((
news
)
=>
{
this
.
fillArticles
(
news
);
});
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/app/post/services/post.service.ts
+
14
−
15
View file @
a003d055
...
@@ -23,22 +23,21 @@ export class PostService {
...
@@ -23,22 +23,21 @@ export class PostService {
}
}
public
getPosts
(
page
:
number
,
tags
?:
string
[]):
Observable
<
PostWithMeta
>
{
public
getPosts
(
page
:
number
,
tags
?:
string
[]):
Observable
<
PostWithMeta
>
{
if
(
!
tags
)
{
let
tagsFilter
=
''
;
return
this
.
http
.
get
<
PostWithMeta
>
(
`
${
this
.
baseUrl
}
?page=
${
page
}
&include=tags,authors`
)
if
(
tags
)
{
.
pipe
(
map
((
item
:
PostWithMeta
)
=>
new
PostWithMeta
(
item
)));
let
tagsString
=
''
;
// Transform tab filters to string filters
tags
.
forEach
((
tag
,
index
)
=>
{
tagsString
+=
tag
;
if
(
index
!=
tags
.
length
-
1
)
{
tagsString
+=
'
+tags:
'
;
}
});
tagsFilter
=
`&filter=tags:
${
encodeURIComponent
(
tagsString
)}
`
;
}
}
let
tagsString
=
''
;
// Transform tab filters to string filters
return
this
.
http
.
get
<
PostWithMeta
>
(
`
${
this
.
baseUrl
}
?page=
${
page
}
&include=tags,authors
${
tagsFilter
}
`
);
tags
.
forEach
((
tag
,
index
)
=>
{
tagsString
+=
tag
;
if
(
index
!=
tags
.
length
-
1
)
{
tagsString
+=
'
+tags:
'
;
}
});
return
this
.
http
.
get
<
PostWithMeta
>
(
`
${
this
.
baseUrl
}
?include=tags,authors&filter=tags:
${
encodeURIComponent
(
tagsString
)}
`
)
.
pipe
(
map
((
item
:
PostWithMeta
)
=>
new
PostWithMeta
(
item
)));
}
}
public
getTags
():
Observable
<
TagWithMeta
>
{
public
getTags
():
Observable
<
TagWithMeta
>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment