194 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			194 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
package views
 | 
						|
 | 
						|
import "fmt"
 | 
						|
import "git.32bit.cafe/32bitcafe/guestbook/internal/models"
 | 
						|
import "git.32bit.cafe/32bitcafe/guestbook/internal/forms"
 | 
						|
 | 
						|
func gbUrl(gb models.Guestbook) string {
 | 
						|
    return fmt.Sprintf("/guestbooks/%s", gb.Slug())
 | 
						|
}
 | 
						|
 | 
						|
templ gbCreateForm(csrf_token string) {
 | 
						|
    <input type="hidden" name="csrf_token" value={ csrf_token }>
 | 
						|
    <label for="siteurl">Site URL: </label>
 | 
						|
    <input type="text" name="siteurl" id="siteurl" required />
 | 
						|
    <button type="submit">Submit</button>
 | 
						|
}
 | 
						|
 | 
						|
templ gbList(guestbooks []models.Guestbook) {
 | 
						|
    if len(guestbooks) == 0 {
 | 
						|
        <p>No Guestbooks yet</p>
 | 
						|
    } else {
 | 
						|
        <ul id="guestbooks" hx-get="/guestbooks" hx-trigger="newGuestbook from:body" hx-swap="outerHTML">
 | 
						|
            for _, gb := range guestbooks {
 | 
						|
                <li><a href={ templ.URL(gbUrl(gb) + "/dashboard") }>
 | 
						|
                    if len(gb.SiteUrl) == 0 {
 | 
						|
                        Untitled
 | 
						|
                    } else {
 | 
						|
                        { gb.SiteUrl }
 | 
						|
                    }
 | 
						|
                </a></li>
 | 
						|
 | 
						|
            }
 | 
						|
        </ul>
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
templ GuestbookList(title string, data CommonData, guestbooks []models.Guestbook) {
 | 
						|
    if data.IsHtmx {
 | 
						|
        @gbList(guestbooks)
 | 
						|
    } else {
 | 
						|
        @base(title, data) {
 | 
						|
            <h1>My Guestbooks</h1>
 | 
						|
            <div>
 | 
						|
                <button hx-get="/guestbooks/create" hx-target="closest div">New Guestbook</button>
 | 
						|
            </div>
 | 
						|
            @gbList(guestbooks)
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
templ GuestbookCreate(title string, data CommonData) {
 | 
						|
    if data.IsHtmx {
 | 
						|
        <form hx-post="/guestbooks/create" hx-target="closest div">
 | 
						|
            @gbCreateForm(data.CSRFToken)
 | 
						|
        </form>
 | 
						|
    } else {
 | 
						|
        @base(title, data) {
 | 
						|
            <form action="/guestbooks/create" method="post">
 | 
						|
                @gbCreateForm(data.CSRFToken)
 | 
						|
            </form>
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
templ sidebar(guestbook models.Guestbook) {
 | 
						|
    {{ dashUrl := gbUrl(guestbook) + "/dashboard" }}
 | 
						|
    <nav>
 | 
						|
        <div>
 | 
						|
            <a href={ templ.URL(gbUrl(guestbook)) } target="_blank">View Guestbook</a>
 | 
						|
            <h3>Messages</h3>
 | 
						|
            <ul>
 | 
						|
                <li><a href={ templ.URL(dashUrl) }>Dashboard</a></li>
 | 
						|
                <li><a href={ templ.URL(dashUrl + "/comments") }>Manage messages</a></li>
 | 
						|
                <li><a href={ templ.URL(dashUrl + "/comments/queue") }>Review message queue</a></li>
 | 
						|
                <li><a href={ templ.URL(dashUrl + "/blocklist") }>Block users</a></li>
 | 
						|
                <li><a href={ templ.URL(dashUrl + "/comments/trash") }>Trash</a></li>
 | 
						|
            </ul>
 | 
						|
        </div>
 | 
						|
        <div>
 | 
						|
            <h3>Design</h3>
 | 
						|
            <ul>
 | 
						|
                <li><a href={ templ.URL(dashUrl + "/themes") }>Themes</a></li>
 | 
						|
                <li><a href={ templ.URL(dashUrl + "/customize") }>Custom CSS</a></li>
 | 
						|
            </ul>
 | 
						|
        </div>
 | 
						|
        <div>
 | 
						|
            <h3>Account</h3>
 | 
						|
            <ul>
 | 
						|
                <li><a href="/users/settings">Settings</a></li>
 | 
						|
                <li><a href="/users/privacy">Privacy</a></li>
 | 
						|
                <li><a href="/help">Help</a></li>
 | 
						|
            </ul>
 | 
						|
        </div>
 | 
						|
    </nav>
 | 
						|
}
 | 
						|
 | 
						|
templ GuestbookDashboardView(title string, data CommonData, guestbook models.Guestbook, comments []models.GuestbookComment) {
 | 
						|
    @base(title, data) {
 | 
						|
        <div id="dashboard">
 | 
						|
            @sidebar(guestbook)
 | 
						|
            <div>
 | 
						|
                <h1>Guestbook for { guestbook.SiteUrl }</h1>
 | 
						|
                <p>Stats and stuff will go here</p>
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
templ GuestbookDashboardCommentsView(title string, data CommonData, guestbook models.Guestbook, comments []models.GuestbookComment) {
 | 
						|
    @base(title, data) {
 | 
						|
        <div id="dashboard">
 | 
						|
            @sidebar(guestbook)
 | 
						|
            <div>
 | 
						|
                <h1>Comments on { guestbook.SiteUrl }</h1>
 | 
						|
                if len(comments) == 0 {
 | 
						|
                    <p>No comments yet!</p>
 | 
						|
                }
 | 
						|
                for  _, c := range comments {
 | 
						|
                    <div>
 | 
						|
                        <strong>{ c.AuthorName }</strong>
 | 
						|
                        { c.Created.Format("01-02-2006 03:04PM") }
 | 
						|
                        <p>
 | 
						|
                            { c.CommentText }
 | 
						|
                        </p>
 | 
						|
                    </div>
 | 
						|
                }
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
templ commentForm(data CommonData, gb models.Guestbook, form forms.CommentCreateForm) {
 | 
						|
    {{ postUrl := fmt.Sprintf("/guestbooks/%s/comments/create", gb.Slug()) }}
 | 
						|
    <form action={ templ.URL(postUrl) } method="post">
 | 
						|
        <input type="hidden" name="csrf_token" value={data.CSRFToken}>
 | 
						|
        <div>
 | 
						|
            <label for="authorname">Name: </label>
 | 
						|
            {{ error, exists := form.FieldErrors["authorName"] }}
 | 
						|
            if exists {
 | 
						|
                <label class="error">{ error }</label>
 | 
						|
            }
 | 
						|
            <input type="text" name="authorname" id="authorname" >
 | 
						|
        </div>
 | 
						|
        <div>
 | 
						|
            <label for="authoremail">Email: </label>
 | 
						|
            {{ error, exists = form.FieldErrors["authorEmail"] }}
 | 
						|
            if exists {
 | 
						|
                <label class="error">{ error }</label>
 | 
						|
            }
 | 
						|
            <input type="text" name="authoremail" id="authoremail" >
 | 
						|
        </div>
 | 
						|
        <div>
 | 
						|
            <label for="authorsite">Site Url: </label>
 | 
						|
            {{ error, exists = form.FieldErrors["authorSite"] }}
 | 
						|
            if exists {
 | 
						|
                <label class="error">{ error }</label>
 | 
						|
            }
 | 
						|
            <input type="text" name="authorsite" id="authorsite" >
 | 
						|
        </div>
 | 
						|
        <div>
 | 
						|
            <label for="content">Comment: </label>
 | 
						|
            {{ error, exists = form.FieldErrors["content"] }}
 | 
						|
            if exists {
 | 
						|
                <label class="error">{ error }</label>
 | 
						|
            }
 | 
						|
            <textarea name="content" id="content"></textarea>
 | 
						|
        </div>
 | 
						|
        <div>
 | 
						|
            <input type="submit" value="Submit">
 | 
						|
        </div>
 | 
						|
    </form>
 | 
						|
    }
 | 
						|
 | 
						|
templ GuestbookView(title string, data CommonData, guestbook models.Guestbook, comments []models.GuestbookComment, form forms.CommentCreateForm) {
 | 
						|
        <div id="main">
 | 
						|
            <div>
 | 
						|
                <h1>Guestbook for { guestbook.SiteUrl }</h1>
 | 
						|
                @commentForm(data, guestbook, form)
 | 
						|
                if len(comments) == 0 {
 | 
						|
                    <p>No comments yet!</p>
 | 
						|
                }
 | 
						|
                for  _, c := range comments {
 | 
						|
                    <div>
 | 
						|
                        <strong>{ c.AuthorName }</strong>
 | 
						|
                        { c.Created.Format("01-02-2006 03:04PM") }
 | 
						|
                        <p>
 | 
						|
                            { c.CommentText }
 | 
						|
                        </p>
 | 
						|
                    </div>
 | 
						|
                }
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
}
 |