diff options
author | Yorhel <git@yorhel.nl> | 2020-03-27 08:50:19 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-03-27 08:50:20 +0100 |
commit | daa7536973531c1149dbe60b70a785997bb871a2 (patch) | |
tree | fc08fa47263de3af8fde9f7a3a7d4d0f6468f97b | |
parent | 74255fe83a6cf7009f9b2091986478a9dce891d6 (diff) |
imgflag: Display image id link instead of using history.replaceState()
replaceState() fucks up the back button in this case - it'll load the
page with the new URL, but that won't allow regular users to vote on the
image they had open.
-rw-r--r-- | elm/ImageFlagging.elm | 14 | ||||
-rw-r--r-- | elm/ImageFlagging.js | 8 |
2 files changed, 5 insertions, 17 deletions
diff --git a/elm/ImageFlagging.elm b/elm/ImageFlagging.elm index 57cc8239..b37c2d44 100644 --- a/elm/ImageFlagging.elm +++ b/elm/ImageFlagging.elm @@ -30,7 +30,6 @@ main = Browser.element port preload : String -> Cmd msg -port updateUrl : String -> Cmd msg type alias Model = @@ -128,11 +127,6 @@ update msg model = case Array.get (m.index+1) m.images of Just i -> (m, Cmd.batch [ c, preload i.url ]) Nothing -> (m, c) - -- Update page URL to current image - url (m,c) = - case Array.get m.index m.images of - Just i -> (m, Cmd.batch [ c, updateUrl i.id ]) - Nothing -> (m, c) in case msg of SkipWarn -> load ({ model | warn = False }, Cmd.none) @@ -153,7 +147,7 @@ update msg model = adv = if not m.single && (i.my_sexual == Nothing || i.my_violence == Nothing) then 1 else 0 in case (i.token,s,v) of -- Complete vote, mark it as a change and go to next image - (Just token, Just xs, Just xv) -> url <| desc <| pre <| save <| load + (Just token, Just xs, Just xv) -> desc <| pre <| save <| load ({ m | index = m.index + adv , myVotes = m.myVotes + adv , changes = Dict.insert i.id { id = i.id, token = token, sexual = xs, violence = xv } m.changes @@ -164,8 +158,8 @@ update msg model = Save -> ({ model | saveTimer = False, saveState = Api.Loading, changes = Dict.empty }, GIV.send { votes = Dict.values model.changes } Saved) Saved r -> save ({ model | saved = True, saveState = if r == GApi.Success then Api.Normal else Api.Error r }, Cmd.none) - Prev -> url <| desc ({ model | saved = False, index = model.index - (if model.index == 0 then 0 else 1) }, Cmd.none) - Next -> url <| desc <| pre <| load ({ model | saved = False, index = model.index + (if model.single then 0 else 1) }, Cmd.none) + Prev -> desc ({ model | saved = False, index = model.index - (if model.index == 0 then 0 else 1) }, Cmd.none) + Next -> desc <| pre <| load ({ model | saved = False, index = model.index + (if model.single then 0 else 1) }, Cmd.none) view : Model -> Html Msg @@ -221,6 +215,8 @@ view model = , b [ class "grayedout" ] [ text " / " ] , text <| "violence: " ++ stat i.violence_avg i.violence_stddev , b [ class "grayedout" ] [ text " / " ] + , a [ href <| "/img/" ++ String.filter Char.isAlphaNum i.id ] [ text <| String.filter Char.isAlphaNum i.id ] + , b [ class "grayedout" ] [ text " / " ] , a [ href i.url ] [ text <| String.fromInt i.width ++ "x" ++ String.fromInt i.height ] ] ] diff --git a/elm/ImageFlagging.js b/elm/ImageFlagging.js index 50ab4943..7fb6d181 100644 --- a/elm/ImageFlagging.js +++ b/elm/ImageFlagging.js @@ -13,12 +13,4 @@ Elm.ImageFlagging.init = function(opt) { preload[url].src = url; } }); - - app.ports.updateUrl.subscribe(function(id) { - if(curid == id || !history || !history.replaceState) - return; - curid = id; - var imgid = id.replace(/[\(\),]/g, ''); - history.replaceState(id, "Image flagging for "+imgid, "/img/"+imgid); - }); }; |