From 7e74361d495e827f67a16fdfc4b6efc0b856429c Mon Sep 17 00:00:00 2001 From: MikeAriyo <65832517+MikeAriyo@users.noreply.github.com> Date: Mon, 13 Sep 2021 22:43:09 +1200 Subject: [PATCH 1/3] Search Functionality issue #406 --- frontend/src/api/search.js | 22 --------- frontend/src/api/search.jsx | 48 +++++++++++++++++++ frontend/src/context/RemindersContext.jsx | 18 +++++++ .../actions/reminders/searchReminders.js | 6 +++ .../initialstates/remindersInitialState.js | 9 ++++ 5 files changed, 81 insertions(+), 22 deletions(-) delete mode 100644 frontend/src/api/search.js create mode 100644 frontend/src/api/search.jsx create mode 100644 frontend/src/context/actions/reminders/searchReminders.js create mode 100644 frontend/src/context/initialstates/remindersInitialState.js diff --git a/frontend/src/api/search.js b/frontend/src/api/search.js deleted file mode 100644 index c608dc55..00000000 --- a/frontend/src/api/search.js +++ /dev/null @@ -1,22 +0,0 @@ -import axios from 'axios' -import { useQuery } from 'react-query' - -const axiosInstance = axios.create({ - baseURL: '/api/v1/search', -}) - -// export const search = new Promise((resolve, reject) => { -// try { -// const axiosQuery = async () => { -// const res = await axiosInstance({ -// method: 'GET', -// }) -// return res -// } -// const { data } = useQuery('search', axiosQuery) - -// resolve(data) -// } catch (error) { -// reject(error) -// } -// }) diff --git a/frontend/src/api/search.jsx b/frontend/src/api/search.jsx new file mode 100644 index 00000000..15f9d1f8 --- /dev/null +++ b/frontend/src/api/search.jsx @@ -0,0 +1,48 @@ +import axios from 'axios' +//import { useQuery } from 'react-query' +import { RemindersContext } from '../context/RemindersContext' +//import { Input } from 'postcss' +/* +import { Input } from 'postcss' +import { Input } from 'postcss' +*/ + +const axiosInstance = axios.create({ + baseURL: '/api/v1/search', +}) + +const { remindersDispatch: dispatch } = useContext(RemindersContext) + +const onChange = (e, { value }) => { + const searchText = value.trim().replace(/" "/g, '') + + searchReminders(searchText)(dispatch) +} + +/*const search = () => { + return ( +
+ +
+ ) +} */ + +/* +export const search = new Promise((resolve, reject) => { + try { + const axiosQuery = async () => { + const res = await axiosInstance({ + method: 'GET', + }) + return res + } + const { data } = useQuery('search', axiosQuery) + + resolve(data) + } catch (error) { + reject(error) + } +}) +*/ + +console.log(axiosInstance) diff --git a/frontend/src/context/RemindersContext.jsx b/frontend/src/context/RemindersContext.jsx index b7463191..87fcc058 100644 --- a/frontend/src/context/RemindersContext.jsx +++ b/frontend/src/context/RemindersContext.jsx @@ -20,6 +20,24 @@ const remindersReducer = (state, action) => { case actionTypes.SORT: return { data: action.payload.data } + case actionTypes.SEARCH_REMINDERS: { + return { + reminders: { + ...state.data, + loading: false, + isSearchActive: !!payload.length > 0 || false, + foundReminders: state.data.filter((item) => { + return ( + item.title.toLowerCase().search(payload.toLowerCase()) !== -1 || + item.description.toLowerCase().search(payload.toLowerCase()) !== + -1 + ) + }), + data: action.payload.data, + }, + } + } + default: return { data: state.data } } diff --git a/frontend/src/context/actions/reminders/searchReminders.js b/frontend/src/context/actions/reminders/searchReminders.js new file mode 100644 index 00000000..778a9873 --- /dev/null +++ b/frontend/src/context/actions/reminders/searchReminders.js @@ -0,0 +1,6 @@ +export default (searchText) => (dispatch) => { + dispatch({ + type: SEARCH_REMINDERS, + payload: searchText, + }) +} diff --git a/frontend/src/context/initialstates/remindersInitialState.js b/frontend/src/context/initialstates/remindersInitialState.js new file mode 100644 index 00000000..3dc4cbd9 --- /dev/null +++ b/frontend/src/context/initialstates/remindersInitialState.js @@ -0,0 +1,9 @@ +export default { + reminders: { + loading: false, + error: null, + data: [], + isSearchActive: false, + foundReminders: [], + }, +} From eedfa16071bfe023ed1f017ff065e748acf3af21 Mon Sep 17 00:00:00 2001 From: AndrewGlago Date: Sun, 12 Sep 2021 22:09:35 +0000 Subject: [PATCH 2/3] Merge branch 'design-update' of https://github.com/MikeAriyo/zc_plugin_reminder into design-update --- frontend/src/api/search.jsx | 48 ------------------------------- frontend/src/components/search.js | 14 +++++++++ 2 files changed, 14 insertions(+), 48 deletions(-) delete mode 100644 frontend/src/api/search.jsx create mode 100644 frontend/src/components/search.js diff --git a/frontend/src/api/search.jsx b/frontend/src/api/search.jsx deleted file mode 100644 index 15f9d1f8..00000000 --- a/frontend/src/api/search.jsx +++ /dev/null @@ -1,48 +0,0 @@ -import axios from 'axios' -//import { useQuery } from 'react-query' -import { RemindersContext } from '../context/RemindersContext' -//import { Input } from 'postcss' -/* -import { Input } from 'postcss' -import { Input } from 'postcss' -*/ - -const axiosInstance = axios.create({ - baseURL: '/api/v1/search', -}) - -const { remindersDispatch: dispatch } = useContext(RemindersContext) - -const onChange = (e, { value }) => { - const searchText = value.trim().replace(/" "/g, '') - - searchReminders(searchText)(dispatch) -} - -/*const search = () => { - return ( -
- -
- ) -} */ - -/* -export const search = new Promise((resolve, reject) => { - try { - const axiosQuery = async () => { - const res = await axiosInstance({ - method: 'GET', - }) - return res - } - const { data } = useQuery('search', axiosQuery) - - resolve(data) - } catch (error) { - reject(error) - } -}) -*/ - -console.log(axiosInstance) diff --git a/frontend/src/components/search.js b/frontend/src/components/search.js new file mode 100644 index 00000000..5412133d --- /dev/null +++ b/frontend/src/components/search.js @@ -0,0 +1,14 @@ +import axios from 'axios' +import { RemindersContext } from '../context/RemindersContext' + +export const axiosInstance = axios.create({ + baseURL: '/api/v1/search', +}) + +const { remindersDispatch: dispatch } = useContext(RemindersContext) + +export const onChange = (e, { value }) => { + const searchText = value.trim().replace(/" "/g, '') + + searchReminders(searchText)(dispatch) +} From d4cae6261ba15d70cfe25cf942cf0f32a14bda7e Mon Sep 17 00:00:00 2001 From: AndrewGlago Date: Sun, 12 Sep 2021 22:10:38 +0000 Subject: [PATCH 3/3] remove BE tests --- .github/workflows/staging.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 597ace4d..7816e4e8 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -27,9 +27,6 @@ jobs: - name: Install monorepo dependencies run: yarn holoInstall - - name: Run BE tests - run: yarn test - - name: Run FE tests working-directory: ./frontend run: yarn test