<commit_before>module View (..) where

import Models exposing (..)
import Actions exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import String
import Routing
import Meals.List
import Meals.Edit
import Meals.Models exposing (MealId)


view : Signal.Address Action -> AppModel -> Html
view address model =
  let
    _ =
      Debug.log "view" model
  in
    div
      []
      [ flash address model
      , page address model
      ]


flash : Signal.Address Action -> AppModel -> Html
flash address model =
  if String.isEmpty model.errorMessage then
    span [] []
  else
    div
      [ class "bold center p2 mb2 white bg-red rounded" ]
      [ p [] [ text model.errorMessage ] ]


page : Signal.Address Action -> AppModel -> Html
page address model =
  case model.routing.route of
    Routing.MealsRoute ->
      mealsPage address model

    Routing.MealEditRoute mealId ->
      mealEditPage address model mealId

    Routing.MealShowRoute mealId ->
      mealShowPage address model mealId

    Routing.NotFoundRoute ->
      notFoundView


mealsPage : Signal.Address Action -> AppModel -> Html
mealsPage address model =
  let
    viewModel =
      { meals = model.meals }
  in
    Meals.List.view (Signal.forwardTo address MealsAction) viewModel


mealShowPage : Signal.Address Action -> AppModel -> MealId -> Html
mealShowPage address model mealId =
  let
    maybeMeal =
      model.meals
        |> List.filter (\meal -> meal.id == mealId)
        |> List.head
  in
    case maybeMeal of
      Just meal ->
        let
          viewModel =
            { meal = meal }
        in
          Meals.Edit.view (Signal.forwardTo address MealsAction) viewModel

      Nothing ->
        notFoundView


mealEditPage : Signal.Address Action -> AppModel -> MealId -> Html
mealEditPage address model mealId =
  let
    maybeMeal =
      model.meals
        |> List.filter (\meal -> meal.id == mealId)
        |> List.head
  in
    case maybeMeal of
      Just meal ->
        let
          viewModel =
            { meal = meal }
        in
          Meals.Edit.view (Signal.forwardTo address MealsAction) viewModel

      Nothing ->
        notFoundView


notFoundView : Html
notFoundView =
  div
    []
    [ text "Not found"
    ]<commit_msg>Use fetchOne meal data in show and edit<commit_after>module View (..) where

import Models exposing (..)
import Actions exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import String
import Routing
import Meals.List
import Meals.Edit
import Meals.Models exposing (MealId)


view : Signal.Address Action -> AppModel -> Html
view address model =
  let
    _ =
      Debug.log "view" model
  in
    div
      []
      [ flash address model
      , page address model
      ]


flash : Signal.Address Action -> AppModel -> Html
flash address model =
  if String.isEmpty model.errorMessage then
    span [] []
  else
    div
      [ class "bold center p2 mb2 white bg-red rounded" ]
      [ p [] [ text model.errorMessage ] ]


page : Signal.Address Action -> AppModel -> Html
page address model =
  case model.routing.route of
    Routing.MealsRoute ->
      mealsPage address model

    Routing.MealEditRoute mealId ->
      mealEditPage address model mealId

    Routing.MealShowRoute mealId ->
      mealEditPage address model mealId

    Routing.NotFoundRoute ->
      notFoundView


mealsPage : Signal.Address Action -> AppModel -> Html
mealsPage address model =
  let
    viewModel =
      { meals = model.meals }
  in
    Meals.List.view (Signal.forwardTo address MealsAction) viewModel


mealEditPage : Signal.Address Action -> AppModel -> MealId -> Html
mealEditPage address model mealId =
  case model.currentMeal of
    Just meal ->
      let
        viewModel =
          { meal = meal }
      in
        Meals.Edit.view (Signal.forwardTo address MealsAction) viewModel

    Nothing ->
      notFoundView


notFoundView : Html
notFoundView =
  div
    []
    [ text "Not found"
    ]
{'fraction_non_alphanumeric': 0.0829366073665748, 'fraction_numerical': 0.0010022550739163117, 'mean_word_length': 2.3128630705394193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6573308', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1159, 'n_words': 360}