Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

giphy: Add clear search button.

Aman Agrawal35bd44ed2a37
diff --git a/static/js/giphy.js b/static/js/giphy.js
index 82ac4940abf..132cfca314e 100644
--- a/static/js/giphy.js
+++ b/static/js/giphy.js
@@ -14,6 +14,7 @@ import * as ui_util from "./ui_util";
const giphy_fetch = new GiphyFetch(page_params.giphy_api_key);
let search_term = "";
+let gifs_grid;
let active_popover_element;
// Only used if popover called from edit message, otherwise it is `undefined`.
@@ -101,15 +102,22 @@ function renderGIPHYGrid(targetEl) {
}
function update_grid_with_search_term() {
+ if (!gifs_grid) {
+ return;
+ }
+
const search_elem = $("#giphy-search-query");
// GIPHY popover may have been hidden by the
// time this function is called.
if (search_elem.length) {
search_term = search_elem[0].value;
- return renderGIPHYGrid($("#giphy_grid_in_popover .popover-content")[0]);
+ gifs_grid.remove();
+ gifs_grid = renderGIPHYGrid($("#giphy_grid_in_popover .popover-content")[0]);
+ return;
}
- // Return undefined to stop searching.
- return undefined;
+
+ // Set to undefined to stop searching.
+ gifs_grid = undefined;
}
export function hide_giphy_popover() {
@@ -155,6 +163,12 @@ export function initialize() {
$("body").on("keydown", ".giphy-gif", ui_util.convert_enter_to_click);
$("body").on("keydown", ".compose_giphy_logo", ui_util.convert_enter_to_click);
+ $("body").on("click", "#giphy_search_clear", (e) => {
+ e.stopPropagation();
+ $("#giphy-search-query").val("");
+ update_grid_with_search_term();
+ });
+
$("body").on("click", ".compose_giphy_logo", (e) => {
e.preventDefault();
e.stopPropagation();
@@ -181,7 +195,7 @@ export function initialize() {
});
active_popover_element.popover("show");
- let gifs_grid = renderGIPHYGrid($("#giphy_grid_in_popover .popover-content")[0]);
+ gifs_grid = renderGIPHYGrid($("#giphy_grid_in_popover .popover-content")[0]);
$("body").on(
"keyup",
@@ -190,14 +204,7 @@ export function initialize() {
// every search. This makes the UX of searching pleasant
// by allowing user to finish typing before search
// is executed.
- _.debounce(() => {
- // GIPHY popover may have been hidden by the
- // time this function is called.
- if (gifs_grid) {
- gifs_grid.remove();
- gifs_grid = update_grid_with_search_term();
- }
- }, 300),
+ _.debounce(update_grid_with_search_term, 300),
);
$(document).one("compose_canceled.zulip compose_finished.zulip", () => {
diff --git a/static/styles/popovers.css b/static/styles/popovers.css
index 44e44548c3a..423bd2b9c2b 100644
--- a/static/styles/popovers.css
+++ b/static/styles/popovers.css
@@ -473,12 +473,26 @@ ul {
.search-box {
display: flex;
position: sticky;
+ padding: 2px;
input {
flex-grow: 1;
margin: 5px;
border-radius: 3px;
}
+
+ .clear_search_button {
+ position: absolute;
+ top: 5px;
+ right: 3px;
+ font-size: 16px;
+
+ &:focus {
+ .fa-remove {
+ outline: 2px solid hsl(215, 47%, 50%);
+ }
+ }
+ }
}
.popover-content {
diff --git a/static/templates/giphy_picker.hbs b/static/templates/giphy_picker.hbs
index ecd5601cc79..6c6bf309b3e 100644
--- a/static/templates/giphy_picker.hbs
+++ b/static/templates/giphy_picker.hbs
@@ -3,6 +3,9 @@
<div class="popover-inner">
<div class="search-box">
<input type="text" tabindex=0 id="giphy-search-query" class="search-query" placeholder="{{t 'Search GIFs' }}">
+ <button type="button" class="btn clear_search_button" id="giphy_search_clear">
+ <i class="fa fa-remove" aria-hidden="true"></i>
+ </button>
</div>
<div class="popover-content"></div>
<div class="popover-footer">