From dfd300c3583e3446c7484dd5f455817de6f87603 Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Wed, 7 Apr 2021 09:21:22 +0530 Subject: [PATCH] Fix library search --- src/database/DBHelper.js | 13 +------------ src/database/tables/UpdateTable.js | 4 ---- src/redux/library/library.actions.js | 8 ++++++-- src/redux/library/library.reducer.js | 10 ++++++++-- src/redux/library/library.types.js | 1 + src/screens/Library/Library.js | 6 ++++-- src/services/updates.js | 1 + 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/database/DBHelper.js b/src/database/DBHelper.js index 228ef643..fc27b286 100644 --- a/src/database/DBHelper.js +++ b/src/database/DBHelper.js @@ -33,18 +33,7 @@ export const createDB = () => { tx.executeSql(createChapterTableQuery); tx.executeSql(createHistoryTableQuery); tx.executeSql(createDownloadTableQuery); - tx.executeSql( - createUpdatesTableQuery, - null, - (txObj, res) => {}, - (txObj, error) => console.log("Error ", error) - ); - // tx.executeSql( - // updatesSeedDataQuery, - // null, - // (txObj, res) => {}, - // (txObj, error) => console.log("Error ", error) - // ); + tx.executeSql(createUpdatesTableQuery); //Db indexes tx.executeSql(createUrlIndexQuery); diff --git a/src/database/tables/UpdateTable.js b/src/database/tables/UpdateTable.js index b11d7886..c3944ea4 100644 --- a/src/database/tables/UpdateTable.js +++ b/src/database/tables/UpdateTable.js @@ -9,7 +9,3 @@ export const createUpdatesTableQuery = ` FOREIGN KEY (novelId) REFERENCES novels(novelId) ON DELETE CASCADE )`; - -export const updatesSeedDataQuery = ` - INSERT INTO updates (chapterId, novelId) VALUES (55,2), (421,2), (345,2) - `; diff --git a/src/redux/library/library.actions.js b/src/redux/library/library.actions.js index 97eb6379..028142f7 100644 --- a/src/redux/library/library.actions.js +++ b/src/redux/library/library.actions.js @@ -1,4 +1,7 @@ -import { GET_LIBRARY_NOVELS } from "./library.types"; +import { + GET_LIBRARY_NOVELS, + GET_LIBRARY_SEARCH_RESULTS, +} from "./library.types"; import { getLibrary, searchLibrary, @@ -15,9 +18,10 @@ export const getLibraryAction = () => async (dispatch) => { export const searchLibraryAction = (searchText) => async (dispatch) => { const res = await searchLibrary(searchText); + console.log(searchText); dispatch({ - type: GET_LIBRARY_NOVELS, + type: GET_LIBRARY_SEARCH_RESULTS, payload: res, }); }; diff --git a/src/redux/library/library.reducer.js b/src/redux/library/library.reducer.js index 05a2ed0a..0005b540 100644 --- a/src/redux/library/library.reducer.js +++ b/src/redux/library/library.reducer.js @@ -1,8 +1,12 @@ import { FOLLOW_NOVEL, UNFOLLOW_NOVEL } from "../novel/novel.types"; -import { GET_LIBRARY_NOVELS } from "./library.types"; +import { + GET_LIBRARY_NOVELS, + GET_LIBRARY_SEARCH_RESULTS, +} from "./library.types"; const initialState = { novels: [], + searchResults: [], loading: true, }; @@ -11,7 +15,9 @@ const libraryReducer = (state = initialState, action) => { switch (type) { case GET_LIBRARY_NOVELS: - return { novels: payload, loading: false }; + return { ...state, novels: payload, loading: false }; + case GET_LIBRARY_SEARCH_RESULTS: + return { ...state, searchResults: payload, loading: false }; case FOLLOW_NOVEL: return { ...state, diff --git a/src/redux/library/library.types.js b/src/redux/library/library.types.js index 4c579f50..92ec60e5 100644 --- a/src/redux/library/library.types.js +++ b/src/redux/library/library.types.js @@ -1 +1,2 @@ export const GET_LIBRARY_NOVELS = "GET_LIBRARY_NOVELS"; +export const GET_LIBRARY_SEARCH_RESULTS = "GET_LIBRARY_SEARCH_RESULTS"; diff --git a/src/screens/Library/Library.js b/src/screens/Library/Library.js index 11297b58..c2a2481d 100644 --- a/src/screens/Library/Library.js +++ b/src/screens/Library/Library.js @@ -30,6 +30,7 @@ const LibraryScreen = ({ getLibraryAction, searchLibraryAction, setNovel, + searchResults, itemsPerRow, }) => { const [refreshing, setRefreshing] = useState(false); @@ -65,7 +66,7 @@ const LibraryScreen = ({ > item.novelUrl} renderItem={({ item }) => ( ({ theme: state.themeReducer.theme, itemsPerRow: state.settingsReducer.itemsPerRow, novels: state.libraryReducer.novels, + searchResults: state.libraryReducer.searchResults, loading: state.libraryReducer.loading, }); diff --git a/src/services/updates.js b/src/services/updates.js index bfe68e35..644cec93 100644 --- a/src/services/updates.js +++ b/src/services/updates.js @@ -41,6 +41,7 @@ export const updateNovel = async (extensionId, novelUrl, novelId) => { ], (txObj, { insertId }) => { if (insertId !== -1) { + console.log(insertId); tx.executeSql( "INSERT OR IGNORE INTO updates (chapterId, novelId, updateTime) values (?, ?, (datetime('now','localtime')))", [insertId, novelId],