diff --git a/api/v1/fixtures/recipe_data.json b/api/v1/fixtures/recipe_data.json index bc447e4e..7c3b6d46 100644 --- a/api/v1/fixtures/recipe_data.json +++ b/api/v1/fixtures/recipe_data.json @@ -67,7 +67,493 @@ "rating": 3, "update_date": "2011-05-21 07:35:32", "pub_date": "2011-05-21 07:35:32", - "slug": "tasty-chili-4", + "slug": "tasghjghjty-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 5, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 14", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "taghjksty-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 6, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 114", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tastsdfsdfy-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 7, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 1114", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tastzsdfsery-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 8, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 2224", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-asdfchili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 9, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 24", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-werwerchili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 10, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 224", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tastysdfsdf-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 11, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 334", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-xcvchili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 12, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 3334", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tastysdf-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 13, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 33334", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-werchili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 14, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 444", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-chertili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 15, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 44", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-chicxvbxcvbli-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 16, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 444", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasdasdasty-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 17, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 554", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "werwertasty-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 18, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 54", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "twerasty-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 19, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 554", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-ertchili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 20, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chili 5554", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "taergtsty-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 21, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chil12i 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-chxcvili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 22, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chil1234i 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-chighli-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 23, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chi124li 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tsdfasty-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 24, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chil14i 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "taertsty-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 25, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Ch124ili 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tastbxcvy-chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 26, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Ch14ili 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-sdfgchili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 27, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Ch15ili 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-6chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 28, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chi125li 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-5chili-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 29, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Chi123li 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-chi234li-4", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 30, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Ch345ili 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-chili-4234", + "prep_time": 60, + "cook_time": 60 + } + }, + { + "pk": 31, + "model": "recipe.recipe", + "fields": { + "info": "This chili is requested every winter by friends and family. I have been making this chili every since I was a small child and learned from my grandma", + "cuisine": 1, + "author": 1, + "title": "Tasty Ch12312ili 4", + "course": 2, + "servings": 8, + "rating": 3, + "update_date": "2011-05-21 07:35:32", + "pub_date": "2011-05-21 07:35:32", + "slug": "tasty-chili-4123", "prep_time": 60, "cook_time": 60 } diff --git a/frontend/modules/browse/components/Pagination.js b/frontend/modules/browse/components/Pagination.js index bbadefaa..76ca47db 100644 --- a/frontend/modules/browse/components/Pagination.js +++ b/frontend/modules/browse/components/Pagination.js @@ -22,14 +22,17 @@ const Pagination = ({ offset, limit, count, buildUrl }) => { let numbers = []; const min = 2, max = 5; + let floor = Math.floor(count/limit); + floor = count % limit === 0 ? floor : floor + 1; + // Make sure we start at the min value - let start = offset - min < 1 ? 1 : offset - min; + let start = offset/limit - min < 1 ? 1 : offset/limit - min; // Make sure we start at the max value - start = start > count/limit-max ? count/limit-max : start; + start = start > floor-max ? floor-max : start; // Only show data if we have results start = start < 1 ? 1 : start; - for (let i = start; i < count/limit && i < max + start; i++) { + for (let i = start; i < floor && i < max + start; i++) { numbers.push(link(i+1, limit*i, i+1, offset==limit*i)) } return numbers diff --git a/frontend/modules/browse/containers/Browse.js b/frontend/modules/browse/containers/Browse.js index 0c811c09..b3cc53da 100644 --- a/frontend/modules/browse/containers/Browse.js +++ b/frontend/modules/browse/containers/Browse.js @@ -46,6 +46,7 @@ class Browse extends React.Component { } reloadData(qs) { + window.scrollTo(0, 0); if (!this.props.search.results[queryString.stringify(this.mergeDefaultFilters(qs))]) { this.props.searchActions.loadRecipes(this.mergeDefaultFilters(qs)); } @@ -61,7 +62,6 @@ class Browse extends React.Component { } doSearch = (value) => { - console.log('hi'); let qs = queryString.parse(this.props.location.search); value !== "" ? qs['search'] = value : delete qs['search']; let str = queryString.stringify(qs); @@ -73,6 +73,7 @@ class Browse extends React.Component { if (!name) return '/browse/'; let qs = queryString.parse(this.props.location.search); + delete qs['offset']; if (value !== "") { if (qs[name] && multiSelect) {