Added keyboard shortcuts for post editing.
This commit is contained in:
parent
4f7058bf36
commit
44d35c6ccb
13 changed files with 215 additions and 28 deletions
|
|
@ -2,6 +2,7 @@ package posts
|
|||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"lmika.dev/lmika/weiro/models"
|
||||
|
|
@ -9,12 +10,13 @@ import (
|
|||
)
|
||||
|
||||
type CreatePostParams struct {
|
||||
GUID string `form:"guid" json:"guid"`
|
||||
Title string `form:"title" json:"title"`
|
||||
Body string `form:"body" json:"body"`
|
||||
GUID string `form:"guid" json:"guid"`
|
||||
Title string `form:"title" json:"title"`
|
||||
Body string `form:"body" json:"body"`
|
||||
Action string `form:"action" json:"action"`
|
||||
}
|
||||
|
||||
func (s *Service) PublishPost(ctx context.Context, params CreatePostParams) (*models.Post, error) {
|
||||
func (s *Service) UpdatePost(ctx context.Context, params CreatePostParams) (*models.Post, error) {
|
||||
site, ok := models.GetSite(ctx)
|
||||
if !ok {
|
||||
return nil, models.SiteRequiredError
|
||||
|
|
@ -27,14 +29,28 @@ func (s *Service) PublishPost(ctx context.Context, params CreatePostParams) (*mo
|
|||
|
||||
post.Title = params.Title
|
||||
post.Body = params.Body
|
||||
post.PublishedAt = time.Now()
|
||||
post.UpdatedAt = time.Now()
|
||||
post.Slug = post.BestSlug()
|
||||
oldState := post.State
|
||||
|
||||
switch strings.ToLower(params.Action) {
|
||||
case "publish":
|
||||
post.State = models.StatePublished
|
||||
post.PublishedAt = time.Now()
|
||||
case "save draft":
|
||||
post.State = models.StateDraft
|
||||
post.PublishedAt = time.Time{}
|
||||
default:
|
||||
// Leave unchanged
|
||||
}
|
||||
|
||||
if err := s.db.SavePost(ctx, post); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.publisher.Queue(site)
|
||||
if oldState != post.State || post.State == models.StatePublished {
|
||||
s.publisher.Queue(site)
|
||||
}
|
||||
|
||||
return post, nil
|
||||
}
|
||||
|
|
@ -56,6 +72,7 @@ func (s *Service) fetchOrCreatePost(ctx context.Context, site models.Site, param
|
|||
GUID: params.GUID,
|
||||
Title: params.Title,
|
||||
Body: params.Body,
|
||||
State: models.StateDraft,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
return post, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue