From ef416d3e86e89bd856eead37fd9479a432ce8cda Mon Sep 17 00:00:00 2001
From: Dan Brown <ssddanbrown@googlemail.com>
Date: Sat, 4 Apr 2020 00:09:58 +0100
Subject: [PATCH] Fixed editor JavaScript error in TemplateManager

- Caused when loading the editor with no templates in the system.
- Tried to init a search box that did not exist.
---
 resources/js/components/template-manager.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/resources/js/components/template-manager.js b/resources/js/components/template-manager.js
index d004a4307..f8b19a40c 100644
--- a/resources/js/components/template-manager.js
+++ b/resources/js/components/template-manager.js
@@ -56,6 +56,10 @@ class TemplateManager {
 
     setupSearchBox() {
         const searchBox = this.elem.querySelector('.search-box');
+
+        // Search box may not exist if there are no existing templates in the system.
+        if (!searchBox) return;
+
         const input = searchBox.querySelector('input');
         const submitButton = searchBox.querySelector('button');
         const cancelButton = searchBox.querySelector('button.search-box-cancel');
@@ -70,7 +74,7 @@ class TemplateManager {
         }
         performSearch = performSearch.bind(this);
 
-        // Searchbox enter press
+        // Search box enter press
         searchBox.addEventListener('keypress', event => {
             if (event.key === 'Enter') {
                 event.preventDefault();