Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Allow users to search for a dat using the search bar (#593)
Browse files Browse the repository at this point in the history
* Allow users to search for a dat using the search bar

* fix test
  • Loading branch information
Karissa committed Jun 19, 2017
1 parent dbf3517 commit f4ca5f8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion client/js/elements/import-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function (emit) {
}
}
return html`<label for="import-dat" class="dat-input">
<input name="import-dat" type="text" placeholder="Search Dat Link" onkeydown=${keydown} class="dat-input__input dat-input__input--icon">
<input name="import-dat" type="text" placeholder="Search" onkeydown=${keydown} class="dat-input__input dat-input__input--icon">
<svg class="dat-input__icon pa1">
<use xlink:href="#daticon-search" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion client/js/models/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ module.exports = function (state, emitter) {
})
})
emitter.on('archive:view', function (link) {
window.location.href = '/view?link=' + link
window.location.href = '/view?query=' + link
})
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"dat-icons": "^2.5.0",
"dat-link-resolve": "^1.0.0",
"dat-registry": "^3.0.2",
"dat-registry-api": "^4.0.0",
"dat-registry-api": "^5.0.0",
"dat-swarm-defaults": "^1.0.0",
"debug": "^2.6.8",
"discovery-swarm": "^4.2.0",
Expand Down
22 changes: 13 additions & 9 deletions server/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,16 @@ module.exports = function (config) {
router.post('/api/v1/password-reset', api.auth.passwordReset)
router.post('/api/v1/password-reset-confirm', api.auth.passwordResetConfirm)

router.get('/api/v1/:username/:dataset', function (req, res) {
db.dats.getByShortname(req.params, function (err, dat) {
router.get('/api/v1/dats/search', function (req, res) {
api.db.dats.search(req.query, function (err, resp) {
if (err) return onerror(err, res)
res.json(dat)
res.json(resp)
})
})

router.get('/api/v1/browse', function (req, res) {
db.dats.list(req.params, function (err, resp) {
router.get('/api/v1/:username/:dataset', function (req, res) {
db.dats.getByShortname(req.params, function (err, dat) {
if (err) return onerror(err, res)
res.json(resp)
res.json(dat)
})
})

Expand All @@ -78,14 +77,19 @@ module.exports = function (config) {
router.get('/browser', send)

router.get('/view', function (req, res) {
archiveRoute(req.query.dat || req.query.link, function (state) {
archiveRoute(req.query.query, function (state) {
if (state.archive.error && state.archive.error.message === 'Invalid key') {
var url = '/explore' + req._parsedUrl.search
console.log('redirecting', url)
return res.redirect(301, url)
}
return sendSPA(req, res, state)
})
})

router.get('/explore', function (req, res) {
var state = getDefaultAppState()
db.dats.list(req.params, function (err, resp) {
db.dats.search(req.query, function (err, resp) {
if (err) return onerror(err, res)
state.explore.data = resp
sendSPA(req, res, state)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ module.exports = new function () {
.url(testServer)
.assert.containsText('body', 'dat')
}
testCases['viewing a dat that doesnt exist gives 404'] = (client) => {
testCases['viewing a dat that doesnt exist gives explore page'] = (client) => {
client
.url(testServer + '/install')
.expect.element("input[name='import-dat']").value.to.equal('').before(2000)
client
.setValue("input[name='import-dat']", 'hello')
.keys(client.Keys.ENTER)
.expect.element('body').text.to.contain('No dat here.').before(2000)
.expect.element('body').text.to.contain('Shared with Dat').before(2000)
}
testCases['viewing a dat with a key that doesnt exist gives 404'] = (client) => {
// this is just a valid hash but doesn't resolve to a dat
Expand Down

0 comments on commit f4ca5f8

Please sign in to comment.