Skip to content

Commit

Permalink
[#25]feat: add new word to db
Browse files Browse the repository at this point in the history
  • Loading branch information
damla committed Apr 25, 2022
1 parent 7f8502f commit 9b12df5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useState } from 'react';
import { Icon } from '../../../../../common';
import { Icons } from '../../../../../common/Icon/Icon';
import { useSearch } from '../../../../../../hooks/useSearch';
Expand All @@ -9,6 +9,7 @@ interface Props {
col1: string;
col2: string;
search: string;
searchBy: string;
};
}

Expand All @@ -17,9 +18,9 @@ const enum Filter {
TO = 'TO',
}

const Search = ({ data: { col1, col2, search } }: Props) => {
const Search = ({ data: { col1, col2, search, searchBy } }: Props) => {
const [current, setCurrent] = useState(Filter.FROM);
const { data, dataLoading, query, addQuery } = useSearch();
const { query, addQuery } = useSearch();

useEffect(() => {
!dataLoading && console.log('hay amk:', data);
Expand All @@ -31,7 +32,7 @@ const Search = ({ data: { col1, col2, search } }: Props) => {
<div className="p-4">
<div className="mb-5 flex">
<h5 className="text-white text-base md:text-lg font-medium pr-3 md:pr-4">
Search by:
{searchBy}
</h5>
<button
type="button"
Expand Down
6 changes: 2 additions & 4 deletions src/components/layouts/Dashboard/modules/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ interface Props {
}

const Table = ({ data }: Props) => {
const { search, col1, col2, col3, col4, ...others } = data;
// const { transactions } = useEthTransactions({ offset: 0 });
// const [data, setData] = useState([]);
const { search, col1, col2, col3, col4, searchBy, ...others } = data;

return (
<div className="min-h-full max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
<div className="relative overflow-x-auto mb-5 shadow-lg sm:rounded-lg bg-gradient-to-r from-cyan-500 to-blue-500">
<Search data={{ col1, col2, search }} />
<Search data={{ col1, col2, search, searchBy }} />
<table className="w-full text-sm text-left text-gray-500">
<thead className="text-xs text-white uppercase">
<tr>
Expand Down
54 changes: 27 additions & 27 deletions src/context/Search/searchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const SearchContext = createContext<SearchContextType>(
);

export const SearchProvider = ({ children }: Props) => {
const { transactions } = useEthTransactions({ offset: 0 });
// const { transactions } = useEthTransactions({ offset: 0 });
const [query, setQuery] = useState<string>(searchContextDefaultValues.query);
const [dataLoading, setDataLoading] = useState(
searchContextDefaultValues.dataLoading
Expand Down Expand Up @@ -63,33 +63,33 @@ export const SearchProvider = ({ children }: Props) => {
// }, [transactions]);

//2
const searchInFrom = useCallback(
async (query: string) => {
setDataLoading(true);

if (transactions && transactions.result) {
const searchedTransactions = transactions?.result.filter(
(transaction) =>
transaction.from_address
.toLowerCase()
.includes(query.toLowerCase()) ||
transaction.from_address
.toLowerCase()
.replace(' ', '')
.includes(query.toLowerCase())
);
console.log('filtreli:', searchedTransactions);
setData(searchedTransactions);
setDataLoading(false);
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[transactions]
);
// const searchInFrom = useCallback(
// async (query: string) => {
// setDataLoading(true);

useEffect(() => {
searchInFrom(query);
}, [searchInFrom, query]);
// if (transactions && transactions.result) {
// const searchedTransactions = transactions?.result.filter(
// (transaction) =>
// transaction.from_address
// .toLowerCase()
// .includes(query.toLowerCase()) ||
// transaction.from_address
// .toLowerCase()
// .replace(' ', '')
// .includes(query.toLowerCase())
// );
// console.log('filtreli:', searchedTransactions);
// setData(searchedTransactions);
// setDataLoading(false);
// }
// },
// // eslint-disable-next-line react-hooks/exhaustive-deps
// [transactions]
// );

// useEffect(() => {
// searchInFrom(query);
// }, [searchInFrom, query]);

const addQuery = (q: string) => setQuery(q);

Expand Down
1 change: 1 addition & 0 deletions src/interfaces/pages/dashboard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ITable {
col3: string;
col4: string;
loading: string;
searchBy: string;
noDataInformation: string;
search: string;
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const pageData: Prisma.PageCreateInput[] = [
col3: 'DATE',
col4: 'AMOUNT',
loading: 'Loading...',
searchBy: 'Search by:',
noDataInformation: 'This address has no related transactions.',
search: 'Search for transaction',
},
Expand All @@ -72,6 +73,7 @@ const pageData: Prisma.PageCreateInput[] = [
col3: 'TARİH',
col4: 'MİKTAR',
loading: 'Yükleniyor...',
searchBy: 'Şuna göre ara:',
noDataInformation: 'Bu adres ile ilişkili işlem bulunmamaktadır.',
search: 'İşlem ara',
},
Expand Down

0 comments on commit 9b12df5

Please sign in to comment.