Skip to content

Commit

Permalink
🐛 Fix bug that prevented returning to the edit screen after deleting …
Browse files Browse the repository at this point in the history
…a diagram
  • Loading branch information
harehare committed Oct 14, 2023
1 parent 9db10f9 commit 8d02cad
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
8 changes: 4 additions & 4 deletions frontend/src/elm/Api/Request.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)

Expand Down
10 changes: 10 additions & 0 deletions frontend/src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/elm/Page/List.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ())


Expand Down
5 changes: 4 additions & 1 deletion frontend/src/elm/Ports.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ port module Ports exposing
, closeLocalFile
, copyText
, downloadCompleted
, reload
, focusEditor
, fullscreen
, getDiagram
Expand All @@ -27,7 +28,7 @@ port module Ports exposing
, openedLocalFile
, progress
, refreshToken
, reload
, removedLocalDiagram
, removeRemoteDiagram
, saveDiagram
, saveLocalFile
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
1 change: 1 addition & 0 deletions frontend/src/ts/elm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type ElmApp = {
saveToLocalCompleted: Send<DiagramItem>;
removeRemoteDiagram: Send<Diagram>;
reload: Send<string>;
removedLocalDiagram: Send<string>;
gotLocalDiagramJson: Send<DiagramItem>;
gotLocalDiagramJsonForCopy: Send<DiagramItem>;
gotLocalDiagramsJson: Send<DiagramItem[]>;
Expand Down

0 comments on commit 8d02cad

Please sign in to comment.