Rebuilding Jagr.Co, Adding Posts & SubCollections to Collections

In this stream, we focus on adding the ability to add posts and subcollections to a collection.

Published
Nov 27, 21
Duration
2h 34m

Developer, dog lover, and burrito eater. Currently teaching AdonisJS, a fully featured NodeJS framework, and running Adocasts where I post new lessons weekly. Professionally, I work with JavaScript, .Net C#, and SQL Server.

Adocasts

Burlington, KY

Transcript

Looking for something specific? Feel free to search the page for keywords to find a specific portion of the live stream that interests you most.

0:15

there we go okay we're up are we yeah okay good

0:22

all righty uh so we'll be picking up today where we left off last night um which was last night we kind of altered

0:30

the future table flow a little bit so previously we were planning on having post series

0:37

topics but we've since changed that last night to post collections taxonomies

0:43

and then we went through set up those models and those migrations um

0:48

and now today well we also got the crud for the collections working so now what

0:54

we need to do is actually allow for posts to be bound to

0:59

collections so that's what we'll be working on today and so we'll be placing that right

1:05

over here and the main thing i think that

1:11

don't ever mind um i was gonna say i think we need um the

1:17

collection to actually be created before posts can get bound to it but uh we can work around that actually and

1:24

make this doable all in one so let's go into the creator edit page and let's go ahead and start stubbing out what we

1:31

want this to be so ideally it would be some kind of autocomplete

1:38

but we don't need to start with that necessarily out of the box um instead

1:44

well yeah why don't we so do we have anything um auto complete based

1:53

in here i do not believe we do let me go take it well on the last one i

1:58

was using view so let's see here well why don't we do a simple select so we'll

2:05

do at form input alt and then for

2:11

the data for it um let's see we're going to do a type of

2:17

select well no you would want it to be typable so we'll do type of let me go take a look at the input real quick

2:24

so we have your basic input maybe we will need to

2:31

make an autocomplete type field and why don't we do that so we'll use this

2:37

as a group so the type will be a group and then we'll do at end

2:44

whoops and then we'll need to do add slot input

2:51

and slot and then within here we'll lie our auto

2:57

complete um and we can actually give this a label

3:02

and everything too so label will be

3:10

[Music] posts sure so we'll start with that we can see that

3:16

we have our posts here with no form input and then let me go find an autocomplete

3:21

js auto complete nope don't want jquery

3:27

autocomplete.js maybe so what i'm hoping for is something that

3:33

doesn't actually

3:41

usage input id okay you have any

3:47

examples of what it here's a demo

3:53

that should that should work okay so we'll plan for that

3:59

so let's see this would be input with an id

4:06

of post autocomplete and we'll just end it like that for

4:13

right now and then we'll go ahead and install this so let's go into the installation copy this

4:26

okay and then

4:32

usage so we need an id

4:37

and then we need the script and then it takes in the config okay

4:43

so within our scripts here since this is specifically

4:50

going to be for well we can do it down at the meh we'll do another script for it and

4:57

won't hurt anything so studio will do collections.js

5:04

we will import i'm assuming we're gonna it's

5:09

probably a default export i would assume i didn't see anything with the import statement in here

5:15

so import autocomplete from who was it at

5:21

uh it had a weird at yeah right here

5:27

i don't know if it was we'll use autocomplete within visual studio code to finish that up so we'll do that do

5:33

and yep all right that's full autocomplete.js there we go

5:39

hey augustine thanks for stopping by um and then

5:46

we need to figure out what all it takes within the configuration so let's see selector would be the

5:52

selector so we can do um const

5:59

post autocomplete equals new right

6:05

new just go back yeah so since it's new and i'm hoping that that's a default import i'm going

6:11

to go ahead and capitalize that so auto completes

6:18

selector would be at post

6:24

autocomplete and

6:30

then yeah i need some way to tell it to grab data

6:36

we could pass that in on load or we could have it filtered

6:43

down i would prefer the back end to do the filtering so

6:48

let's see if maybe yeah async there you go data source

6:56

all right and then we grab it and then we return it gotcha

7:02

it's a data source oh was that a function yes all right

7:09

async take some kind of query

7:14

okay that's probably the search query we'll have to see exactly what that looks like um

7:21

and then keys data object key to be searched

7:26

so the key for this i'm going to put that above source would probably be name well no it's post

7:33

so that would be title actually okay so now we need to create some form of autocomplete search for the post but

7:41

first i want to see exactly what this query is i assume that's probably just a string

7:47

but it would have to be like url safe the way that they're using it right so let's see what exactly it is so

7:52

console.log query and then that will also allow us to see whether or not this autocomplete

7:58

is taking to the post at all so we need to add it to our webpack

8:03

config since this is a new file

8:11

studio dot collections

8:17

and resources js studio

8:23

collections.js i believe so we have this save and

8:29

i think we need to restart the server whenever we add in a new entry

8:35

so we'll do that as well

8:41

and then we need to actually add that post um that script onto the page

8:47

so i'm just going to copy and paste the one that i have from here yeah

8:53

onto here and instead of studio post editor it's

8:59

just to do the collections okay so let's

9:06

check and make sure that that's loading in we have our post or our um

9:12

input over here and

9:18

i want to just mmm doesn't look like it's overwriting anything with that

9:29

well that's a babble thing if i remember

9:36

right

9:45

yeah babel polyfill let's see he's got a butt there's always

9:50

a butt

10:06

well i'm pretty sure last time i just went with the battle polyfill so even though he says deprecated i'm gonna go

10:16

up least that's a temporary fix and i can't even spell it right there's no

10:22

i don't know why i figured there would be an out there

10:28

all right and then within

10:35

that particular script

10:42

um i know that there's a way to like have that apply everywhere with webpack encore but for right now we'll do this

10:48

just to make sure that everything's working with

10:54

this so we no longer get that error which is good

10:59

and now that input is of writing stuff on that normal input so that is at least working

11:06

so let's see if we can type something in and get oop all right

11:12

yeah that makes sense because we're not returning anything um i want to do a full-on test so testing

11:19

with a space and it looks like it had that space in it yeah so it's not necessarily url safe like their um

11:27

thing here imply so i'm gonna pass it up as a query string um

11:32

i think so we'll do something like uh

11:40

let's wrap it up in a try catch well no i want the error to come back while we're developing it so i won't

11:46

quite wrap it on the try catch yet so const posts equals weight

11:52

i will do data pardon me i still use axios i know i

11:58

should use fetch but i still use axios axios then we'll do get and then this will be something like api

12:08

posts um search or something of the sort and then we'll pass it well this should

12:14

be tilda all right we could do it yeah

12:20

all right now we'll do that and

12:28

term equals uh query

12:34

so we'll see about that and then

12:39

return data dot posts try that to start

12:46

and then we need to actually go create that input or route so do routes and then we have our posts right

12:53

here actually that needs to also be within studio so api

13:00

studio posts there we go so we have this basic api here for the

13:08

assets so far so we'll tack this inside of here as route.group

13:13

and then we will scope this specifically to the studio so prefix studio

13:21

as studio route dot get

13:26

uh what was it posts search i think

13:32

and then this will go inside of the posts controller oh wait we need to name space this as

13:38

well um so let's see this should be app uh

13:43

control uh controllers http studio i think

13:49

let me cheat look at this one app controller yeah okay all right and then we'll do

13:56

let's just do search on that

14:02

and then we want to go into that controller so post controller

14:09

do this just below and we'll do that at the bottom

14:15

public async search so we have a request and then we're

14:20

going to have a response http context contract

14:28

all right and then let's see to get a particular query string let's

14:33

see what is that so const term equals

14:38

request dot i think qs gets the whole

14:45

query string yeah object um we could do that and then we could

14:50

accept like a sort but

14:55

let's see i think is it only

15:01

get value of specified keys no i think that's off of the body

15:06

[Music] which one is it

15:13

i think it might be input request body or query string there we go

15:19

that's the one i'm looking for term otherwise it should be an empty string

15:26

um and then we'll want to just query using that term so const

15:32

posts equals and i'm just going to do a like a simplistic query it doesn't need to be anything fancy

15:37

um awaits post dot query dot where

15:47

uh sorry title is like

15:53

the term and then that also needs to be

16:01

percent term percent

16:08

okay so we'll just do a simple title search on that um and then maybe order by

16:13

descending

16:19

the uh publish it hey

16:32

and then we will just return those back

16:40

so we'll do posts and then it doesn't yeah we don't need to do a

16:45

message or anything like that so we can just return back the posts okay

16:51

and we already made the route for that right so we can go ahead and test that out

16:57

so i'm going to just refresh for clarification here

17:03

well we're still getting in there or no it's okay it's sending it off but that's returning back at 500. so what be the

17:10

issue okay so it's something wrong with the

17:16

namespace how i can i find module

17:21

code app controllers http studio post controllers

17:27

oh did i do post controllers whoops

17:32

sure enough it's a single controller full of multiple controllers all right let's try

17:38

that again all right so uh do we have any posts

17:46

that's going to be an issue let's create some test test posts real quick all right um

17:52

this is a test post doesn't need to be anything fancy

18:02

another test post and we'll do one more that doesn't match anything with the

18:08

previous ones so we'll do yeah

18:14

all right so we have some test posts it gives us some stuff to query off of

18:19

and then within our collection here we should be able to do

18:24

if we search for test oh i saw an object show up all right so it looks like the search is

18:31

so yeah that comes back empty but this one came back with something

18:38

um i did name them test didn't they like two of them had tests in it

18:45

test and test okay

18:50

oh i bet you it's capitalization probably all right well let's test it with out nope still

18:59

doesn't want to show me up on that

19:09

oh no it is coming back just doesn't want to display and then

19:14

it's also showing it as object like if we take back to just t it's showing it as object object so

19:24

oh keys is supposed to be an array okay so that might be the issue because i

19:30

just put it as a string i think so let's see yep sure enough

19:35

so let's wrap that up in an array and let's see if maybe that fixes

19:41

this no it's still out there did it refresh it should have but we'll check make sure

19:48

yeah it's still object object interesting um all right i guess

19:54

the next thing to check would be to see exactly what i'm returning back so let's console.logoutdata.posts

20:08

make sure that we're just getting back the array of the posts

20:15

so we got two here so yep sure enough all right

20:22

so it probably has some sort of thing not within there that's specifying or searching for value and

20:29

key or something like that value id

20:35

something of the sort so let's see

20:46

result item

21:06

hmm let's take a look at what it's doing for this string so

21:12

for that it's just a string for this yeah

21:22

we have title am i putting that in the right spot data keys

21:28

data yeah keys

21:35

there we go okay that's better um

21:41

cool so now that's showing up so one problem solved there

21:50

cool so they persist and then if we do another if we just do a

21:56

cool so that seems to be working next we need to like handle the select so those are

22:01

definitely like they don't even seem to be selectable

22:09

um

22:15

so i'll just let's see results list

22:20

rendering interception and customizing so

22:31

okay i'm gonna go ahead copy that

22:38

let's try so that probably outside of data so it's probably like here um

22:45

destination it's probably something that it's i'm gonna leave destination off it

22:50

should autofill that i would think with whatever it's using [Music] and then

22:56

here we're going to want

23:16

i think that's it so that it's like at least selectable um and then i don't know whether or not

23:22

we're gonna need to like put an ant click on that or if there's gonna be some kind of let's see yeah there we go all right so

23:28

that's at least appearing clickable now um let's see if there's like a

23:35

but we're also going to want new results open next previous go to select

23:45

select the result i know from the list it should do that automatically that you would think that's just to do it programmatically

23:54

but definitely if i type that in it doesn't even want to autofill the select with it

24:00

so

24:13

is there any examples just steal one off of their example

24:20

styles plugins playground maybe

24:27

yeah here we go so let's see they are doing

24:42

all right

24:49

well i'm gonna copy and paste all of this um and i'm gonna paste it down below

24:58

um so here's ours and i'm gonna paste this down here

25:03

because i don't know what all oh it didn't do any formatting ah wow

25:08

that's a lot too oh that copied way too much

25:16

yeah that copied the whole thing there we go

25:22

all right now we'll pluck out what we need out of here

25:31

ah so let's see here

25:40

get rid of all of these comments all right

25:47

and then we'll tack this on to also we'll replace

25:52

this with jesus pete

26:04

they really didn't no there was not this much in there was there no i okay evidently i didn't get rid of the whole

26:09

thing last time or did i copy the whole thing again no okay that's definitely not as big as

26:15

it was before

26:20

okay that's better so we'll go ahead and

26:26

let's see i used mine with a capital a lowercase c and let's get our data grab in place of

26:34

their data grab

26:43

turn data.posts okay and our key is just title

26:53

we do not need a filter our back end will be taking care of that

27:00

everything else let's just go ahead and save and see what we get uh oh we need the selector in there too don't worry so

27:05

selector do they have a selector in there that i need to overwrite it doesn't look like it so we'll add that in

27:11

okay so let's comment ours out

27:17

okay and oh we got some we got an error

27:24

canon access property at event listener document.queryselectors null but which one is it

27:30

it could be a number of them um let's get element by id i i think

27:38

why don't we go ahead and just use the default like what what what what are what are they they're probably just

27:43

using autocomplete as their id on their input i would assume that's what it is yeah

27:48

okay so this would then be um

27:56

posts autocompletes posts

28:03

auto-complete any others i mean i got a lot of stuff in here

28:13

okay let's give that a go still all right what line are you on

28:19

110.

28:27

document query selector add event listener so there's no toggler i don't know what the toddler would do

28:34

what's the tackler doing there example oh okay mode yeah

28:45

uh augustine asked can you show me the project you do yet are you do you mean the project that we're working on

28:51

um we're rebuilding jaeger the site that i host all my posts or

28:56

content on um so like i don't have an end result but this

29:02

is ultimately like what we're rebuilding and we're going with different styles and a different approach with it this

29:07

time um so that's kind of what we're doing so like the home page is all hard-coded at

29:13

this point but it will end up looking something like this um and then we'll have a post page and all

29:19

that that we're incrementally working on so there is no finished project with this already i'm kind of just working

29:25

through this as we go um

29:32

so we'll get rid of this toggler we'll see if we run into an issue with that blur on blur i don't know what that

29:38

would be for either

29:43

okay no error so let's try this out so oh now we got in there

29:50

title is null

29:56

oh okay so const action equals action the blur on blur we can get rid of that too

30:04

i'm just gonna go ahead and get rid of this as well i think that's related

30:12

okay there we go no error but we are not getting any results

30:19

either that or it's just like up here that might be absolutely positioned or

30:24

something like that so let's see if no the list is empty

30:39

well it could be because it's caching it too i don't know how strong their cache is

30:47

so come over here we'll check let's turn yeah xhrs on

30:54

so no it's not kicking anything out as we type

31:03

so let's see what that's all about

31:16

i'm gonna get rid of that that might be messing it up

31:25

nope still doesn't want to go all right you

31:31

let's see

31:42

i don't necessarily see anything in here that would uh well there's no query now is there

31:50

all right let's do that see if that makes a difference

31:55

nope are we at least getting in here

32:05

yeah we're getting in there so it's kicking it out somewhere um it could be

32:10

actually erroring out right here

32:17

let's go ahead and just get rid of it

32:26

okay there we go now we're getting stuff

32:35

cool all right and then if we select something

32:42

cannot access property enter html document query selectors null online 89.

32:51

yeah so i mean whenever a user selects something what we're going to want to do is append it

32:57

into a list anyway so we need to go ahead and create that list

33:07

so let's do so actually what we can do

33:12

is um

33:18

i what did i i have some form of input that can go inside of

33:23

the alt um

33:28

i don't remember what that is but so let's do

33:34

a let's see

33:42

well no you wouldn't want that to be as well yeah yeah why not template with an id of

33:50

well we have the list item kind of altered in there already so we'll do ul with an id of

33:57

selected posts right

34:02

and then what we'll do is we'll just append that list item from the collection into there

34:08

so let's see if

34:15

all right so let's walk through this here so let's see we have here

34:20

are we actually getting the selection or does this thing changed here we definitely know that we need to

34:26

change something so why don't we go ahead and instead of query selectoring all of

34:32

queer selector um instead of query selecting all of that well i will

34:39

do it there for right now i'm just going to get on by id

34:47

and what did i name that selected posts

34:56

dot append child

35:02

um and then we would want to make like a

35:07

node for that to actually append or we could just enter html

35:14

concatenate a string and we'll we'll do this

35:19

well do we

35:24

yeah why don't we go ahead and just enter html pin to string for right now so const

35:49

i have no clue what selection is yet so we're just going to do selection there

35:54

and we'll get rid of this line

35:59

and it looks like that's trying to set it to the selection we'll see whether or not that works if it is then i would imagine that that is just like the title

36:06

string um so yeah we'll see what what all this is going to do

36:13

so we'll do test and then we will select this one

36:21

and let's verify whether or not that's the ul yep so that's the selected ones

36:26

all right and now what we really need is an id so

36:32

let's see what our selection is and then it's also query clearing out the feedback down here so selection is

36:39

indeed just a string um feedback though

36:45

let's see what the event has in it so

36:52

nope that wouldn't be it selection

36:57

yeah so this this is what we would ultimately want so it has the value in here with the actual row

37:04

record so we want selection value dot id and then

37:12

yeah so it's using the key to get the string there so that works for that

37:25

so that would be the matched key

37:41

oh okay so that's ultimately just getting it off of there so

37:46

all right get rid of all of that

37:52

um we can get rid of this because we don't want that well actually we want to clear it out

37:57

um let's get rid of that as well and then we'll leave that console.log in there for a minute until we have this

38:04

working so here what we want is for this to have

38:12

a hidden input in it with our post ids

38:18

and then it's also going to need to have the collection id in it as well because ultimately what we're going to want

38:25

is for these collections to be nestable and so we would have also so that this wouldn't necessarily in the

38:31

future will be posts but it will be collections and then each collection would have a post and then you could

38:37

have posts directly off of the collection as well so uh to show you an example of what i'm

38:42

talking about here so if we go into this wasn't the best implementation of

38:48

it especially since the back end isn't the best implementation of it um

38:53

but if we go into the series and let's take a look at the let's build nope not let's build the let's learn

39:01

um so you can see the modules here which are ultimately in the back end just

39:07

well no these are different but in our back end now these are just

39:13

collections so this would be a collection and then this would be a child collection this would be another child

39:18

collection and then all of the posts would be just off of that child collection

39:24

if that makes sense

39:30

so that's what we're after

39:36

so we're going to want an input type hidden

39:44

um we need to determine how we want to maintain this so it would be

39:53

named of

39:58

um so this one would be collection id

40:05

but it would be an array and then the value would be

40:12

for right now whatever collection we are in which i don't think we have anywhere

40:19

currently accessible

40:24

we do not so actually we can leave that null if it's just directly off of the parent

40:32

for right now anyway um so we'll just do post id here and that one will be an

40:37

array and the value there we do have and

40:43

that's going to be

40:50

feedback selection value id if i'm remembering that correctly

40:58

and then we would have the actual label off of it

41:05

and then we can use counters um on css side to count

41:11

so we don't necessarily need to put well like an index based counter on it

41:18

um i don't exactly remember how those work well to look those up but to start with this should work okay

41:25

so let's try this again let's do t select that nope

41:30

selection is not defined

41:36

oh yeah

41:43

okay

41:51

there select you now all right well that needs some

41:59

oh that's the input why isn't that hidden i did too oh i didn't i did not oh my bad

42:06

so yeah that should be a type hidden okay let's try that one more time

42:13

so t there we go so now we have that and then if we were to save this we would now get with our data

42:20

post ids i don't know why i'm doing an underscore there actually that should be just let's do post id

42:26

okay i'll probably do post ids there we go so within our

42:33

collection validator post ids

42:39

schema string nope sorry array

42:46

um and that should actually be optional because you don't necessarily

42:53

need to have any posts and then members

42:59

schema.number because we'll just be sending up the ids and then

43:04

number needs a rule of exists

43:13

for the table posts and the column id

43:20

okay so we can go ahead well

43:27

then we need to try and persist it in order to actually test and see whether or not it works but we could just console.log out our data

43:34

so let's see we'll start with edit and then we'll go back to create since we it'll

43:41

be easier to test it out with edit that we don't have to create a bunch

43:46

uh okay so sorry update i mean

43:55

so on here instead of trying to append the post id in with the collection merge

44:01

we're going to want to extract it out of the data so it'll be post ids and then data would then be a spread of

44:07

the rest and then we want to do something like if

44:14

post ids dot well no sorry uh then we want to do awaits collection related

44:22

there it is posts dot sync and this will definitely change in

44:28

the future because we need to actually get the sort order to save but for right now just to test things

44:34

out let's do post ids let's just pass it no

44:41

why argument of type number array or undefined it's not assignable to a parameter oh okay

44:46

gotcha there okay so we'll test that out we'll see we

44:53

can also toss a console.log up just to make sure that we're getting post ids as we expect

45:00

but i believe that should work so we'll test it out here let's do t we'll tack two on there

45:11

another thing we need to do is uh remove already selected once so i guess we would want filter for that

45:17

to remove already selected items from the autocomplete or we could pass up like an array

45:22

array of extend or ignore ids on here as an additional query string i

45:28

think that would probably be the better approach though the back end is doing everything so let's go ahead and try saving

45:34

okay we won't have it auto populate yet because we don't have anything querying but if we check out the database

45:42

and see where we need to check collection posts there they are we have

45:48

two with the post id of one and two on collection number two so they seem to be saving so the next

45:54

thing to do would be to get those to auto well we can also check out the console log as well make sure everything came

46:00

through yep so we get rid of that console log

46:05

and whenever we actually go into edit a collection now we want to also query

46:11

those posts

46:17

for our collection so we'll do just a simple load i think

46:30

and we don't have it in place yet but we'll go ahead and put the order by the sort order on here just so we have it

46:36

there

46:44

our order by pivot sorry right isn't that a thing

46:52

um thought it was

46:57

let's see

47:06

oh

47:38

let's see so we have pivot foreign key pivot related form key pivot table pivot columns

47:44

am i looking in the right spot nope that's i'm sorry that's not the query uh query builder here we go so

47:52

maybe not maybe we i don't forget it's been a while

47:57

select project user dot role as pivot rule oh yes all right

48:04

that's right so it would be pivot sort order on here because i already have the pivot

48:12

column defined on the model so query dot order by

48:18

pivot sort order we'll at least see if that works well we can't quite test it yet because

48:24

nothing's different with the sword order but we'll test it here in a minute so that should get them loading into the

48:30

edit page so then on the creator edit

48:35

what we need to do is go ahead and plot those in here

48:40

um

48:51

this will be each post in collection.posts

48:58

and we can do i i think we can do that

49:06

or well let's just wrap it in an if and make it a little bit cleaner

49:27

okay and then we'll do the same thing that we have going on on that script so it'd be an li

49:34

with an input type hidden

49:39

um name of post oop post ids as an array

49:45

and the value is the post dot id

49:52

and then just a post up title rendering out there

49:57

and then end li so now if we save this that should be a

50:03

way to kind of auto populate it because those post ids will now be

50:09

within the form and there they are it's not pretty to look at but it should

50:14

work and we need to add in a way to actually remove them as well

50:20

so why don't we go ahead and do that um div class flex

50:26

just justify between

50:36

okay and then we'll do button type button

50:51

do that for right now oh oh i didn't get the red oh

50:56

um let's see what does that need to be 700 yeah that works all right so it's not

51:02

pretty but again should work and then that would just be

51:10

we need to remove the whole li so

51:15

why don't we do this instead let's move this up to here get rid of this div altogether

51:24

i don't think it this input should mess anything up oh okay so then all we need

51:29

to do is

51:36

unclick this

51:42

parent element.remove i think

51:48

so if we click on this yep there it goes it's away and then if we save

51:54

that should have synced it so it would have removed um i think it was this first one here with

51:59

the post id of one yep so it's gone and then if we go back

52:05

in and edit this there we are we just have that one left

52:10

so that seems to be working as well so let's go ahead and get this to where

52:15

if we type we don't get a duplicate response of something that's already selected

52:23

so let's see here how do i want to maintain that

52:30

i think something that would be better is if we turned this

52:36

into an alpine component instead of relying on native javascript

52:41

that way we can actually hold all of these within an array

52:47

instead of having like the template defined in two different places

52:56

so i am going to pull the collections over

53:03

to the right hand side i'm going to get rid of the old autocomplete that we had there

53:11

and

53:18

let's see if i can remember how to do this um actually i'm going to pull up

53:24

the file manager here so that i can cheat off of it because i alright so it's just a simple function that returns

53:30

back an object all right so we'll do function um

53:38

collection post manager

53:44

that takes in posts which will default to an empty

53:50

array if it's not provided and we'll have this return

53:58

is there like an unmounted hook or something like that for alpine because that's where we would probably

54:03

want this stuff to register and it would be great to have that

54:08

within the life cycle of alpine so let's see

54:15

alpine js hooks

54:22

life cycle there we go in it okay

54:28

do i need to explicitly do that within data though or can i do that like within the function approach

54:35

i would assume you'd be okay to do that within the function approach right

54:42

all right let's give it a go let's see if it works so is that i guess that would be within

54:48

the return as like a function

54:53

in which case we would want to i don't all right let's wrap this all up in

55:00

well all right let's cut it out since we know that that works as one and paste it with another knit

55:08

okay and then um

55:14

i think what am i doing i'm plopping that on the window yeah that way we can call it from within the template

55:23

and then this would be called collection post manager oh i'm okay

55:30

collection we'll do it as that naming so i'll alter this one to match

55:37

lowercase c okay and then let's see here we want

55:44

this to have posts which we will default to posts

55:51

that's passed into the function arguments um probably going to want some kind of

55:56

loading state and apart from that

56:04

i don't know we'll start with this all right

56:10

results actually yeah let's do results as well so um or options

56:18

okay so then my hope would be that

56:24

within here let's see we're using an arrow function so my mind says that should be okay so

56:30

let's do this dot um

56:38

loading equals true

56:50

well no i mean it's this component here that's going to take care of those options

56:55

would it not be easier to just build this on my own at this point then like

57:03

yeah i don't see why not well you have like the arrow controls and all that with the drop down don't you

57:12

no i'm not seeing any

57:18

no yeah okay we'll we'll progress so this dot options equals

57:26

data dot posts and then we'll go ahead and just return back data.post there

57:37

and then we should be okay to get rid of the results list

57:43

no no that's the that's the actual visual representation of the drop down

57:49

uh it's this result item i think

57:56

no maybe not i need to spend some time to

58:02

figure out exactly what those are for all right but it's on this selection here we actually want to get rid of some

58:08

stuff so um it's mostly just right here so we would

58:14

want to do this posts

58:20

oh no all right so this needs to be an arrow function

58:27

now this needs to be this dot posts dot push

58:32

feedback dot selection dot

58:37

value i believe and we'll just have that be the whole

58:42

list of the posts okay

58:51

that should be okay and then over here on the view side

58:58

what we would want to do is instead of doing this we would want

59:03

this wrapped up in a div

59:09

with x is it init or

59:14

data i think it's it's x data isn't it i think so and then we called a function

59:21

so that would be collection post manager and provided

59:27

the posts which we'll do here in a second i just want to get this

59:33

pasted back in first

59:38

and then this would be from edge as

59:44

collection collection.posts and then i think we need to stringify

59:50

that as well so with the um

59:57

view or the asset manager i went and just did json.string if i but

1:00:03

i'm pretty sure that there is a helper to string five with adonis as well

1:00:12

oh yeah right here yep so we just call stringify there

1:00:20

and that should work so stringify

1:00:26

okay and then instead of manually looping over this with edge

1:00:33

we would want to switch this to a template x4 [Music]

1:00:40

post in posts with the key of post dot id

1:00:48

and then right here we want to do well that was if right here we want to do end

1:00:53

template and get rid of that if all together

1:00:59

um decrement whoops decrement and then

1:01:07

this needs i don't know if they do the um curly braces so we'll do x text post

1:01:13

dot title and then this i know needs to be like

1:01:20

that and then like that

1:01:25

and i think well oh the air click needs to change as well so

1:01:31

this would change to act click equals remove we need to add that in or delete

1:01:39

it's just the right spot it sure is remove post and then we'll take the post

1:01:45

in

1:01:57

okay

1:02:04

so give that a save and we'll give that a test let's see if it works

1:02:10

all right collection post manager is not defined

1:02:17

um

1:02:27

did i go and name it right so collection post manager window.collectionpostman

1:02:43

so it seems the same uh let's see i'm going to get rid of this side

1:02:49

and let's make sure that that script is actually plopping on the page okay it might be that the script's not there

1:02:56

well no the script would be there because it was working before so it's right here

1:03:04

it could have something to do with the placement though um let me take a look and see exactly where i had it on here oh it was outside

1:03:09

of the screen yeah so it's probably something with the placement because within the scripts is where alpine is added so i think this

1:03:16

needs added before alpine so it would probably be in the prior

1:03:21

section right so here so we're headed oh no it was in scripts it was outside

1:03:27

of the script though i think did i have this inside of the script no i did not

1:03:32

okay well then that just takes us right back to where we were

1:03:44

all right let me check and see is it x data

1:03:54

form file manager let's check and see what we're using in there so form file manager

1:04:01

x data yep

1:04:07

oh that's actually importing it just like that so

1:04:13

we could do that as well we can move this into a component called autocomplete and make it reusable

1:04:22

um i don't know if that would we would need to like plop it out into its own thing again whenever

1:04:28

we add in the module system so we'll leave it separate

1:04:35

um i do have a feeling though that

1:04:41

it's something with it being called before alpine or something like that

1:04:51

collection post management's not defined but i bet you it's on the window

1:04:59

post minute out post manager yep so it's there

1:05:05

it's just not to find when it needs to be so i need to figure out where it doesn't need to be defined at

1:06:17

you

1:06:40

there we go okay all right

1:06:47

yeah okay so it's back to working cool cool cool so if we add another one

1:06:53

into this still work so if we had test back in yeah okay all right so i just need to be helping

1:07:01

with it so i'll probably split that out into its own thing

1:07:06

um okay

1:07:12

now i lost my train of thought um

1:07:19

oh right we were gonna make sure that the uh items were unique within the search

1:07:24

so if we head back into the script right here

1:07:33

we can add get ignore ids

1:07:41

that returns back this posts dot map and it just returns back the id

1:07:49

so that would be an array of those ids and then what we would want to do

1:07:54

is do and ignore

1:08:00

and then we can actually let's do const ignore ids equals this dot get

1:08:08

get ignore ids.join with a comma so comma separate them

1:08:14

and then we'll do ignore ids

1:08:19

okay and then up in our end point

1:08:25

for the post controller we can do

1:08:30

const ignore ids equals request

1:08:36

input

1:08:42

ignore have that default to an empty array

1:08:47

or empty string and then split it

1:08:53

by the comma so then we could also do then

1:08:58

a where not in

1:09:05

the ignore ids are you an array no you're in any

1:09:13

but why would that be in any why does split return back in any it doesn't make any sense

1:09:21

oh oh oh okay um

1:09:28

is what array array whoops

1:09:34

here's a ray um let's see

1:09:40

if there is let's see if array dot is

1:09:47

array ignore ids then we'll do

1:10:11

if we'll do it with an if on the query array dot is array

1:10:17

ignore ids then we will do query

1:10:23

query dot we're not in and then we can make this be an array

1:10:31

by spreading it right

1:10:37

oh yeah okay now let's expect to get two arguments got one because we need to specify the id there we go

1:10:43

let's see do we need to spread still no okay it seems happy without it so

1:10:48

okay cool so that should be good um i'm gonna give that a save

1:10:54

and try it out so we have another test post already defined here so if we type a

1:11:02

all right cool that's not coming back you can verify that it's one of the ones that's already listed i know it's kind of hard to tell but by the x over here

1:11:08

and then the actual results have title um it's a little hard to see but so it seems to be working if we type test it

1:11:16

does not come back if we select this is a test post and then we type test again

1:11:21

comes back as zero matches so that seems to be working if we remove them both

1:11:28

and we type test we get back a 500.

1:11:34

so all right i have to imagine that's something to do with an empty array being provided for

1:11:40

the ignore

1:11:48

invalid input syntax for type integer yeah so whenever we split the empty um

1:11:54

yeah

1:12:03

so why don't we

1:12:08

what is well i don't know

1:12:21

because if you have an empty string and you split it it

1:12:26

turns it into an object array with uh yeah

1:12:34

so i mean we could tack on a filter there to get rid of empty strings

1:12:39

but it seems a little redundant

1:12:45

does filter boolean do that i don't think it does but

1:12:52

because it's still an empty string on there okay yeah turn it into an empty array

1:12:57

see there you can see it's an empty string okay so we'll stick with that that

1:13:02

should let's refresh to get rid of those errors

1:13:08

so if we get rid of you and we do test there they are

1:13:14

okay so this seems to be working all right now

1:13:23

um we want now that we have that working we want these to be

1:13:29

able to work for modules as well so we should be able to create another collection within this collection

1:13:44

so this is where things can get a little

1:13:49

messy so let's see

1:13:55

we're going to want to take this component up a notch

1:14:01

outside of the input

1:14:08

okay so now you are inside of the input

1:14:13

or the um that component and what the heck happened to the

1:14:18

indentation here all kinds of flopped up

1:14:26

okay and this would just change from

1:14:31

collection post manager to just collection manager because now this is going to maintain

1:14:36

collections as well

1:14:45

okay

1:14:51

um and then we're going to want something

1:14:56

like a button in here to add a new collection

1:15:21

um

1:15:33

yeah i think that's right

1:15:44

so i don't know something like that and sub collection um

1:15:52

and then this would be not just an array of selected posts

1:15:57

but

1:16:05

let's do collection items instead i think that's a little more appropriate

1:16:14

well no hold on a minute so we're going to want the post autocomplete to definitely be

1:16:21

specific to we're going to want it for the

1:16:27

root collection but we're also going to want it for all of the sub collections as well

1:16:40

so whenever you create a collection i think we're going to want this to loop for each collection but then

1:16:47

we're also going to want it to be at the bottom of the collection itself

1:16:58

so this would be template

1:17:23

okay and then we're gonna have that inside of each one of those but we're also going to have

1:17:31

um another ul that would then nest these within it

1:17:40

oops so i pasted that too soon

1:17:50

well now the ul would be outside of the loop

1:18:01

no it was that that needed okay there we go oops oops

1:18:07

there we go okay there we go all right and then this would be

1:18:16

the sub collection name

1:18:23

i have no clue how this is going to work i know that we definitely don't want these to be alt based inputs so maybe we

1:18:29

get rid of that just i don't even know if we want it to be a group at this point but we'll we'll

1:18:34

leave it as that and it's the same let's give it a save and see what we get

1:18:40

probably in here yep collections is not defined which of course it's definitely not

1:18:48

so we need to come in here collections

1:18:56

which this would want to accept collections as well so

1:19:02

posts specific to a collection are going to be within the collection item post specific to the collection that we're

1:19:08

editing so this collection will be with over here

1:19:16

in the sort order we don't have this touched at all yet will match as well so you can have post

1:19:24

subcollection post sub collection so the sort order will be inclusive of them

1:19:29

all i think we'll touch that last because then we're going to need to merge the arrays into

1:19:35

one another in order to make that happen which should be interesting but we'll

1:19:42

figure it out probably do like a computed property that just merges the two together based off of their safe sword order or

1:19:48

something like that okay so now what we need is the click

1:19:55

function that actually creates the collection so here add collection

1:20:04

i'm going to collapse this in it

1:20:09

here it was add collection with it

1:20:16

and all this does is creates a collection it doesn't take in a name or

1:20:21

anything like that you can alter the name afterward it will be given a base name so

1:20:29

data equals weight axios post

1:20:36

api studio

1:20:42

collections stub

1:20:49

and then this dot collections

1:20:54

push data dot

1:21:01

collection okay so let's go create this api studio collection stub

1:21:37

okay and then the collections controller

1:21:44

do this right underneath the create because that's in essence what it is so store

1:21:51

public async stub won't need anything off of the request

1:21:57

because it doesn't take a name or anything like that but we will need a response oop what the heck

1:22:05

http context contract okay so

1:22:10

nothing to validate all that we need to do is await collection.create

1:22:17

and we'll give it a name of

1:22:23

something like your new collection um owner id

1:22:28

is oh we do need auth there we go

1:22:34

off user id um what else on data up here

1:22:43

we don't want well it won't need a slug at all

1:22:52

but we'll let we'll let it do its thing um

1:22:58

collection type id status id state id none of those apply to this

1:23:03

but those are not nullable but they should have a database default so they should be okay um

1:23:10

so that i think that should be it and then all we need to do is return response dot

1:23:16

oh we need we need to get back the collection so that we can return it

1:23:22

okay json collection so that's it that should be it i think

1:23:29

so if oh that needs to be async okay

1:23:38

there we go uh is that iterator a new error so yep

1:23:45

that's applicable iter is undefined

1:23:55

why all right so that

1:24:03

uh

1:24:10

let's take a look at the actual collections so oh oh

1:24:15

okay did a coal in there instead of an equals

1:24:23

all right um different error this time is that still applicable

1:24:29

nope okay something with hot reloading i guess so if we click it's a giant button for this

1:24:35

but uh again right now we're not after pretty we're just after working ad collections not defined so it's not

1:24:40

getting the function name it's probably something with the button um

1:24:46

i don't think i'm going to want to use that button anyway so i'm just going to not use the edge

1:24:52

component button and instead let's just do an actual button button so that we can do that click

1:25:02

add collection

1:25:11

okay so it won't look like a button it'll just be text but it'll actually be a button that if we click

1:25:16

that uh oh i need to set a type on it type equals button so that the form

1:25:23

doesn't submit on me like it just did so if we come back in here i have no

1:25:28

clue if that just created a collection so i'm going to go test and see or not test but check out the database

1:25:34

and see so let's do collections

1:25:40

all right nothing in here with the name your new collection or anything like that so it shouldn't have

1:25:46

or did i refresh yeah no okay nothing with the name your new collection so we're good so if we

1:25:53

now we click add new collection there is our new collection

1:25:59

oh the one thing that's missing is it needs to be bound to this

1:26:04

collection so it needs the parent id so that is one thing that we do need to send up with this

1:26:11

and we need to pass that in here so parent id

1:26:17

should be and i'm going to break this down because we also need to add in the collections to this as well

1:26:24

parent id should be available

1:26:29

collections dot id or sorry collection dot id

1:26:37

otherwise we want that to be null okay

1:26:43

and then

1:26:49

well that should be okay because it would come back undefined and it would fail the truthy check anyway

1:26:54

okay and then we went to collections as well so collections and that one will be stringify

1:27:01

collection dot collections i think

1:27:07

is that what we named or did we name it children let's go take a look at the collection table and see what the

1:27:13

we have parent oh there is no children so we can't load that we need to do a separate query

1:27:22

is there a way to do that i'm trying to think

1:27:38

not off the top of my head i can't think of a way to do that i don't know i've never tried it before

1:27:43

so what i'm thinking is like to where you do public children and then you would say like

1:27:50

find the parent by this id i don't think that exists i think we have to query it separately which is no

1:27:55

big deal

1:28:03

let's see here so on well first let's so we do want

1:28:09

the request so that we can get back the parent id here so let's do

1:28:16

const well we could use the validator as well that way we get back an error saying that something doesn't exist we

1:28:22

can check to see whether or not it does exist so const data equals

1:28:29

await request dot validate

1:28:37

schema equals do i have that imported

1:28:42

now

1:29:02

create i'm just going to do this online since we only should be really small

1:29:08

parent id schema.number

1:29:14

rules.exists dot table

1:29:20

collections column id

1:29:27

okay so then we would just merge data in

1:29:32

to that and then what was the other thing that i needed to do

1:29:38

um

1:29:45

shoot there was something i got distracted with this one that i was headed to do

1:29:50

what was it ah fudge

1:29:58

there was something in here oh the query um

1:30:04

okay so on edit because we haven't done create yet i have to go back and do that

1:30:10

so on edit edit edit right here uh we need to query for the um children collections as well so let's do

1:30:19

children equals um a weight

1:30:26

collection well here so no we can't do related now

1:30:31

can we collection dot query dot where parent id equals collection dot id

1:30:40

border by the sort order okay and then let's add children into

1:30:46

this okay and then down here

1:30:53

where was that oh right up here so it won't be collection.collections it will be um just

1:31:00

children and that needs to come after it okay

1:31:07

so oh select star from collections where parent id one or yeah

1:31:15

order by sort order sending column sort order does not oh right it's pivot sword order my bad

1:31:27

okay nope oh

1:31:34

hmm

1:31:43

because there is no relation there it's the issue right

1:31:48

all right

1:32:05

um

1:32:12

no there is no sort order yeah no oh we're gonna have to add that aren't we

1:32:20

yeah we're gonna have to add that

1:32:32

so collection to collection whenever a collection has a subcollection we need a way to order it um

1:32:38

because these are going to be like the modules where you separate a collection up into different sections

1:32:43

so we have the parent id but we don't have a way to sort them whenever they do have a parent id so we need table dot

1:32:52

sort order on here um

1:33:01

we'll make that nullable i think well

1:33:08

not nullable defaulted to zero and then open the model

1:33:23

okay um

1:33:33

so what i'm going to do is i'm just going to comment this offer right now just so that we can continue on make sure that this is working and then we'll

1:33:38

go back and refresh the database it's definitely not all the data needs to persist

1:33:46

but we have that prepared for whenever we do refresh so we have that collection that we just

1:33:52

created that didn't get bound to anything so now if we click this we get a 422

1:33:59

where's the actual here's the okay let's see required parent id

1:34:06

did i not add it i must not have added oh i added it um

1:34:12

here but i didn't actually add it into the script

1:34:19

yeah i didn't add it in here at all

1:34:25

we'll put it on the data just in case but i don't think it need to be on there at all but it doesn't hurt

1:34:31

okay so that should be it all right let's refresh to get rid of

1:34:36

those errors and add new collection there it is so

1:34:42

now we should have a collection that properly has a parent id so if we refresh this

1:34:48

we have that junk one that got the null of parent id and then we have this one that's properly bound

1:34:56

so that should be good and then you can see that our posts are looped

1:35:01

they're loop-de-looped um so we need to change the one where the collection i need to here let me add

1:35:07

some hierarchy to that

1:35:12

let's see oops accidentally clicked so let's come in here and where we have

1:35:18

the collection name um i'll just make that bold for right now

1:35:25

there we go so this is for the collection

1:35:32

this is for this collection so this sub collection this main collection

1:35:41

and then eventually we'll merge them into one another so

1:35:46

we need to separate this out because this should not have a post bound to it at all yet

1:35:53

so if it's within here

1:35:58

we need to alter what we're looping over so instead

1:36:05

of posts here it should be sub collection

1:36:10

dot posts which then we run into the issue well we're not loading that so let's go load that

1:36:17

so within here let's drop this down

1:36:22

i'm going to drop down the order by comment out too and then we'll do preload

1:36:27

and we should have posts within here and these posts do have a sort order

1:36:33

already so we'll do query dot order by and i believe this one would be

1:36:38

pivot sword order so we give that a save now we should have posts

1:36:45

coming through and if we save this that should now be yup so now this is

1:36:51

empty it doesn't have any posts but the collection as a whole does have a post on it

1:36:56

okay now we need to alter this to say hey whenever you select a post it needs to go to this and not

1:37:03

this so let's take a look at that

1:37:12

um okay

1:37:18

where's the actual so yeah another issue is these are both gonna have the same id

1:37:24

so

1:37:30

let's think for a second here

1:38:32

let me change that to just use a class query selector um and then within the init on selector

1:38:40

you would change to

1:38:46

collection of posts did i put it oops did i put an s on that in here or did i

1:38:51

just do collection of post no you didn't collection posts okay good

1:38:57

okay so let's check it should still be there

1:39:02

refresh make sure that yeah okay so that's still there this one's not binding though you can tell because it doesn't have the um placeholder on it

1:39:15

so that might only be doing

1:39:25

it could be because it's within a loop um

1:39:31

and maybe a net is before like ready

1:39:37

let me go back and look at the life cycles here and see what else we have so we have data in a net

1:39:56

oh it looks like that's really it just dated a net there's no like

1:40:02

mounted or anything like that

1:40:07

yeah like if you're talking view um okay

1:40:14

well

1:40:27

so we know that the selector's working because it's still coming on for the second one

1:40:33

so we know that that's still good

1:40:43

what if we put this inside of a next tick is that this does have that right

1:40:52

oh i got another magics ooh would it be this then inside of the function

1:41:00

probably try and see what happens

1:41:22

okay well so it is only happening to one because

1:41:27

now this has it but this one doesn't that's interesting

1:41:33

because it like it most of the time if they accept a selector they'll do it to all that apply to the selector

1:41:52

yeah no that that is very much so only for one isn't it so it says

1:41:58

um function that returns an element

1:42:06

so we need to call that for each instance of it

1:42:12

so and anytime that we add in a new item evidently

1:42:18

so uh we'll split this off into a function inside of here um

1:42:25

and we're gonna need a way to pass specific whoops let me take the next tick with me

1:42:31

we're gonna need a way to pass a specific selector into it or we're gonna need to

1:42:37

alter again how we're specifying the selector for specific collection

1:42:44

so init autocomplete

1:42:51

we'll need the selector of some kind passed in

1:42:58

okay all of that should be self-scoped um

1:43:05

yeah all of that should be okay i think it shouldn't shouldn't hurt anything

1:43:13

and then we need to provide the selector there

1:43:19

so here this one would be this dot and knit autocomplete

1:43:26

for the main so i guess we'll name this dot

1:43:34

autocomplete main or something like that i don't know

1:43:41

so this would be id

1:43:47

i didn't and then we would understand to do it

1:43:52

again for each post or each collection sorry so this dot

1:43:57

collections map

1:44:08

and then we'd probably do

1:44:15

something i guess oh let's make these back ticks

1:44:23

c dot id give that a save come in here and then we need to change this to match that

1:44:31

so this would become id no it was what was it autocomplete

1:44:38

collection id

1:44:59

okay see if that works

1:45:06

there we go all right now they're both highlighted up

1:45:11

cool now the next issue is

1:45:16

if in here we type another it's not going to show up because it's selected down here so we

1:45:23

need to change that ignore to be separate based off of the autocomplete as well

1:45:31

so i'm sure there is a better way to

1:45:37

structure all of this but we'll move forward with what we have um

1:45:50

let's see how do we want to do that so that's within the init autocomplete

1:45:56

yeah it is and it's grabbing it using this ignore

1:46:03

ids which is grabbing it if i can find it um based

1:46:08

off of this posts so

1:46:16

why don't we pass in a second that is the collection so if collection

1:46:23

is null we want to do it off of this post if it isn't null then we want to do it

1:46:28

straight off of the collection

1:46:36

so or we could just pass in the collection id i guess right

1:46:42

that way we don't have to worry about mutation off of this object or anything like that so

1:46:50

collection id um and then

1:46:55

shoot where's the selector oh yeah and then we'll just bind it based off of the selector so if collection id

1:47:03

then we'll do what was it auto

1:47:09

complete collection collection id

1:47:16

otherwise it will just be

1:47:22

auto complete main yeah and then here we would pass in

1:47:29

just empty and then here bc.id

1:47:35

now i like it the old way past and selector then pass in the collection and then

1:47:40

we'll just grab the collection id off of the collection

1:47:46

so c and then

1:47:54

get ignore ids pass in the collection into there

1:48:00

and then we'll do if

1:48:06

collection return this dot

1:48:12

find or shoot this dot collections dot find

1:48:18

get it off of this instead of that way we don't have to worry about mutations on this particular object getting

1:48:23

outdated c dot where c dot id equals

1:48:30

collection id dot map no

1:48:35

dot all right let's

1:48:41

do c equals and then we'll return

1:48:48

c dot

1:49:00

yeah otherwise just return this off of posts okay

1:49:09

and that should be that should be that should be good okay

1:49:20

all right so now if we type another there it is and if we type

1:49:26

another down here it is not so that's still working cool

1:49:32

and if we select this is test post that's the next thing that we need to do because now that's adding it on to the main

1:49:39

and not necessarily the actual collection so that's the next step so let's see our selection

1:49:46

right down here

1:49:55

so the same sort of thing is going to apply here um if we have a collection add it onto the

1:50:00

id otherwise add it onto the posts so if we have a collection

1:50:11

sorry that should be post.push

1:50:22

what am i doing doing a dance there we go so that should be all that we need for

1:50:27

that i believe so now if we do test and we select this one

1:50:33

we're getting there how fun what's the air cannot access property posts

1:50:40

oh yeah i did this.collection collections yeah and then we would need

1:50:46

to find it so there's a little bit more to that than what i let on so let's do the top one

1:50:53

as that we'll do not collection i'll do the else and then we'll do this dot

1:51:02

collections well now let's turn this into a full if

1:51:32

is it is it collections on this yes

1:52:28

nope that's gonna have naming collision

1:52:42

there we go all right

1:52:50

so now if we do there we go now that's working

1:53:05

oh yeah it's still capitalization based all right

1:53:14

all right now it looks like next we need to do remove because that's not working that would make sense that we would need

1:53:20

to add that in there so uh let's see it should have its own remove

1:53:25

post call

1:53:30

so that should be easy enough we should just be able to pass the actual collection in so let's see here

1:53:37

remove post post and then if we're inside of a sub collection it

1:53:43

would be sub collection passed in as the second argument so if oops i had that selected

1:53:59

since that's directly what we're looping over you might just be able to delete it right off of there let's see

1:54:08

i don't know we'll see if it works

1:54:43

yeah that seems to be working

1:54:52

cool okay i didn't actually know if that would work but i guess that is being watched well

1:54:58

enough cool all right so let's give that a save and let's see if things auto-populate back

1:55:04

exactly as we have it here

1:55:12

no not quite so they both saved to the actual collection here and not to

1:55:20

that makes sense because the id's the same on both

1:55:29

so how do we want to name that so it's it's

1:55:36

uh where are we it's this right here causing an issue so they're all going into this post ids

1:55:41

array on the input field so ideally what we should be doing here

1:55:47

is separating them out somehow um and you need to separate them out by the

1:55:53

collection as well so let's see we definitely want these to

1:56:00

maintain post ids

1:56:14

put them inside of an object i don't know how you would do that with a form naming though

1:56:24

could do an array inside of the array i don't know how you do that either though um let's see

1:56:31

it's been a while html field nested array name

1:56:37

i don't know yeah something like that is that

1:56:43

possible indexes okay yeah i can do that

1:56:50

that's a-okay to me provide the id so we'll do that so um

1:57:00

now what i don't know is if we can mix and match like have these be we'll do

1:57:06

these different so we'll do collection sub collection post ids

1:57:12

and then we'll have these be the sub collection id and then that will be

1:57:17

a nested array okay i like that that sounds good so we'll do name

1:57:26

and then we need this instead of here so this will be

1:57:31

sub collection dot id then we need to add sub collection post

1:57:37

ids into the validator i don't i would assume that this is going

1:57:43

to be an array where this

1:57:49

the id is the index and then that's going to have an array inside of it so that might be a little

1:57:55

messy picking out i don't know we'll see how it works could be perfectly valid

1:58:00

i honestly don't think i've ever actually tried this before so let's see how how well it works so sub

1:58:09

collection post ids schema dot it's going to be an array

1:58:14

it's going to be optional it's going to have members of an array

1:58:21

so here let's drop that down so schema dot

1:58:27

array dot optional

1:58:46

and at this point we would be at the post id number

1:58:57

now i don't think this level would be optional because if you have yeah i think maybe we'll leave it there

1:59:03

rules dot exists

1:59:08

table posts column id okay

1:59:16

break this down too just so it's a little bit easier to see okay

1:59:24

i'm gonna just console.log that out and see exactly what we get so that's going to be on the update

1:59:35

so collection post ids then i'm also going to do

1:59:41

test and grab it off of the request as well

1:59:46

just in case the validation does fail at least this way we'll have an additional console log showing exactly what we're getting

1:59:52

um

1:59:57

is it input input's the one you're looking for input

2:00:06

okay so now that we have that let's drop a

2:00:12

console log right here we're not going to worry about persisting i just want to make sure that we're actually getting the data at this point in time so let's

2:00:17

do console.log sub collection post ids test

2:00:23

so we'll console log both of those out

2:00:29

and let's give it a test so

2:00:34

this one should not be on there well let's go ahead and refresh just to make sure we have the freshest data so we'll take that one off and we'll try putting

2:00:41

it back up here so test this is a test post

2:00:46

and let's try saving see what our console log looks like

2:00:52

the validation didn't fail um so sub collection post that uses an array of an array with one

2:00:59

and test is an array of an array with one so not quite what i'm looking for because

2:01:06

like it doesn't i don't

2:01:14

there's no real index um so like if i came into here

2:01:22

really the parent id is two and like how am i going to discern that

2:01:28

that is two based off of you know like that would be an index of zero so

2:01:39

uh let's see mr ivantic said hey there just wanted to pop in and say thank you for all the effort you are putting into this

2:01:45

really enjoying the series and content thank you so much i appreciate that um and

2:01:51

no problem at all with catching it on on demand later i just appreciate you guys support

2:01:58

um so i need to rethink this because that's not quite working how i wanted it to

2:02:03

work

2:02:08

so like if we could specify a specific id there

2:02:14

would be fantastic i think the way that we would want to do that is via an object

2:02:20

but i don't know if you can can you like you probably cannot replace that with

2:02:25

that i would imagine i've never seen that before so i wouldn't imagine that it would be a

2:02:31

thing

2:02:44

let's see yeah i'm

2:02:49

probably not going to get any good search results for this search um

2:02:57

let's see here

2:03:06

now we could alter it so that like it's

2:03:14

yeah let's do that so i'm overthinking it so let's take it back to that right

2:03:22

no let's take it back to this let's determine how you get the index in

2:03:27

alpine because i just i don't know how um i don't think it works like view where

2:03:34

it's the second argument if it is then

2:03:40

well that would be nice but oh it is okay great i'd

2:03:45

has it always been i used to think that it was more like angular right it had a specific key

2:03:51

okay so we'll get the index we'll keep the same approach we'll

2:03:56

replace the id with the actual index and then in

2:04:02

addition to that we'll do that twice so we'll do input type hidden

2:04:08

name

2:04:16

so that'll be the post

2:04:27

i don't know

2:04:48

okay let's try that see how that works so collection collection ids needs to be

2:04:54

added onto the validator it's going to be very similar to this

2:04:59

except for it's just going to be for collections and for the most part it's going to be

2:05:04

duplicated so let's see array optional array optional

2:05:10

number collections

2:05:15

id at well yeah the sub collections they will be created

2:05:22

um why are you red squiggly oh because the name's the same i didn't

2:05:27

change the name yet so subcollection collection ids okay let's give that a save

2:05:36

and let's um

2:05:44

post ids

2:05:58

okay so collection collection ids

2:06:03

oh duplicate name take an eye in front of it

2:06:09

i don't know it's all for testing so it doesn't matter anyway okay and then we need to extract

2:06:15

subcollection collection ids as well

2:06:28

and okay let's see if that works back into here back into there

2:06:37

and add this is a test post on to you and we get

2:06:43

in there literal not terminated before end of script my bad

2:06:52

which one is it this one yep okay

2:07:01

all right so let's give this a go so test okay let's try saving

2:07:09

okay what did we get so sub collection post id

2:07:15

has an id of one and then subcollection collection ids has an id of nine

2:07:24

so that's right the collection id is right

2:07:33

and then this is a test i think did have an id of one for the posts

2:07:41

yep so okay that might work um the

2:07:46

bad part is is then we're just looping over similar indexes so it's not as clean as i'd love it to be

2:07:52

but it'll it should should work okay um

2:07:59

so let's get rid of these console logs let's try persisting it see how we

2:08:05

how we get so we'll maintain the post ids for right now as the main collection posts and

2:08:11

then for each

2:08:17

do it over the post ids so um

2:08:24

four let i equal zero while i is less than sub

2:08:32

collection post ids i plus plus let's do

2:08:39

oh dot length my bad uh it's optional right so

2:08:55

ah yeah i get that it's possibly undefined

2:09:11

there we go okay all right so for each one of those we'll get the index and then we will loop over

2:09:17

it so const collection id equals

2:09:24

sub collection collection ids i and then const post id equals

2:09:32

sub collection post ids i and these are possibly nullable so we

2:09:39

will do a check so if not sub collection collection ids i or not

2:09:48

sub collection post ids i will get hopefully this will

2:09:55

will that make typescript happy no

2:10:04

there we go that does all right let's do that

2:10:09

uh that would be better to do outside

2:10:15

why do that for each loop when you can just do it once

2:10:24

and then we'll flip it okay

2:10:30

it should be all right to get rid of that since we are now checking to make sure that it exists

2:10:36

okay there we go took a big circle to get here but we're

2:10:41

here all right so now what we want to do um

2:10:48

is bind these together so we want to add the post to this collection so

2:10:56

um what's the most

2:11:03

best way that we could do this without querying the collection each and every time so we could group them

2:11:10

first before we loop based off of the collection that way all

2:11:15

we need to do is for each collection do a you know add many or whatever

2:11:21

or what um something like that or sync it to each collection as opposed to adding it for each collection each

2:11:27

post so let's do that um const

2:11:33

collections equals new set so let's get all of the unique

2:11:44

no

2:11:52

let's go ahead and just do let

2:12:00

collection post map equal an object

2:12:07

and then for each one of these let's do collection post map

2:12:14

collection id push post id

2:12:21

if not collection post map

2:12:27

collection id

2:12:36

then

2:12:44

all right why are you red oh wait you're a number

2:12:52

are you a number array

2:12:58

are you a number right you are a number how are you a number ran

2:13:09

all right let me take a look at the console log so

2:13:20

all right let's add in more to see what this looks like with more

2:13:26

um i'm gonna go back to where we have the console logs

2:13:43

right here okay and then let's dive into

2:13:49

here come back into that collection um

2:13:55

and let's add in yet another new collection it's going to have the same name it's a biggie we need to fix that

2:14:01

to where it reinitializes it whenever we actually add one in so refresh to actually make it initialized and let's

2:14:07

add a test post here and here

2:14:14

and then to this one we'll add two so um

2:14:20

okay so there we go so now we have two collections one with one and one with two so let's

2:14:27

take a look and see what those console logs look like okay

2:14:32

so that's exactly what i'm looking for yeah okay my mind just wasn't wrapping around

2:14:39

in the right place so we get the index there

2:14:45

which matches nine what nine and ten and then ten

2:14:52

nine in ten and then ten so those are already grouped right two one three

2:15:00

yeah so you just need to get the ones that have the same index they're already grouped so you take this index and then you take

2:15:06

this index now

2:15:26

nine and ten and three

2:15:51

what's got me confused is i was expecting to see 9 9 10.

2:16:09

because like the index should be the same

2:16:15

right

2:16:21

for the one that has like it's grouped in the same array no

2:16:27

maybe not so it was the second one that had two in it

2:16:34

the first one had one

2:16:53

three was on the second one

2:17:00

but the second one had two on it hmm

2:17:18

really

2:17:26

interesting okay let me try that one more time paying

2:17:32

more attention to what's going on so let's do

2:17:40

another test here i'm going to remove it completely from here

2:17:47

and let's do this is a test post there

2:17:52

and then we'll do asdf there

2:17:59

and then let's take a look at what actually is on here so we have our li

2:18:08

both of these have the index of zero on it

2:18:15

the value here is nine the value there is two

2:18:23

and here the index went up to one

2:18:31

but oh no we want the index to be up here

2:18:38

so let's do x and i don't think we'll need y but we'll put y right there so this would be x

2:18:46

x okay that's better so now let's try it out

2:18:52

let's see what's going on here make sure that this is right so

2:18:58

do that we'll get rid of you here and we'll do both of the test ones up there and then we'll do asdf right here

2:19:07

okay let's take a look at it now

2:19:12

so now it's zero zero with nine and two

2:19:17

and zero zero with nine and one so there we go now that would be posting up as

2:19:24

nine nine like i would it was expecting it to the first time and then we would have two one

2:19:30

now i don't think this needs to be a sub

2:19:37

array i think we can simplify that on ourselves by just getting rid of that all together

2:19:43

and allowing the index to do its thing there so we can manually define the index to

2:19:49

make sure that it's the same but i think i don't think we need that to

2:19:55

have a sub array on it so now if we post this up so let's try this

2:20:02

one more time so test and test

2:20:08

oh did i miss click i must have test and

2:20:14

asdf okay let's make sure that this is still looking right before we post it so

2:20:23

zero zero value nine nine um

2:20:29

in hindsight that could go outside of there too right like that doesn't need to be inside of this loop it should probably

2:20:36

be able to go up here

2:20:42

and it would still apply to it so that should be okay um

2:20:49

yeah okay so let's actually post it this time

2:20:55

so test another test test this is a test post and asdf

2:21:03

okay save and we don't have any anything actually saving but

2:21:09

we do get two one which the first one had two and

2:21:15

what the heck nine ten

2:21:21

still getting back the same freaking thing for that

2:21:31

no no oh something failed anyway oh yeah

2:21:38

because we removed the array from validation so that's probably the old

2:21:44

console log from before which would be why it would still be the same and then we just failed validation so we never

2:21:49

even got to the console logs because we removed the array

2:21:54

from this subcollection collection id so we just need to get rid of one layer of the

2:22:01

array okay so now let's try this one more time all

2:22:07

right so another test this is a test

2:22:14

and asdf okay and let's save that

2:22:20

okay that actually succeeded there we go that's more of what i want

2:22:25

index one on the collection gets us the array of two posts

2:22:30

index or sorry zero um and then index one gets us the array of one post

2:22:36

that's what i wanted so now

2:22:43

hopefully i didn't yeah good so we can go forward with this

2:22:50

back to where we were okay we shouldn't need to do the mapping

2:22:56

now because this is now working as we want okay so we get the collection id so this

2:23:03

should actually just be a string yeah or sorry a number and then this should be an array of number

2:23:10

or undefined yeah cool so instead of looping over the posts

2:23:17

we'd want to loop over the collections since if we loop over the posts we would be querying the collection more than

2:23:23

once and applying the collection update more than once but if we do it off of the collection

2:23:30

where things are defined only once then we can grab the post array and sync

2:23:36

using the entire array of the posts so sub collection

2:23:43

collectionids.length okay and then we would do const collection

2:23:50

equals a weight and then actually we can simplify that not simplify but we can make this even

2:23:57

more efficient by taking it out of a for loop and into

2:24:02

something else and maintaining just uh promises so that they run in parallel instead of in a serious fashion

2:24:10

so we'll do that here in a second but let's get these saving first so const collection

2:24:15

[Music] equals find or fail

2:24:21

by the collection id

2:24:27

and then we would want to await collection dot related

2:24:33

posts dot sync and then we're going to want to do the in the sort order here

2:24:41

so this will be a little bit different um trying to remember exactly so i think it's an object

2:24:48

and we're going to want to actually um loop over them for that so

2:24:54

this would not be a single post id but rather post ids

2:25:01

okay and then let's do const post

2:25:08

sync data equals post ids reduce

2:25:16

previous current index

2:25:22

start this off as an object okay and then let's return

2:25:28

an object spreading the previous where the

2:25:35

current because no current we would yeah current

2:25:42

and then it would be another object with sort order of i

2:25:49

so we can simplify this actually by getting rid of that and wrapping it

2:25:54

in this there we go okay

2:26:00

so what that ends up looking like is um here let me do a multi-line comment um something like this so we'll have an

2:26:07

object where the post id is here and then within there it has sort

2:26:14

order zero and then this one would be another one oops sorry

2:26:20

then we have another one with two with sort order of one so that's kind of what

2:26:26

we're doing so these are the post ids and then we save it with the intermediary table data that we need to save as the object off of the post id

2:26:34

so that's what we're doing here that's what we're building with this reduce so then all we should need to do is pass

2:26:39

and post sync data into u something with null i bet

2:26:45

argument object or undefined is not assignable to a parameter of type string or number

2:27:06

i'm doing the same kind of thing over here so let me take a look real quick oh no it's in the sink assets

2:27:16

yeah that looks the same

2:27:24

it's it's okay it's the fact that i remember now it's the fact that this is knowledge

2:27:29

um that should fix it there we go okay

2:27:38

so i think that should now persist things um let's give it a try

2:27:43

oh before we do that let's clean this up so we can make this run in um parallel

2:27:48

instead of in a series as it's doing now because now it's going to loop over it's going to await right here the finder

2:27:55

fail and then it's going to await the sync as well and then it will move on to the next one

2:28:00

and then it will wait again and then we'll move on to the next one but we can make it to where it can kind of run these all in parallel

2:28:08

you know instead of awaiting and then going to the next one by using promises so

2:28:15

since we don't need to get any particular data back from this this will be a relatively easy switch so we'll do

2:28:21

[Music] sub collection collection ids

2:28:27

dot map okay and then within here we'll just

2:28:32

loop over it so this would be the collection id

2:28:39

and then inside of here all we need to do is take that stuff there we need to change this

2:28:45

into an async function

2:28:50

and

2:28:55

we need to return a new promise

2:29:02

we'll take resolve and then we can pop this in here

2:29:08

and then at the end of this map we'll have const promises

2:29:15

and then we need to just call resolve once we reach the end of that

2:29:20

uh oh no this is the one that needs to be async sorry

2:29:26

you don't need to be and then you are now back to the issue to where you can be nullable because we

2:29:32

don't have a check on you so we'll do if

2:29:40

well we can wrap this whole thing up an if and then this will be a prime candidate to move off into a service

2:29:45

so if not sub collection post ids

2:29:52

if yeah no there we go okay and then why is resolve not happy

2:29:59

because it accepts an argument we don't really need to pass anything into it so we'll just pass true

2:30:06

and then down at the bottom of our if we'll do weight promise dot

2:30:13

what is it all are all settled

2:30:18

i think it's all i don't remember the difference and then we'll just await those promises

2:30:24

no argument of type promise unknown or

2:30:31

undefined is not assignable to a parameter of type iterable unknown

2:30:42

sorry about much here um oh okay

2:31:04

there we go when in doubt always assume it's an issue with it being nullable

2:31:11

okay so then we don't need this if at all so we can get rid of that uh now let's test it

2:31:21

so we'll come back into here nothing would have saved with the previous because we were just console.logging out so let's go ahead and actually do it now

2:31:27

so let's put both of the tests on this first one

2:31:32

okay and then we'll put asdf on the second okay so let's go ahead and hit save

2:31:40

wow that bombed that that did a hard bomb i is not defined

2:31:48

isn't it no it isn't is it my bad there we go

2:31:53

let's make i happen again there we go now i is in there

2:32:04

and test

2:32:10

test and asdf

2:32:17

all right that no errors so that seems good

2:32:22

um see if it pre-populates back with that and it does

2:32:28

fan flipping tastic

2:32:35

so outside of the stream i'll worry about making this prettier you guys don't need to sit around for

2:32:40

that but let's go ahead and test the additional crud of it so if we remove another test post from

2:32:46

this first collection let's see whether or not that persists

2:32:52

it does if we add it on to this one

2:32:57

let's see if that persists it does

2:33:03

and then the next thing to really do is to merge these posts

2:33:09

somehow into the collection of these collections

2:33:14

i don't know how the best way to go about that would be so i need to think on that

2:33:20

um and then apart from that once we get that working we would want to do drag and drop so that you can reorder stuff

2:33:27

which that shouldn't take too much time once we have this all in a similar in a single array type fashion

2:33:38

um so yeah

2:33:43

that should what are we going on here

2:33:48

about two and a half hours so i think that we'll call it there for today

2:33:53

and we will progress onward in the next stream and i will have an answer

2:33:59

for how we want to approach merging the parent collections posts

2:34:04

with the child collections because we should be able to do you know a post and then a collection

2:34:11

and then a post in the collection uh i'm a little bit baffled by that

2:34:17

right now i'm sure there's an easy way to do it but i need to play around with it and get a clear head around it so

2:34:23

uh thank you all for stopping by watching and for all of your support as always um and i'll see you guys the next

2:34:29

one have a great week

Join The Discussion! (0 Comments)

Please sign in or sign up for free to join in on the dicussion.

robot comment bubble

Be the first to Comment!