fixes thumbnail bug
This commit is contained in:
20
db/main.go
20
db/main.go
@@ -60,10 +60,10 @@ func setupEventHandlers(app *pocketbase.PocketBase, client meilisearch.ServiceMa
|
|||||||
app.OnModelAfterCreate("users").Add(createUserHandler(app, client))
|
app.OnModelAfterCreate("users").Add(createUserHandler(app, client))
|
||||||
|
|
||||||
app.OnModelAfterCreate("trails").Add(createTrailIndexHandler(app, client))
|
app.OnModelAfterCreate("trails").Add(createTrailIndexHandler(app, client))
|
||||||
|
app.OnModelAfterUpdate("trails").Add(updateTrailIndexHandler(app, client))
|
||||||
|
app.OnModelAfterDelete("trails").Add(deleteTrailIndexHandler(client))
|
||||||
|
|
||||||
app.OnRecordAfterCreateRequest("trails").Add(createTrailHandler(app))
|
app.OnRecordAfterCreateRequest("trails").Add(createTrailHandler(app))
|
||||||
app.OnRecordAfterUpdateRequest("trails").Add(updateTrailHandler(app, client))
|
|
||||||
app.OnRecordAfterDeleteRequest("trails").Add(deleteTrailHandler(client))
|
|
||||||
|
|
||||||
app.OnRecordAfterCreateRequest("trail_share").Add(createTrailShareHandler(app, client))
|
app.OnRecordAfterCreateRequest("trail_share").Add(createTrailShareHandler(app, client))
|
||||||
app.OnRecordAfterDeleteRequest("trail_share").Add(deleteTrailShareHandler(client))
|
app.OnRecordAfterDeleteRequest("trail_share").Add(deleteTrailShareHandler(client))
|
||||||
@@ -160,19 +160,21 @@ func createTrailHandler(app *pocketbase.PocketBase) func(e *core.RecordCreateEve
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateTrailHandler(app *pocketbase.PocketBase, client meilisearch.ServiceManager) func(e *core.RecordUpdateEvent) error {
|
func updateTrailIndexHandler(app *pocketbase.PocketBase, client meilisearch.ServiceManager) func(e *core.ModelEvent) error {
|
||||||
return func(e *core.RecordUpdateEvent) error {
|
return func(e *core.ModelEvent) error {
|
||||||
author, err := app.Dao().FindRecordById("users", e.Record.GetString(("author")))
|
record := e.Model.(*models.Record)
|
||||||
|
author, err := app.Dao().FindRecordById("users", record.GetString(("author")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return util.UpdateTrail(e.Record, author, client)
|
return util.UpdateTrail(record, author, client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteTrailHandler(client meilisearch.ServiceManager) func(e *core.RecordDeleteEvent) error {
|
func deleteTrailIndexHandler(client meilisearch.ServiceManager) func(e *core.ModelEvent) error {
|
||||||
return func(e *core.RecordDeleteEvent) error {
|
return func(e *core.ModelEvent) error {
|
||||||
_, err := client.Index("trails").DeleteDocument(e.Record.Id)
|
record := e.Model.(*models.Record)
|
||||||
|
_, err := client.Index("trails").DeleteDocument(record.Id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ func documentFromTrailRecord(r *models.Record, author *models.Record, includeSha
|
|||||||
photos := r.GetStringSlice("photos")
|
photos := r.GetStringSlice("photos")
|
||||||
thumbnail := ""
|
thumbnail := ""
|
||||||
if len(photos) > 0 {
|
if len(photos) > 0 {
|
||||||
thumbnail = r.GetStringSlice("photos")[r.GetInt("thumbnail")]
|
thumbnailIndex := r.GetInt("thumbnail")
|
||||||
|
if thumbnailIndex >= len(photos) {
|
||||||
|
thumbnailIndex = 0
|
||||||
|
}
|
||||||
|
thumbnail = photos[thumbnailIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
document := map[string]interface{}{
|
document := map[string]interface{}{
|
||||||
|
|||||||
@@ -202,7 +202,8 @@
|
|||||||
);
|
);
|
||||||
setFields(updatedTrail);
|
setFields(updatedTrail);
|
||||||
}
|
}
|
||||||
|
photoFiles = []
|
||||||
|
|
||||||
savedAtLeastOnce = true;
|
savedAtLeastOnce = true;
|
||||||
show_toast({
|
show_toast({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
|||||||
Reference in New Issue
Block a user