From 9c4fcb2d251d71ec076e3b1725ae74b497535d66 Mon Sep 17 00:00:00 2001 From: Andreas Eriksson Date: Fri, 16 Apr 2021 16:57:16 +0200 Subject: [PATCH] feat: Improve menu (#109) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Return empty array if no match on week Better to handle empty response in client * Parse all descriptions to markdown To get rid of
and other stuff Co-authored-by: Johan Öbrink --- lib/api.ts | 2 +- lib/parse/menu.ts | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index 4bba90f7..987ad888 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -387,7 +387,7 @@ export class Api extends EventEmitter { } public async getMenu(child: EtjanstChild): Promise { - if (this.isFake) return fakeResponse(fake.menu(child)) + if (this.isFake) return fakeResponse(fake.menu(child).map(parse.menuItem)) const menuService = await this.getMenuChoice(child) if (menuService === 'rss') { diff --git a/lib/parse/menu.ts b/lib/parse/menu.ts index ab03ef2f..5872a6c8 100644 --- a/lib/parse/menu.ts +++ b/lib/parse/menu.ts @@ -18,34 +18,29 @@ export const menuList = (data: any): MenuItem[] => { ) if (!currentWeek) { - return [ - { - title: 'Måndag - Vecka ?', - description: 'Hittade ingen meny', - }, - ] + return [] } const menuItemsFS = [ { title: `Måndag - Vecka ${currentWeek.week}`, - description: currentWeek.mon, + description: toMarkdown(currentWeek.mon) , }, { title: `Tisdag - Vecka ${currentWeek.week}`, - description: currentWeek.tue, + description: toMarkdown(currentWeek.tue), }, { title: `Onsdag - Vecka ${currentWeek.week}`, - description: currentWeek.wed, + description: toMarkdown(currentWeek.wed), }, { title: `Torsdag - Vecka ${currentWeek.week}`, - description: currentWeek.thu, + description: toMarkdown(currentWeek.thu), }, { title: `Fredag - Vecka ${currentWeek.week}`, - description: currentWeek.fri, + description: toMarkdown(currentWeek.fri), }, ]