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 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/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) +} 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: [], + }, +}