Skip to content

Commit

Permalink
further uglify + few instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Aug 26, 2023
1 parent e02cb42 commit 3308866
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 34 deletions.
8 changes: 4 additions & 4 deletions R/mod_poke_evolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ mod_poke_evolve_server <- function(id, selected, is_shiny) {
tablerAlert(
title = "Alert",
"This Pokemon is a base pokemon.",
icon = "alert-triangle",
status = "danger"
icon = "thumbs-up",
status = "success"
)
} else {
# Check that the evolution belongs to the first 151 pkmns ...
Expand All @@ -52,8 +52,8 @@ mod_poke_evolve_server <- function(id, selected, is_shiny) {
title = "Alert",
"This pokemon is an evolution of another pokemon but not
in the first generation.",
icon = "alert-triangle",
status = "danger"
icon = "thumbs-up",
status = "success"
)
}
}
Expand Down
58 changes: 30 additions & 28 deletions R/mod_poke_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,37 @@ mod_poke_info_server <- function(id, selected, is_shiny) {

tagList(
fluidRow(
tablerProfileCard(
title = selected()$name,
subtitle = tagList(
pokemon$description,
tablerTagList(
align = "center",
tablerTag(name = pokemon$shape, rounded = TRUE, color = "default"),
tablerTag(name = pokemon$habitat, rounded = TRUE, color = pokemon$color)
)
),
background = "https://images.pexels.com/photos/355748/pexels-photo-355748.jpeg",
src = if (!is_shiny()) {
pokemon$sprites$front_default
} else {
pokemon$sprites$front_shiny
},
socials = tablerSocialLinks(
tablerSocialLink(
name = "pokeApi",
href = paste0("https://pokeapi.co/api/v2/pokemon/", tolower(selected())),
icon = "at"
tablerCard(
tablerProfileCard(
title = selected()$name,
subtitle = tagList(
pokemon$description,
tablerTagList(
align = "center",
tablerTag(name = pokemon$shape, rounded = TRUE, color = "default"),
tablerTag(name = pokemon$habitat, rounded = TRUE, color = pokemon$color)
)
),
tablerSocialLink(
name = "Bulbapedia",
href = paste0("https://bulbapedia.bulbagarden.net/wiki/", selected(), "_(Pok\u00e9mon)"),
icon = "address-card"
)
),
width = 4
background = "https://images.pexels.com/photos/355748/pexels-photo-355748.jpeg",
src = if (!is_shiny()) {
pokemon$sprites$front_default
} else {
pokemon$sprites$front_shiny
},
socials = tablerSocialLinks(
tablerSocialLink(
name = "pokeApi",
href = paste0("https://pokeapi.co/api/v2/pokemon/", tolower(selected())),
icon = "at"
),
tablerSocialLink(
name = "Bulbapedia",
href = paste0("https://bulbapedia.bulbagarden.net/wiki/", selected(), "_(Pok\u00e9mon)"),
icon = "address-card"
)
),
width = 4
)
)
),
br()
Expand Down
6 changes: 5 additions & 1 deletion R/mod_poke_select.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ mod_poke_select_ui <- function(id) {
mod_poke_select_server <- function(id) {
moduleServer(id, function(input, output, session) {
ns <- session$ns

# WORKSHOP TODO
# Add user feedback to select_pokemon

return(
list(
selected = reactive(poke_data[[input$selected]]),
selected = reactive(select_pokemon(input$selected)),
is_shiny = reactive(input$is_shiny)
)
)
Expand Down
2 changes: 1 addition & 1 deletion R/mod_poke_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod_poke_type_server <- function(id, selected) {
tablerInfoCard(
value = paste(type_slot, type_name),
status = poke_color,
icon = icon("card"),
icon = icon("xmark"),
description = "%",
width = 12
),
Expand Down
32 changes: 32 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,35 @@ process_pokemon_stats <- function(stats) {
y = extra_from_list(stats, "base_stat", numeric(1))
)
}

#' Function to select pokemon
#'
#' Select pokemon in the \link{poke_data}.
#'
#' @param selected Selected pokemon name.
#'
#' @return A list containing the selected pokemon data.
#' @keywords internal
select_pokemon <- function(selected) {
# We make the function slow on purpose.

# WORKSHOP TODO
# Find a way to warn the user about this waiting time ...
Sys.sleep(5)

# We simulate an imaginary failing API connection
# This randomly fails so the function result
# isn't predictable...and the app crashes without
# notifying the user of what happened...

# WORKSHOP TODO
# Find a way to make this function elegantly failing
# and warn the end user ...
res <- sample(c(FALSE, TRUE), 1)
message(res)
if (!res) {
stop("Could not connect to the Pokemon API ...")
} else {
poke_data[[selected]]
}
}
18 changes: 18 additions & 0 deletions man/select_pokemon.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3308866

Please sign in to comment.