Skip to content

Commit 8e70636

Browse files
committed
fix filter display
1 parent e9880f0 commit 8e70636

File tree

4 files changed

+48
-65
lines changed

4 files changed

+48
-65
lines changed

src/components/contractors/Contractors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ class Contractors extends Component {
8787
const args = Object.assign({}, this.props.config.contractor_filter, {
8888
subject: selected_subject ? selected_subject.id : null,
8989
pagination: this.props.config.pagination,
90+
sort: this.props.config.sort_on,
9091
page: page,
9192
location: location_str,
9293
})
93-
console.log(args)
9494
const contractor_response = await this.props.root.requests.get('contractors', args)
9595
this.props.config.event_callback('updated_contractors', contractor_response)
9696
this.setState({contractor_response: {results: []}})
@@ -132,13 +132,13 @@ class Contractors extends Component {
132132
<If v={this.state.contractor_response}>
133133
<div className="tcs-filters-container">
134134
<LocationInput get_text={this.props.root.get_text}
135-
show={this.props.config.location_input}
135+
show={this.props.config.show_location_search}
136136
loc_raw={this.state.location_str}
137137
loc_change={this.location_change}
138138
submit={this.submit_location}/>
139139

140140
<SubjectSelect get_text={this.props.root.get_text}
141-
show={this.props.config.subject_filter}
141+
show={this.props.config.show_subject_filter}
142142
subjects={this.state.subjects}
143143
selected_subject={this.state.selected_subject}
144144
subject_change={this.subject_change}/>

src/components/contractors/Filters.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ export const SubjectSelect = ({get_text, show, subjects, selected_subject, subje
2222

2323
export const LocationInput = ({get_text, show, loc_raw, loc_change, submit}) => {
2424
return (
25-
<div className="tcs-contractor-filter tcs-location-filter">
25+
<div className="tcs-contractor-filter">
2626
<If v={show}>
27-
<input className="tcs-location-input"
28-
type="text"
29-
value={loc_raw || ''}
30-
onChange={v => loc_change(v.target.value || null)}
31-
onKeyPress={v => v.key === 'Enter' && submit()}
32-
placeholder={get_text('location_input_placeholder')}/>
33-
<span className="tcs-location-clear"
34-
style={{visibility: loc_raw === null ? 'hidden' : 'visible'}}
35-
onClick={() => loc_change(null) || submit(null)}>
36-
×
37-
</span>
27+
<div className="tcs-location-filter">
28+
<input className="tcs-location-input"
29+
type="text"
30+
value={loc_raw || ''}
31+
onChange={v => loc_change(v.target.value || null)}
32+
onKeyPress={v => v.key === 'Enter' && submit()}
33+
placeholder={get_text('location_input_placeholder')}/>
34+
<span className="tcs-location-clear"
35+
style={{visibility: loc_raw === null ? 'hidden' : 'visible'}}
36+
onClick={() => loc_change(null) || submit(null)}>
37+
×
38+
</span>
39+
</div>
3840
</If>
3941
</div>
4042
)

src/index.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@ window.socket = async function (public_key, config) {
6969
}
7070
}
7171

72-
let options_required = false
7372
let error = null
74-
if (!config.mode) {
75-
options_required = true
76-
} else if (MODES.indexOf(config.mode) === -1) {
73+
if (config.mode && MODES.indexOf(config.mode) === -1) {
7774
error = `invalid mode "${config.mode}", options are: ${MODES.join(', ')}`
7875
config.mode = 'grid'
7976
}
@@ -97,8 +94,6 @@ window.socket = async function (public_key, config) {
9794
// use history mode with enquiry so it doesn't add the hash
9895
if (config.mode === 'enquiry') {
9996
config.router_mode = 'history'
100-
} else {
101-
options_required = true
10297
}
10398
} else if (ROUTER_MODES.indexOf(config.router_mode) === -1) {
10499
error = `invalid router mode "${config.router_mode}", options are: ${ROUTER_MODES.join(', ')}`
@@ -119,14 +114,6 @@ window.socket = async function (public_key, config) {
119114
delete config.labels_exclude
120115
}
121116

122-
if (config.subject_filter === undefined) {
123-
config.subject_filter = true
124-
}
125-
126-
if (config.location_input === undefined) {
127-
config.location_input = true
128-
}
129-
130117
if (!config.event_callback) {
131118
config.event_callback = () => null
132119
}
@@ -137,7 +124,6 @@ window.socket = async function (public_key, config) {
137124
return
138125
}
139126

140-
config.pagination = config.pagination || 100
141127
config.messages = config.messages || {}
142128
for (let k of Object.keys(STRINGS)) {
143129
if (!config.messages[k]) {
@@ -147,20 +133,31 @@ window.socket = async function (public_key, config) {
147133
config.random_id = Math.random().toString(36).substring(2, 10)
148134
config.grecaptcha_key = process.env.REACT_APP_GRECAPTCHA_KEY
149135

150-
if (options_required) {
151-
let company_options
152-
try {
153-
company_options = await get_company_options(public_key, config)
154-
} catch(e) {
155-
error = e.toString()
156-
company_options = {
157-
display_mode: 'grid',
158-
router_mode: 'hash',
159-
}
136+
let company_options
137+
try {
138+
company_options = await get_company_options(public_key, config)
139+
} catch(e) {
140+
error = e.toString()
141+
// these are the default values
142+
company_options = {
143+
display_mode: 'grid',
144+
pagination: 100,
145+
router_mode: 'hash',
146+
show_hours_reviewed: true,
147+
show_labels: true,
148+
show_location_search: true,
149+
show_stars: true,
150+
show_subject_filter: true,
151+
sort_on: 'name',
152+
}
153+
}
154+
155+
company_options.mode = company_options.display_mode
156+
console.debug('company options:', company_options)
157+
for (let [k, v] of Object.entries(company_options)) {
158+
if (config[k] === undefined) {
159+
config[k] = v
160160
}
161-
console.debug('company options:', company_options)
162-
config.mode = config.mode || company_options.display_mode
163-
config.router_mode = config.router_mode || company_options.router_mode
164161
}
165162

166163
console.debug('using config:', config)

src/styles/contractor-filters.scss

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,25 @@
1414
background: darken($brand-colour, 10%);
1515
}
1616

17-
//.cross {
18-
// position: absolute;
19-
// top: 1px;
20-
// right: 1px;
21-
// margin: 5px 4px;
22-
// padding: 4px 4px;
23-
// cursor: pointer;
24-
// z-index: 10;
25-
// svg.tcs-svg {
26-
// transition: all .4s ease;
27-
// opacity: 0.5;
28-
// width: 18px;
29-
// height: 18px;
30-
// }
31-
// &:hover {
32-
// svg.tcs-svg {
33-
// opacity: 1;
34-
// }
35-
// }
36-
//}
37-
3817
.tcs-filters-container {
3918
display: flex;
4019
}
4120

4221
.tcs-contractor-filter {
4322
width: 50%;
44-
padding: 0 2px;
4523
box-sizing: border-box;
4624
}
4725

26+
.Select {
27+
margin-left: 4px;
28+
}
29+
4830
.tcs-location-filter {
31+
margin-right: 4px;
4932
border-radius: 4px;
5033
border: 1px solid #ccc;
5134
height: 36px;
35+
padding: 0 2px;
5236
}
5337

5438
.tcs-location-input {

0 commit comments

Comments
 (0)