Fix library search

This commit is contained in:
Rajarshee Chatterjee
2021-04-07 09:21:22 +05:30
parent 76c108597d
commit dfd300c358
7 changed files with 21 additions and 22 deletions
+1 -12
View File
@@ -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);
-4
View File
@@ -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)
`;
+6 -2
View File
@@ -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,
});
};
+8 -2
View File
@@ -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,
+1
View File
@@ -1 +1,2 @@
export const GET_LIBRARY_NOVELS = "GET_LIBRARY_NOVELS";
export const GET_LIBRARY_SEARCH_RESULTS = "GET_LIBRARY_SEARCH_RESULTS";
+4 -2
View File
@@ -30,6 +30,7 @@ const LibraryScreen = ({
getLibraryAction,
searchLibraryAction,
setNovel,
searchResults,
itemsPerRow,
}) => {
const [refreshing, setRefreshing] = useState(false);
@@ -65,7 +66,7 @@ const LibraryScreen = ({
>
<SearchAppbar
screen="Library"
placeholder="Search Library (Broken)"
placeholder="Search Library"
getNovels={getLibraryAction}
getSearchResults={searchLibraryAction}
searchText={searchText}
@@ -84,7 +85,7 @@ const LibraryScreen = ({
}}
numColumns={itemsPerRow}
key={itemsPerRow}
data={novels}
data={!searchText ? novels : searchResults}
keyExtractor={(item) => item.novelUrl}
renderItem={({ item }) => (
<NovelCover
@@ -128,6 +129,7 @@ const mapStateToProps = (state) => ({
theme: state.themeReducer.theme,
itemsPerRow: state.settingsReducer.itemsPerRow,
novels: state.libraryReducer.novels,
searchResults: state.libraryReducer.searchResults,
loading: state.libraryReducer.loading,
});
+1
View File
@@ -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],