From 7b488ab198f2c0444478ad21a67fcf401f6a4531 Mon Sep 17 00:00:00 2001
From: Megha-Dev-19 <100185149+Megha-Dev-19@users.noreply.github.com>
Date: Mon, 27 Nov 2023 08:06:37 +0530
Subject: [PATCH] Ft: Autocomplete widget added (#502)
* add autocomplete widget
* fix following info
---
.../molecule/AccountAutocomplete.jsx | 143 ++++++++++++++++++
src/devhub/entity/post/PostEditor.jsx | 2 +-
src/devhub/page/create.jsx | 2 +-
3 files changed, 145 insertions(+), 2 deletions(-)
create mode 100644 src/devhub/components/molecule/AccountAutocomplete.jsx
diff --git a/src/devhub/components/molecule/AccountAutocomplete.jsx b/src/devhub/components/molecule/AccountAutocomplete.jsx
new file mode 100644
index 000000000..f205550df
--- /dev/null
+++ b/src/devhub/components/molecule/AccountAutocomplete.jsx
@@ -0,0 +1,143 @@
+if (!context.accountId || !props.term) return <>>;
+
+let results = [];
+const profilesData = Social.get("*/profile/name", "final") || {};
+const followingData = Social.get(
+ `${context.accountId}/graph/follow/**`,
+ "final"
+);
+if (!profilesData) return <>>;
+const profiles = Object.entries(profilesData);
+const term = (props.term || "").replace(/\W/g, "").toLowerCase();
+const limit = 5;
+
+for (let i = 0; i < profiles.length; i++) {
+ let score = 0;
+ const accountId = profiles[i][0];
+ const accountIdSearch = profiles[i][0].replace(/\W/g, "").toLowerCase();
+ const nameSearch = (profiles[i][1]?.profile?.name || "")
+ .replace(/\W/g, "")
+ .toLowerCase();
+ const accountIdSearchIndex = accountIdSearch.indexOf(term);
+ const nameSearchIndex = nameSearch.indexOf(term);
+
+ if (accountIdSearchIndex > -1 || nameSearchIndex > -1) {
+ score += 10;
+
+ if (accountIdSearchIndex === 0) {
+ score += 10;
+ }
+ if (nameSearchIndex === 0) {
+ score += 10;
+ }
+ if (followingData[accountId] === "") {
+ score += 30;
+ }
+
+ results.push({
+ accountId,
+ score,
+ });
+ }
+}
+
+results.sort((a, b) => b.score - a.score);
+results = results.slice(0, limit);
+
+function onResultClick(id) {
+ props.onSelect && props.onSelect(id);
+}
+
+const Wrapper = styled.div`
+ position: relative;
+ background: #eceef0;
+
+ &::before {
+ content: "";
+ display: block;
+ position: absolute;
+ right: 0;
+ width: 6px;
+ height: 100%;
+ background: linear-gradient(
+ to left,
+ rgba(236, 238, 240, 1),
+ rgba(236, 238, 240, 0)
+ );
+ z-index: 10;
+ }
+`;
+
+const Scroller = styled.div`
+ position: relative;
+ display: flex;
+ padding: 6px;
+ gap: 6px;
+ overflow: auto;
+ scroll-behavior: smooth;
+ align-items: center;
+ scrollbar-width: none;
+ -ms-overflow-style: none;
+ &::-webkit-scrollbar {
+ display: none;
+ }
+
+ > * {
+ max-width: 175px;
+ flex-grow: 0;
+ flex-shrink: 0;
+
+ button {
+ border: 1px solid #eceef0;
+ background: #fff !important;
+ border-radius: 6px;
+ padding: 3px 6px;
+ transition: all 200ms;
+
+ &:focus,
+ &:hover {
+ border-color: #687076;
+ }
+ }
+ }
+`;
+
+const CloseButton = styled.button`
+ background: none;
+ border: none;
+ display: block;
+ padding: 12px;
+ color #687076;
+ transition: all 200ms;
+
+ &:hover {
+ color: #000;
+ }
+`;
+
+if (results.length === 0) return <>>;
+
+return (
+
+
+
+
+
+
+ {results.map((result) => {
+ return (
+
+ );
+ })}
+
+
+);
diff --git a/src/devhub/entity/post/PostEditor.jsx b/src/devhub/entity/post/PostEditor.jsx
index 489f75fda..af094a82c 100644
--- a/src/devhub/entity/post/PostEditor.jsx
+++ b/src/devhub/entity/post/PostEditor.jsx
@@ -379,7 +379,7 @@ const callDescriptionDiv = () => {
{autocompleteEnabled && state.showAccountAutocomplete && (