@@ -12,19 +12,23 @@ import { AstroObject } from "@/types";
1212import {
1313 fetchObjectListsDb ,
1414 fetchObjectListsNamesDb ,
15+ fetchObjectListByNameDb ,
1516 saveUserCurrentObjectListNameDb ,
1617} from "@/db/db_utils" ;
1718
1819type PropType = {
1920 objectFavoriteNames : string [ ] ;
2021 setObjectFavoriteNames : Dispatch < SetStateAction < string [ ] > > ;
22+ objectPersonalList : AstroObject [ ] ;
23+ setObjectPersonalList : Dispatch < SetStateAction < AstroObject [ ] > > ;
2124 setModule : Dispatch < SetStateAction < string | undefined > > ;
2225 setErrors : Dispatch < SetStateAction < string | undefined > > ;
2326 setSuccess : Dispatch < SetStateAction < string | undefined > > ;
2427} ;
2528
2629export default function GotoUserLists ( props : PropType ) {
2730 const { objectFavoriteNames, setObjectFavoriteNames } = props ;
31+ const { objectPersonalList, setObjectPersonalList } = props ;
2832 const { setModule, setErrors, setSuccess } = props ;
2933
3034 let connectionCtx = useContext ( ConnectionContext ) ;
@@ -35,21 +39,45 @@ export default function GotoUserLists(props: PropType) {
3539 } > ( { } ) ;
3640 const [ showImportModal , setShowImportModal ] = useState ( false ) ;
3741 const [ showDeleteModal , setShowDeleteModal ] = useState ( false ) ;
42+ const [ selectPersonalList , setSelectPersonalList ] = useState (
43+ connectionCtx . currentUserObjectListName === "personal"
44+ ) ;
45+
46+ useEffect ( ( ) => {
47+ try {
48+ // get objects lists from local storage on page load
49+ console . log ( "Load personalObjecList on load" ) ;
50+ let personalObjecList = fetchObjectListByNameDb ( "personal" ) ;
51+ if ( personalObjecList ) {
52+ setObjectPersonalList ( personalObjecList ) ;
53+ console . log (
54+ "Loaded personalObjecList on load: " ,
55+ personalObjecList . length
56+ ) ;
57+ } else {
58+ console . log ( "No personalObjecList found in DB" ) ;
59+ }
60+ } catch ( error ) {
61+ console . error ( "Error personalObjecList on load" , error ) ;
62+ }
63+ } , [ ] ) ;
3864
3965 useEffect ( ( ) => {
40- // get objects lists from local storage on page load
66+ // get objects lists from local storage personal list change
4167 let names = fetchObjectListsNamesDb ( ) ;
4268 if ( names ) {
4369 setObjectListsNames ( names ) ;
4470 }
4571 let lists = fetchObjectListsDb ( ) ;
72+ console . log ( "List Objects" , lists ) ;
4673 if ( lists ) {
4774 setObjectLists ( lists ) ;
4875 }
49- } , [ ] ) ;
76+ } , [ objectPersonalList ] ) ;
5077
5178 function selectListHandler ( e : ChangeEvent < HTMLSelectElement > ) {
5279 let listName = e . target . value ;
80+ setSelectPersonalList ( listName == "personal" ) ;
5381 connectionCtx . setUserCurrentObjectListName ( listName ) ;
5482 saveUserCurrentObjectListNameDb ( listName ) ;
5583 }
@@ -96,10 +124,15 @@ export default function GotoUserLists(props: PropType) {
96124 < div className = "col-md-4" >
97125 < select
98126 className = "form-select mb-2"
99- value = { connectionCtx . currentUserObjectListName || "default" }
127+ value = {
128+ connectionCtx . currentUserObjectListName ||
129+ "default" ||
130+ "personal"
131+ }
100132 onChange = { selectListHandler }
101133 >
102134 < option value = "default" > { t ( "cGoToListdefault" ) } </ option >
135+ < option value = "personal" > { t ( "cGoToListpersonal" ) } </ option >
103136 { objectListsNames . map ( ( list , index ) => (
104137 < option key = { index } value = { list } >
105138 { list }
@@ -115,12 +148,14 @@ export default function GotoUserLists(props: PropType) {
115148 >
116149 { t ( "cGoToUserListNewList" ) }
117150 </ button >
118- < button
119- className = "btn btn-more03 me-2 mb-2"
120- onClick = { deleteListModalHandle }
121- >
122- { t ( "cGoToUserListDeleteList" ) }
123- </ button >
151+ { ! selectPersonalList && (
152+ < button
153+ className = "btn btn-more03 me-2 mb-2"
154+ onClick = { deleteListModalHandle }
155+ >
156+ { t ( "cGoToUserListDeleteList" ) }
157+ </ button >
158+ ) }
124159 </ div >
125160 </ div >
126161
@@ -130,6 +165,9 @@ export default function GotoUserLists(props: PropType) {
130165 objects = { objectLists [ connectionCtx . currentUserObjectListName ] }
131166 objectFavoriteNames = { objectFavoriteNames }
132167 setObjectFavoriteNames = { setObjectFavoriteNames }
168+ objectPersonalList = { objectPersonalList }
169+ setObjectPersonalList = { setObjectPersonalList }
170+ isInObjectPersonalList = { selectPersonalList }
133171 setModule = { setModule }
134172 setErrors = { setErrors }
135173 setSuccess = { setSuccess }
0 commit comments