Improved the helpers package.

This commit is contained in:
Simon Sarasova 2024-08-11 12:31:40 +00:00
parent 60ee8afb6c
commit 1f30bfa71c
No known key found for this signature in database
GPG key ID: EEDA4103C9C36944
13 changed files with 24 additions and 46 deletions

View file

@ -9,4 +9,4 @@ Many other people have written code for modules which are imported by Seekia. Th
Name | Date Of First Commit | Number Of Commits
--- | --- | ---
Simon Sarasova | June 13, 2023 | 276
Simon Sarasova | June 13, 2023 | 277

View file

@ -2451,7 +2451,7 @@ func setBuildMateProfilePage_Tags(window fyne.Window, previousPage func()){
deleteButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newList, deletedAny := helpers.DeleteAllMatchingItemsFromStringList(myTagsList, tagName)
newList, deletedAny := helpers.DeleteAllMatchingItemsFromList(myTagsList, tagName)
if (deletedAny == false){
setErrorEncounteredPage(window, errors.New("Cannot delete tag: tag not found."), currentPage)
return

View file

@ -2445,7 +2445,7 @@ func setBuildMateProfilePage_EyeColor(window fyne.Window, previousPage func()){
getNewAttributeList := func()[]string{
if (newChoice == false){
newList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentEyeColorList, colorName)
newList, _ := helpers.DeleteAllMatchingItemsFromList(currentEyeColorList, colorName)
return newList
}
@ -2613,7 +2613,7 @@ func setBuildMateProfilePage_HairColor(window fyne.Window, previousPage func()){
getNewAttributeList := func()[]string{
if (newChoice == false){
newList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentHairColorList, colorName)
newList, _ := helpers.DeleteAllMatchingItemsFromList(currentHairColorList, colorName)
return newList
}

View file

@ -482,7 +482,7 @@ func setAddContactFromIdentityHashPage(window fyne.Window, userIdentityHash [16]
newContactCategoriesList := helpers.AddItemToStringListAndAvoidDuplicate(currentContactCategoriesList, categoryName)
contactCategoriesListBinding.Set(newContactCategoriesList)
} else {
newContactCategoriesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentContactCategoriesList, categoryName)
newContactCategoriesList, _ := helpers.DeleteAllMatchingItemsFromList(currentContactCategoriesList, categoryName)
contactCategoriesListBinding.Set(newContactCategoriesList)
}
}
@ -785,8 +785,8 @@ func setEditContactCategoriesPage(window fyne.Window, contactIdentityHash [16]by
newCategoriesList := append(currentContactCategoriesList, categoryName)
return newCategoriesList
}
newCategoriesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentContactCategoriesList, categoryName)
newCategoriesList, _ := helpers.DeleteAllMatchingItemsFromList(currentContactCategoriesList, categoryName)
return newCategoriesList
}

View file

@ -275,7 +275,7 @@ func setChooseDesiresPage_ProfileLanguage(window fyne.Window, previousPage func(
deleteLanguageButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredLanguagesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, languageIdentifierBase64)
newDesiredLanguagesList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, languageIdentifierBase64)
if (len(newDesiredLanguagesList) == 0){
@ -499,7 +499,7 @@ func setChooseDesiresPage_Country(window fyne.Window, previousPage func()){
deleteCountryButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredCountriesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, countryIdentifierBase64)
newDesiredCountriesList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, countryIdentifierBase64)
if (len(newDesiredCountriesList) == 0){
@ -805,7 +805,7 @@ func setChooseDesiresPage_SearchTerms(window fyne.Window, previousPage func()){
deleteTermButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredTermsList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, termNameBase64)
newDesiredTermsList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, termNameBase64)
if (len(newDesiredTermsList) == 0){
@ -1287,7 +1287,7 @@ func getDesireEditor_Choice(window fyne.Window, currentPage func(), desireName s
return emptyList
}
newAttributeList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, "Other")
newAttributeList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, "Other")
return newAttributeList
}

View file

@ -109,7 +109,7 @@ func setChooseDesiresPage_Language(window fyne.Window, previousPage func()){
if (response == false){
newList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, "Other")
newList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, "Other")
return newList
}
@ -195,7 +195,8 @@ func setChooseDesiresPage_Language(window fyne.Window, previousPage func()){
languageNameLabel := getBoldLabelCentered(translate(languageName))
deleteLanguageButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredLanguagesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, languageNameBase64)
newDesiredLanguagesList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, languageNameBase64)
if (len(newDesiredLanguagesList) == 0){

View file

@ -1305,7 +1305,7 @@ func setChooseDesiresPage_23andMe_Haplogroup(window fyne.Window, maternalOrPater
return emptyList
}
newAttributeList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, "Other")
newAttributeList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, "Other")
return newAttributeList
}
@ -1393,7 +1393,7 @@ func setChooseDesiresPage_23andMe_Haplogroup(window fyne.Window, maternalOrPater
deleteHaplogroupButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredHaplogroupsList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, haplogroupNameBase64)
newDesiredHaplogroupsList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, haplogroupNameBase64)
if (len(newDesiredHaplogroupsList) == 0){

View file

@ -1329,7 +1329,7 @@ func setCreateCouplePage(window fyne.Window, previousPage func()){
return
}
newList, deletedAny := helpers.DeleteAllMatchingItemsFromStringList(existingList, personIdentifier)
newList, deletedAny := helpers.DeleteAllMatchingItemsFromList(existingList, personIdentifier)
if (deletedAny == false){
setErrorEncounteredPage(window, errors.New("Person not found when trying to delete person from chosen people list."), currentPage)
return

View file

@ -762,7 +762,7 @@ func setBrowseMatchesPage(window fyne.Window, previousPage func()){
currentAttributesList := strings.Split(currentAttributesListString, ",")
displayAttributesListPruned, _ := helpers.DeleteAllMatchingItemsFromStringList(currentAttributesList, currentSortByAttribute)
displayAttributesListPruned, _ := helpers.DeleteAllMatchingItemsFromList(currentAttributesList, currentSortByAttribute)
newDisplayAttributesList := []string{currentSortByAttribute}
@ -1390,7 +1390,7 @@ func setCustomizeMatchDisplayPage(window fyne.Window, previousPage func()){
deleteAttributeButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newAttributesList, _ := helpers.DeleteAllMatchingItemsFromStringList(customDisplayAttributesList, attributeName)
newAttributesList, _ := helpers.DeleteAllMatchingItemsFromList(customDisplayAttributesList, attributeName)
if (len(newAttributesList) == 0){

View file

@ -1098,34 +1098,11 @@ func DeleteIndexFromStringList(inputList []string, indexToDelete int)([]string,
//Outputs:
// -[]string: New list
// -bool: Deleted any items
func DeleteAllMatchingItemsFromStringList(inputList []string, itemToDelete string)([]string, bool){
func DeleteAllMatchingItemsFromList[E comparable](inputList []E, itemToDelete E)([]E, bool){
listCopy := slices.Clone(inputList)
deletionFunction := func(input string)bool{
if (input == itemToDelete){
return true
}
return false
}
newList := slices.DeleteFunc(listCopy, deletionFunction)
if (len(newList) == len(inputList)){
return newList, false
}
return newList, true
}
//Outputs:
// -[]string: New list
// -bool: Deleted any items
func DeleteAllMatchingItemsFromProfileHashList(inputList [][28]byte, itemToDelete [28]byte)([][28]byte, bool){
listCopy := slices.Clone(inputList)
deletionFunction := func(input [28]byte)bool{
deletionFunction := func(input E)bool{
if (input == itemToDelete){
return true
}

View file

@ -776,7 +776,7 @@ func GetProfileVerdictMaps(profileHash [28]byte, profileNetworkType byte, integr
}
// We can omit the current profileHash, because we are already checking it
attributeProfileHashesList, _ := helpers.DeleteAllMatchingItemsFromProfileHashList(attributeProfilesList, profileHash)
attributeProfileHashesList, _ := helpers.DeleteAllMatchingItemsFromList(attributeProfilesList, profileHash)
return attributeProfileHashesList, nil
}

View file

@ -467,7 +467,7 @@ func DeleteContactCategory(identityType string, categoryToDeleteName string)erro
contactCategoriesListBase64 := strings.Split(contactCategoriesListString, "+")
newCategoriesList, deletedAny := helpers.DeleteAllMatchingItemsFromStringList(contactCategoriesListBase64, categoryToDeleteNameBase64)
newCategoriesList, deletedAny := helpers.DeleteAllMatchingItemsFromList(contactCategoriesListBase64, categoryToDeleteNameBase64)
if (deletedAny == false){
newContactsMapList = append(newContactsMapList, contactMap)
continue

View file

@ -163,7 +163,7 @@ func (listObject *MyList) DeleteListItem(item string)error{
currentList := listObject.memoryList
newList, anyDeleted := helpers.DeleteAllMatchingItemsFromStringList(currentList, item)
newList, anyDeleted := helpers.DeleteAllMatchingItemsFromList(currentList, item)
if (anyDeleted == false){
listObject.memoryMutex.Unlock()
return nil