Skip to content

Commit

Permalink
feat/embed: open link in newtab in embed view mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrckd committed Oct 10, 2024
1 parent 6678c56 commit 0e629dc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 16 deletions.
7 changes: 5 additions & 2 deletions assets/js/ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ export const actions = {
'LOG': (app, session, message) => {
console.log(`From Elm:`, message);
},
'LOGERR': (app, session, message) => {
console.warn(`Error from Elm:`, message);
},
'SHOW': (app, session, id) => {
var $e = document.getElementById(id);
if (!$e) { return }
Expand All @@ -564,8 +567,8 @@ export const actions = {
$e.style.display = "none";
//$e.style.visibility = "hidden";
},
'LOGERR': (app, session, message) => {
console.warn(`Error from Elm:`, message);
'OPENINNEWTAB': (app, session, url) => {
window.open(url, '_blank');
},
'CLICK': (app, session, target) => {
if (target == "") {
Expand Down
16 changes: 13 additions & 3 deletions assets/sass/fractal6.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@
*
*/

#app.embed .is-hidden-embed {
display: none;
#app.embed {
.is-hidden-embed {
display: none !important;
}

.columns {
}
.orgPane > .column, .orgPane > * > .column, .orgPane > * > * > .column {
padding: 0 !important;
width: 100% !important;
}
}


/*
*
* Bulma Fixes
Expand Down Expand Up @@ -1205,7 +1215,7 @@ figcaption {
position: relative;
//position: absolute;
box-shadow: 0 0 1px 0 var(--is-highlight);
margin-top: 3rem;
margin-top: 4rem;
padding: 1rem 1rem 1rem;
}

Expand Down
13 changes: 12 additions & 1 deletion src/Extra/Url.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
-}


module Extra.Url exposing (queryBuilder, queryFullBuilder, queryParser, toAnchor)
module Extra.Url exposing (getUrlQueryParam, queryBuilder, queryFullBuilder, queryParser, toAnchor)

import Dict exposing (Dict)
import List.Extra as LE
import Maybe exposing (withDefault)
import Url exposing (Url)


Expand Down Expand Up @@ -105,3 +107,12 @@ toAnchor x =
|> String.replace " " "-"
|> String.toLower
|> String.append "#"


getUrlQueryParam : String -> Url -> Maybe String
getUrlQueryParam key url =
url.query
|> Maybe.map (String.split "&")
|> Maybe.andThen (LE.find (String.startsWith (key ++ "=")))
|> Maybe.map (String.split "=")
|> Maybe.andThen LE.last
8 changes: 6 additions & 2 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ module Main exposing (main)

import Browser exposing (Document)
import Browser.Navigation as Nav exposing (Key)
import Extra.Url exposing (queryParser)
import Extra.Url exposing (getUrlQueryParam, queryParser)
import Generated.Pages as Pages
import Generated.Route as Route exposing (Route(..))
import Global exposing (Msg(..))
import Html
import Ports
import Session exposing (encodeViewMode)
import Url exposing (Url)
import Url.Parser.Query


main : Program Flags Model Msg
Expand Down Expand Up @@ -94,7 +95,10 @@ update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
LinkClicked (Browser.Internal url) ->
if Route.fromUrl url == Just Route.Logout then
if getUrlQueryParam "view" model.url == Just "embed" then
( model, Ports.openInNewTab (Url.toString url) )

else if Route.fromUrl url == Just Route.Logout then
( model, Nav.replaceUrl model.key (Url.toString url) )

else
Expand Down
2 changes: 1 addition & 1 deletion src/Org/Project.elm
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ view_ : Global.Model -> Model -> Html Msg
view_ global model =
div [ class "columns is-centered" ]
[ div [ class "column is-12 is-11-desktop is-10-fullhd pb-0" ]
[ div [ class "columns is-centered mb-0" ]
[ div [ class "columns is-centered mb-0 is-hidden-embed" ]
[ div [ class "column is-tree-quarter pb-1" ]
[ case model.project_data of
Success p ->
Expand Down
22 changes: 15 additions & 7 deletions src/Ports.elm
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,14 @@ log message =
}


logErr : String -> Cmd msg
logErr message =
outgoing
{ action = "LOGERR"
, data = JE.string message
}


show : String -> Cmd msg
show message =
outgoing
Expand All @@ -607,18 +615,18 @@ hide message =
}


fitHeight : String -> Cmd msg
fitHeight message =
openInNewTab : String -> Cmd msg
openInNewTab url =
outgoing
{ action = "FIT_HEIGHT"
, data = JE.string message
{ action = "OPENINNEWTAB"
, data = JE.string url
}


logErr : String -> Cmd msg
logErr message =
fitHeight : String -> Cmd msg
fitHeight message =
outgoing
{ action = "LOGERR"
{ action = "FIT_HEIGHT"
, data = JE.string message
}

Expand Down

0 comments on commit 0e629dc

Please # to comment.