Skip to content

Commit

Permalink
Merge pull request #55 from seanbirchall/development
Browse files Browse the repository at this point in the history
UPDATE: new auth and junk removal
  • Loading branch information
seanbirchall authored Dec 30, 2024
2 parents ad41330 + bc8f232 commit 9451c66
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 203 deletions.
4 changes: 2 additions & 2 deletions app/R/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ with(scrapeable, {
id <- uuid::UUIDgenerate()
session$sendCustomMessage(
"duckdb_r",
list(
message = list(
url = url,
query = query,
id = id
Expand Down Expand Up @@ -144,7 +144,7 @@ with(scrapeable, {
shinyjs::delay(1, shinyjs::click(id = "control-viewer-show", asis = TRUE))
session$sendCustomMessage(
"view",
list(
message = list(
obj = obj
)
)
Expand Down
11 changes: 5 additions & 6 deletions app/R/header.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ server_header <- function(id, ide){

# observe share link ----
shiny::observeEvent(input$share, {
if(session$userData$authentication){
if(session$userData$logged_in){
## share notification ----
show_notification(
type = "loading",
Expand Down Expand Up @@ -144,11 +144,6 @@ server_header <- function(id, ide){
}else{
id <- ide$last_id
payload <- NULL
if(ide$code_received > 0){
ide$code_received <- as.integer(Sys.time())
}else{
ide$code_received <- -as.integer(Sys.time())
}
}
## send payload if not null ----
if(!is.null(payload)){
Expand Down Expand Up @@ -177,6 +172,10 @@ server_header <- function(id, ide){

# put code response ----
shiny::observeEvent(input$put_code_response, {
ide$put_code_response <- input$put_code_response
})
shiny::observeEvent(ide$put_code_response, {
response <- ide$put_code_response
if(response$status == "success"){
removeNotification(id = "notification_share")
show_notification(
Expand Down
71 changes: 22 additions & 49 deletions app/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ui <- bslib::page(
shiny::tags$script(
type = "text/javascript", src = "df_viewer2.js"
),
# js to load right away ----
shiny::tags$script(
type = "text/javascript", src = "view.js"
),
Expand All @@ -51,6 +52,11 @@ ui <- bslib::page(
label = NULL,
style = "display: none;"
),
shiny::actionButton(
inputId = "logged_in",
label = NULL,
style = "display: none;"
),

# content ----
bslib::card(
Expand Down Expand Up @@ -109,12 +115,6 @@ ui <- bslib::page(
shiny::tags$script(
type = "text/javascript", src = "w2ui.js"
),
# shiny::tags$script(
# type = "text/javascript", src = "active_tab.js"
# ),
shiny::tags$script(
type = "text/javascript", src = "check_auth.js"
),
shiny::tags$script(
type = "text/javascript", src = "handlers.js"
),
Expand All @@ -124,18 +124,6 @@ ui <- bslib::page(
shiny::tags$script(
type = "text/javascript", src = "events.js"
),
# shiny::tags$script(
# type = "text/javascript", src = "modalActive.js"
# ),
# shiny::tags$script(
# type = "text/javascript", src = "authenticate.js"
# ),
# shiny::tags$script(
# type = "text/javascript", src = "copy_by_id.js"
# ),
# shiny::tags$script(
# type = "text/javascript", src = "put_code.js"
# ),
shiny::tags$script(
type = "text/javascript", src = "keyboard_shortcuts.js"
)
Expand Down Expand Up @@ -195,8 +183,22 @@ server <- function(input, output, session) {
ide = ide
)

# check auth on-load ----
session$sendCustomMessage("check_auth", list())
# check auth on-load set logged in ----
session$sendCustomMessage(
"check_refresh_token",
message = list(
inputId = "tokens"
)
)
shiny::observeEvent(input$tokens, {
if(input$tokens[["status"]] == "success"){
session$userData$logged_in <- TRUE
return()
}
session$userData$logged_in <- FALSE
})

# recheck login ----

# style code ----
shiny::observeEvent(input$style, {
Expand Down Expand Up @@ -285,7 +287,6 @@ server <- function(input, output, session) {
}
})

# session$sendCustomMessage("refreshToken", list())
# on start observe query parameters ----
shiny::observeEvent(session$clientData$url_search, {
query <- parseQueryString(session$clientData$url_search)
Expand Down Expand Up @@ -347,34 +348,6 @@ server <- function(input, output, session) {
}
})

# set token in session user data ----
observeEvent(input$is_logged_in, {
session$userData$authentication <- input$is_logged_in
})

# successful share code ----
shiny::observeEvent(input$code_received, {
ide$code_received <- as.numeric(input$code_received)
})
shiny::observeEvent(ide$code_received, {
if(length(ide$code_received) > 0){
show_notification(
type = "success",
msg = "Share Link Ready!",
duration = 5,
id = "notification_share"
)
ide$show_share <- ide$show_share + 1
}else{
show_notification(
type = "error",
msg = "Share Link Failed",
duration = 5,
id = "notification_share"
)
}
})

# df_viewer modal ----
shiny::observeEvent(input$modal_df_viewer, {
ide$modal_df_viewer <- input$modal_df_viewer
Expand Down
86 changes: 0 additions & 86 deletions app/www/authenticate.js

This file was deleted.

20 changes: 0 additions & 20 deletions app/www/check_auth.js

This file was deleted.

30 changes: 19 additions & 11 deletions app/www/handlers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// put code to digitial ocean
Shiny.addCustomMessageHandler("put_code", function(inputId, message) {
const { payload, token } = message; // Destructure both payload and token
Shiny.addCustomMessageHandler("put_code", function(message) {
const { inputId, payload } = message;
fetch('https://reprex.org/put/code/', {
method: 'POST',
credentials: 'include',
Expand All @@ -23,7 +23,6 @@ Shiny.addCustomMessageHandler("put_code", function(inputId, message) {
});
})
.catch(error => {
console.error('Error:', error);
Shiny.setInputValue(inputId, {
status: 'error',
timestamp: Date.now(),
Expand All @@ -33,24 +32,33 @@ Shiny.addCustomMessageHandler("put_code", function(inputId, message) {
});

// check for refresh token
Shiny.addCustomMessageHandler('check_refresh_token', function(inputId, message) {
Shiny.addCustomMessageHandler('check_refresh_token', function(message) {
const { inputId } = message;
fetch('https://reprex.org/auth/refresh', {
method: 'GET',
credentials: 'include'
})
.then(response => {
if (response.status === 200) {
console.log('refreshed successfully');
Shiny.setInputValue(inputId, true);
Shiny.setInputValue(inputId, {
status: 'success',
timestamp: Date.now(),
data: response
})
} else {
// Refresh failed
console.log('refresh failed');
Shiny.setInputValue(inputId, false);
Shiny.setInputValue(inputId, {
status: 'error',
timestamp: Date.now(),
data: response
})
}
})
.catch(error => {
console.error('refresh error:', error);
Shiny.setInputValue(inputId, false);
Shiny.setInputValue(inputId, {
status: 'error',
timestamp: Date.now(),
data: error
})
});
});

Expand Down
27 changes: 0 additions & 27 deletions app/www/put_code.js

This file was deleted.

2 changes: 1 addition & 1 deletion webR/app.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion webR/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>REPREX</title>
<link rel="icon" type="image/svg+xml" href="./logo2.svg">
<link rel="icon" type="image/svg+xml" href="./logo.svg">
<script
src="./shinylive/load-shinylive-sw.js"
type="module"
Expand Down
File renamed without changes

0 comments on commit 9451c66

Please sign in to comment.