Skip to content

Commit

Permalink
feat: Improve menu (kolplattformen#109)
Browse files Browse the repository at this point in the history
* Return empty array if no match on week

Better to handle empty response in client

* Parse all descriptions to markdown

To get rid of <br/> and other stuff

Co-authored-by: Johan Öbrink <johan.obrink@gmail.com>
  • Loading branch information
whyer and JohanObrink authored Apr 16, 2021
1 parent 0a02ffa commit 9c4fcb2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export class Api extends EventEmitter {
}

public async getMenu(child: EtjanstChild): Promise<MenuItem[]> {
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') {
Expand Down
17 changes: 6 additions & 11 deletions lib/parse/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
]

Expand Down

0 comments on commit 9c4fcb2

Please sign in to comment.