Skip to content

Commit

Permalink
Use cookie to pre-populate fridge index page
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Jun 25, 2024
1 parent 70348ac commit 4c83f3d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/fridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {makeHebcalOptions, makeHebrewCalendar, localeMap,
cleanQuery,
makeGeoUrlArgs,
langNames,
processCookieAndQuery,
getLocationFromQuery,
cacheControl, queryDefaultCandleMins} from './common.js';
import {getDefaultHebrewYear} from './dateUtil.js';
import '@hebcal/locales';
Expand All @@ -14,8 +16,11 @@ const CACHE_CONTROL_3DAYS = cacheControl(3);

export async function fridgeShabbat(ctx) {
if (ctx.request.path.startsWith('/fridge')) {
const q = processCookieAndQuery(ctx.cookies.get('C'), {}, ctx.request.query);
const location = getLocationFromQuery(ctx.db, q);
q['city-typeahead'] = location && location.geo !== 'pos' ? location.getName() : '';
return ctx.render('fridge-index', {
q: ctx.request.query,
q,
langNames,
});
}
Expand Down
4 changes: 2 additions & 2 deletions views/fridge-index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
single page. You can print it out and post it on your refrigerator.</p>

<form action="/shabbat/fridge.cgi" method="get" autocomplete="off">
<input type="hidden" name="geo" value="<%= q.geo %>" id="geo">
<input type="hidden" name="zip" value="<%= q.zip %>" id="zip">
<input type="hidden" name="geo" id="geo" value="<%= q.geo || 'geonameid' %>">
<input type="hidden" name="zip" id="zip" value="<%= q.zip || '' %>">
<input type="hidden" name="geonameid" value="<%= q.geonameid %>" id="geonameid">
<%- await include('partials/city-and-havdalah.ejs') -%>
<div class="mt-2">
Expand Down

0 comments on commit 4c83f3d

Please sign in to comment.