diff --git a/hyphae/categories/categories.go b/hyphae/categories/categories.go index b03561d..d46cc93 100644 --- a/hyphae/categories/categories.go +++ b/hyphae/categories/categories.go @@ -60,5 +60,12 @@ func AddHyphaToCategory(hyphaName, catName string) { // RemoveHyphaFromCategory removes the hypha from the category and updates the records on the disk. If the hypha is not in the category, nothing happens. func RemoveHyphaFromCategory(hyphaName, catName string) { mutex.Lock() + if node, ok := hyphaToCategories[hyphaName]; ok { + node.removeCategory(catName) + } + + if node, ok := categoryToHyphae[catName]; ok { + node.removeHypha(hyphaName) + } mutex.Unlock() } diff --git a/hyphae/categories/files.go b/hyphae/categories/files.go index 9064cb4..0cf17a7 100644 --- a/hyphae/categories/files.go +++ b/hyphae/categories/files.go @@ -58,6 +58,15 @@ func (cn *categoryNode) storeHypha(hypname string) { cn.hyphaList = append(cn.hyphaList, hypname) } +func (cn *categoryNode) removeHypha(hypname string) { + for i, hyphaName := range cn.hyphaList { + if hyphaName == hypname { + cn.hyphaList[i] = cn.hyphaList[len(cn.hyphaList)-1] + cn.hyphaList = cn.hyphaList[:len(cn.hyphaList)-1] + } + } +} + type hyphaNode struct { // TODO: ensure this is sorted categoryList []string @@ -72,6 +81,15 @@ func (hn *hyphaNode) storeCategory(cat string) { hn.categoryList = append(hn.categoryList, cat) } +func (hn *hyphaNode) removeCategory(cat string) { + for i, category := range hn.categoryList { + if category == cat { + hn.categoryList[i] = hn.categoryList[len(hn.categoryList)-1] + hn.categoryList = hn.categoryList[:len(hn.categoryList)-1] + } + } +} + type catFileRecord struct { Categories []catRecord `json:"categories"` } diff --git a/views/categories.html b/views/categories.html index 7f7f999..67364c7 100644 --- a/views/categories.html +++ b/views/categories.html @@ -9,14 +9,16 @@
{{end}}