diff --git a/frontend/src/elm/Api/Request.elm b/frontend/src/elm/Api/Request.elm index 2f34b7d4e..716c1472c 100644 --- a/frontend/src/elm/Api/Request.elm +++ b/frontend/src/elm/Api/Request.elm @@ -71,17 +71,17 @@ bookmark idToken itemID isBookmark = |> Task.mapError toError -delete : Maybe IdToken -> DiagramId -> Bool -> Task RequestError String +delete : Maybe IdToken -> DiagramId -> Bool -> Task RequestError DiagramId delete idToken itemID isPublic = Mutation.delete (DiagramId.toString itemID) isPublic |> Http.mutationRequest graphQLUrl |> authHeaders idToken |> Http.toTask - |> Task.map (\(Graphql.Scalar.Id id) -> id) + |> Task.map (\(Graphql.Scalar.Id id) -> DiagramId.fromString id) |> Task.mapError toError -deleteGist : Maybe IdToken -> AccessToken -> DiagramId -> Task RequestError String +deleteGist : Maybe IdToken -> AccessToken -> DiagramId -> Task RequestError DiagramId deleteGist idToken accessToken gistId = GithubRequest.deleteGist accessToken gistId |> Task.mapError RequestError.fromHttpError @@ -91,7 +91,7 @@ deleteGist idToken accessToken gistId = |> Http.mutationRequest graphQLUrl |> authHeaders idToken |> Http.toTask - |> Task.map (\(Graphql.Scalar.Id id) -> id) + |> Task.map (\(Graphql.Scalar.Id id) -> DiagramId.fromString id) |> Task.mapError toError ) diff --git a/frontend/src/elm/Main.elm b/frontend/src/elm/Main.elm index f16dd62ee..431e6ee68 100644 --- a/frontend/src/elm/Main.elm +++ b/frontend/src/elm/Main.elm @@ -753,6 +753,7 @@ subscriptions model = , Ports.loadSettingsFromLocalCompleted M.LoadSettingsFromLocal , Ports.startDownload M.StartDownload , Ports.gotLocalDiagramsJson (\json -> M.UpdateDiagramList (DiagramList.GotLocalDiagramsJson json)) + , Ports.removedLocalDiagram (\idString -> (Ok <| DiagramId.fromString idString) |> DiagramList.Removed |> M.UpdateDiagramList) , Ports.reload (\_ -> M.UpdateDiagramList DiagramList.Reload) , onVisibilityChange M.HandleVisibilityChange , onResize (\width height -> M.UpdateDiagram (DiagramModel.Resize width height)) @@ -1391,6 +1392,15 @@ processDiagramListMsg msg = DiagramList.GotExportDiagrams (Err e) -> showErrorMessage <| RequestError.toMessage e + DiagramList.Removed (Ok diagramId) -> + Return.map <| + \m -> + if (m.currentDiagram.id |> Maybe.withDefault (DiagramId.fromString "")) == diagramId then + { m | currentDiagram = DiagramItem.new DiagramType.UserStoryMap } + + else + m + DiagramList.Removed (Err _) -> showErrorMessage Message.messagEerrorOccurred diff --git a/frontend/src/elm/Page/List.elm b/frontend/src/elm/Page/List.elm index ac52544bb..efee2b226 100644 --- a/frontend/src/elm/Page/List.elm +++ b/frontend/src/elm/Page/List.elm @@ -93,7 +93,7 @@ import Json.Encode as E import List.Extra as ListEx import Message exposing (Lang) import Models.Color as Color -import Models.Diagram.Id as DiagramId +import Models.Diagram.Id as DiagramId exposing (DiagramId) import Models.Diagram.Item as DiagramItem exposing (DiagramItem) import Models.Diagram.Location as DiagramLocation import Models.Dialog as Dialog @@ -128,7 +128,7 @@ type Msg | Reload | Remove DiagramItem | RemoveRemote D.Value - | Removed (Result RequestError String) + | Removed (Result RequestError DiagramId) | Bookmarked (Result RequestError ()) | GotTimeZone Zone | GetDiagrams @@ -213,7 +213,7 @@ load : { session : Session, isOnline : Bool } -> Return.ReturnF Msg Model load { session, isOnline } = Return.andThen <| \m -> - Return.singleton { m | session = session, isOnline = isOnline } + Return.singleton { m | session = session, isOnline = isOnline, diagramList = DiagramList.notAsked } |> Return.command (getDiagrams ()) diff --git a/frontend/src/elm/Ports.elm b/frontend/src/elm/Ports.elm index 62ea491cc..d647d29ae 100644 --- a/frontend/src/elm/Ports.elm +++ b/frontend/src/elm/Ports.elm @@ -5,6 +5,7 @@ port module Ports exposing , closeLocalFile , copyText , downloadCompleted + , reload , focusEditor , fullscreen , getDiagram @@ -27,7 +28,7 @@ port module Ports exposing , openedLocalFile , progress , refreshToken - , reload + , removedLocalDiagram , removeRemoteDiagram , saveDiagram , saveLocalFile @@ -128,6 +129,8 @@ port progress : (Bool -> msg) -> Sub msg port refreshToken : () -> Cmd msg +port removedLocalDiagram : (String -> msg) -> Sub msg + port reload : (String -> msg) -> Sub msg diff --git a/frontend/src/ts/db.ts b/frontend/src/ts/db.ts index c143e80b9..73005088f 100644 --- a/frontend/src/ts/db.ts +++ b/frontend/src/ts/db.ts @@ -125,7 +125,7 @@ export const initDB = (app: ElmApp): void => { app.ports.removeRemoteDiagram.send(diagram); } else { await db.diagrams.delete(id); - app.ports.reload.send(''); + app.ports.removedLocalDiagram.send(id); } }); diff --git a/frontend/src/ts/elm.ts b/frontend/src/ts/elm.ts index dc7e1bedd..46937f561 100644 --- a/frontend/src/ts/elm.ts +++ b/frontend/src/ts/elm.ts @@ -61,6 +61,7 @@ export type ElmApp = { saveToLocalCompleted: Send; removeRemoteDiagram: Send; reload: Send; + removedLocalDiagram: Send; gotLocalDiagramJson: Send; gotLocalDiagramJsonForCopy: Send; gotLocalDiagramsJson: Send;