Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added urls for searching #501

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const App = ({ loading, navbarDark, login, logout, loggedIn, username }) => (
/>
<Async path="/pulse" getComponent={() => import('../routes/pulse')} />
<Async
path="/plugin-hub/:author?"
path="/plugin-hub/:author?/:parameters?"
getComponent={() => import('../routes/plugin-hub')}
/>
<Async
Expand Down Expand Up @@ -77,6 +77,7 @@ const App = ({ loading, navbarDark, login, logout, loggedIn, username }) => (
export default connect(
state => ({
loggedIn: isLoggedIn(state),
search: state.filter,
...state.app,
...state.account
}),
Expand Down
5 changes: 4 additions & 1 deletion src/components/external-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { numberWithCommas } from '../util'
const ExternalPlugin = ({
displayName,
author,
s,
description,
internalName,
imageUrl,
Expand All @@ -29,7 +30,9 @@ const ExternalPlugin = ({
<a href={`/plugin-hub/show/${internalName}`}>{displayName}</a>
</h5>
<h6 class="card-subtitle mb-2 text-muted">
<a href={`/plugin-hub/${author}`}>{author}</a>
<a href={`/plugin-hub/${s ? author + '?s=' + s : author}`}>
{author}
</a>
</h6>
<p class="card-text">
{count > 0 && (
Expand Down
45 changes: 36 additions & 9 deletions src/routes/plugin-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import SearchBar from '../components/search-bar'
import { fetchConfig } from '../modules/config'
import Choice from '../components/choice'
import { numberWithCommas } from '../util'
import { route } from 'preact-router'

const description =
'The Plugin Hub is a repository of plugins that are created and ' +
Expand All @@ -28,13 +29,25 @@ const description =
"Developers to ensure they comply with Jagex's 3rd party client rules " +
'and are not malicious in some other way.'

const handleChange = (event, setPluginFilter) =>
const handleChange = (event, author, setPluginFilter) => {
setPluginFilter({
name: event.target.value
})
if (author) {
route(
`/plugin-hub/${author}${
event.target.value ? '?s=' + event.target.value : ''
}`
)
} else {
route(`/plugin-hub/${event.target.value ? '?s=' + event.target.value : ''}`)
}
}

// "s" is the search param from the query parameters to filter plugins
const PluginHub = ({
author,
s,
externalPlugins,
pluginFilter,
pluginSorting,
Expand All @@ -45,6 +58,16 @@ const PluginHub = ({
author ? plugin.author === author : true
)

if (s) {
if (s !== pluginFilter.name) {
setPluginFilter({ name: s })
}
} else {
if (pluginFilter.name !== '') {
setPluginFilter({ name: '' })
}
}

const pluginCount = externalPlugins.length
const installedPluginCount = externalPlugins.filter(p => p.installed).length
const totalCount = externalPlugins.reduce((a, b) => a + b.count, 0)
Expand Down Expand Up @@ -103,7 +126,9 @@ const PluginHub = ({
<div class="col-sm-8">
<SearchBar
value={pluginFilter.name}
onInput={e => handleChange(e, setPluginFilter)}
onInput={e => {
handleChange(e, author, setPluginFilter)
}}
/>
</div>
<div class="col-sm-4">
Expand All @@ -117,7 +142,7 @@ const PluginHub = ({
</div>
<div class="row">
{externalPlugins.map(plugin => (
<ExternalPlugin key={plugin.internalName} {...plugin} />
<ExternalPlugin key={plugin.internalName} s={s} {...plugin} />
))}
</div>
</div>
Expand All @@ -126,12 +151,14 @@ const PluginHub = ({
)
}

const mapStateToProps = (state, props) => ({
...props,
externalPlugins: getSortedExternalPlugins(state),
pluginFilter: getPluginFilter(state),
pluginSorting: getPluginSorting(state)
})
const mapStateToProps = (state, props) => {
return {
...props,
externalPlugins: getSortedExternalPlugins(state),
pluginFilter: getPluginFilter(state),
pluginSorting: getPluginSorting(state)
}
}

const mapDispatchToProps = dispatch =>
bindActionCreators(
Expand Down
Loading