Fix library search
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
`;
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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 +1,2 @@
|
||||
export const GET_LIBRARY_NOVELS = "GET_LIBRARY_NOVELS";
|
||||
export const GET_LIBRARY_SEARCH_RESULTS = "GET_LIBRARY_SEARCH_RESULTS";
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user