Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #82 from Code4Nepal/bug-fixes
Browse files Browse the repository at this point in the history
Fix issues in the frontend
  • Loading branch information
tux4 authored Oct 15, 2019
2 parents 77f1d7d + 62bda47 commit 46ef056
Show file tree
Hide file tree
Showing 30 changed files with 23,948 additions and 13,833 deletions.
9 changes: 8 additions & 1 deletion parijat-frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"presets": ["env"]
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry"
}
]
]
}
10 changes: 10 additions & 0 deletions parijat-frontend/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { configure } from '@storybook/preact';

function loadStories() {
require('../stories/components/SearchBox.js');
require('../stories/components/TransliteratedInput.js');
require('../stories/components/Logo.js');
// You can require as many stories as you need.
}

configure(loadStories, module);
29 changes: 29 additions & 0 deletions parijat-frontend/.storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This is a deprecated way, and you should see a warning when starting storybook
// But only Allah knows what's up. I spent an entire day in webpack hell and gave up.
module.exports = {
module: {
rules: [
{
test: /\.css$/,
loaders: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
}
],
},
],
},
resolve: {
alias: {
'react': 'preact-compat',
'react-dom': 'preact-compat',
}
},
}

28,215 changes: 17,589 additions & 10,626 deletions parijat-frontend/package-lock.json

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions parijat-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "MIT",
"scripts": {
"start": "if-env NODE_ENV=production && npm run -s serve || npm run -s dev",
"storybook": "start-storybook",
"build": "NODE_ENV=production preact build",
"serve": "yarn serve:gen-config && superstatic --port 8080 --host 0.0.0.0",
"serve:gen-config": "preact serve --server config --dest superstatic.json",
Expand All @@ -25,20 +26,22 @@
"build/*"
],
"devDependencies": {
"babel-polyfill": "^6.26.0",
"babel-register": "^6.26.0",
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"@babel/register": "^7.4.0",
"@storybook/preact": "^5.0.4",
"core-js": "3",
"eslint": "^4.5.0",
"eslint-config-synacor": "^1.1.0",
"expect": "^23.1.0",
"if-env": "^1.0.0",
"mocha": "^5.2.0",
"preact-cli": "^2.0.0",
"preact-cli": "^3.0.0-next.19",
"superstatic": "^5.0.1"
},
"dependencies": {
"babel-preset-env": "^1.7.0",
"lodash": "^4.17.5",
"preact": "^8.2.1",
"preact": "^8.5.2",
"preact-compat": "^3.17.0",
"preact-material-components": "^1.4.0",
"preact-router": "^2.5.5",
Expand Down
11 changes: 11 additions & 0 deletions parijat-frontend/src/components/CurrentQuery/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { h } from 'preact';
import { SearchkitComponent } from 'searchkit';

export default class CurrentQuery extends SearchkitComponent {
render() {
const queryString = decodeURI(this.getQuery().index.queryString);
return queryString !== '' ? (
<div>"{queryString}" को नतिजा</div>
) : null;
}
}
124 changes: 93 additions & 31 deletions parijat-frontend/src/components/filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@ import { h, Component } from 'preact';
import Icon from 'preact-material-components/Icon';
import Dialog from 'preact-material-components/Dialog';
import 'preact-material-components/Dialog/style.css';
import Checkbox from 'preact-material-components/Checkbox';
import 'preact-material-components/Checkbox/style.css';
const map = require('lodash/map');
import TransliteratedInput from '../transliteratedinput';
const omitBy = require('lodash/omitBy');
const isUndefined = require('lodash/isUndefined');
import Button from '../button';
import debounce from 'lodash/debounce';
import {
RefinementListFilter,
FacetFilter,
FacetAccessor,
FilterBucket,
TermsBucket,
CardinalityMetric
CardinalityMetric,
RefinementListFilter
} from 'searchkit';
import style from './style';

/* This is disgusting code. We need our own state management. Searchkit abstractions are not very good */

class SearchableFacetAccessor extends FacetAccessor {
setSearchValue(searchValue) {
this.searchValue = searchValue;
performSearch = debounce(() => {
this.searchkit.performSearch();
}, 200);

setSearchValue(searchValue) {
this.searchValue = searchValue;
this.performSearch();
}

buildOwnQuery(query) {
Expand Down Expand Up @@ -63,7 +67,7 @@ class SearchableFacetAccessor extends FacetAccessor {
}
}

class SearchableRefinementListFilter extends FacetFilter {
class SearchableFacetFilter extends FacetFilter {
getAccessorOptions() {
const {
field,
Expand Down Expand Up @@ -130,8 +134,8 @@ class FiltersListInput extends Component {
<div className={style.FiltersListInput__Container}>
{editable ? (
<div className={style.FiltersListInput__Editable}>
<input
autoFocus
<TransliteratedInput
autofocus
placeholder={`${title}`}
value={this.props.searchValue}
onInput={this.props.onInput}
Expand All @@ -150,7 +154,7 @@ class FiltersListInput extends Component {
className={style.FiltersListInput__Button}
onClick={this.showEdit}
>
<Icon>filter_list</Icon>
<Icon>search</Icon>
</button>
</div>
)}
Expand All @@ -159,44 +163,102 @@ class FiltersListInput extends Component {
}
}

class FiltersList extends Component {
class SearchableRefinementListFilter extends Component {
state = {
searchValue: ''
};

onSearchValueChange(evnt) {
this.setState({
searchValue: evnt.target.value
});
onSearchValueChange = (event) => {
this.setSearchValue(event.target.value);
}

clearSearchValue = () => {
this.setSearchValue('');
}

clearSearchValue() {
this.setState({ searchValue: '' });
setSearchValue = (searchValue) => {
this.setState({ searchValue });
}

render() {
return (
<ul className={style.FiltersList__Container}>
<div>
<FiltersListInput
searchValue={this.state.searchValue}
onInput={this.onSearchValueChange.bind(this)}
clearSearchValue={this.clearSearchValue.bind(this)}
title="लेखक"
onInput={this.onSearchValueChange}
clearSearchValue={this.clearSearchValue}
title={this.props.title}
/>
<SearchableRefinementListFilter
id="author"
size={7}
title="लेखक"
field="author.keyword"
operator="OR"
<SearchableFacetFilter
id={this.props.id}
size={this.props.size}
title={this.props.title}
field={this.props.field}
operator={this.props.operator}
searchValue={this.state.searchValue}
itemComponent={RefinementOption}
/>
</ul>
</div>
);
}
}

function StandardRefinementListFilter({ field, title, id, operator, itemComponent, size }) {
return (
<div>
<div
className={style.StandardRefinementListFilter__Title}
>
<strong>{title}</strong>
</div>
<RefinementListFilter
field={field}
title={title}
id={id}
operator={operator}
itemComponent={itemComponent}
size={size}
/>
</div>
);
}

function FiltersList() {
return (
<ul className={style.FiltersList__Container}>
<li className={style.FiltersList__Section}>
<StandardRefinementListFilter
field="lang"
title="भाषा"
id="lang"
operator="OR"
itemComponent={RefinementOption}
size={7}
/>
</li>
<li className={style.FiltersList__Section}>
<StandardRefinementListFilter
field="genre"
title="विधा"
id="genre"
operator="OR"
itemComponent={RefinementOption}
size={7}
/>
</li>
<li className={style.FiltersList__Section}>
<SearchableRefinementListFilter
field="author.keyword"
title="लेखक"
id="author"
operator="OR"
size={7}
/>
</li>
</ul>
);
}

const RefinementOption = props => (
<div>
<span onClick={props.onClick} className={style.RefinementOption__Container}>
Expand All @@ -219,19 +281,19 @@ class Filters extends Component {
this.scrollingDlg.MDComponent.show();
}}
>
Filters
खोज सुधार
</Button>
<Dialog
ref={scrollingDlg => {
this.scrollingDlg = scrollingDlg;
}}
>
<Dialog.Header>Select Filters</Dialog.Header>
<Dialog.Header>खोज सुधार</Dialog.Header>
<Dialog.Body scrollable>
<FiltersList />
</Dialog.Body>
<Dialog.Footer>
<Dialog.FooterButton cancel>Close</Dialog.FooterButton>
<Dialog.FooterButton cancel>बन्द गर्नुहोस्</Dialog.FooterButton>
</Dialog.Footer>
</Dialog>
</div>
Expand Down
32 changes: 29 additions & 3 deletions parijat-frontend/src/components/filters/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
.FiltersList__Container {
margin: 0;
padding: 0;
list-style: none;
}

.Filters__Container {
Expand All @@ -28,6 +29,7 @@

.FiltersListInput__Container {
display: flex;
height: 2rem;
}

.FiltersListInput__Editable {
Expand All @@ -47,14 +49,38 @@
.FiltersListInput__NonEditable {
display: flex;
width: 100%;
padding-left: 14px;
justify-content: space-between;
align-items: center;
}

.FiltersListInput__Button {
background: none;
border: none;
width: 3rem;
height: 3rem;
width: 2rem;
height: 2rem;
line-height: 0rem;
}

.FiltersList__Section {
margin-bottom: 2rem;
}

/* SearchableRefinementListFilter */

.SearchableRefinementListFilter {

}

.StandardRefinementListFilter {

}

.StandardRefinementListFilter__Title {
display: flex;
align-items: center;
height: 2rem;
padding-left: 15px;
}

/* To swith to a button view when in small screens */
Expand All @@ -70,4 +96,4 @@
display: none;
width: 100%;
}
}
}
Loading

0 comments on commit 46ef056

Please sign in to comment.