Skip to content

Commit

Permalink
🐛 Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
harehare committed Oct 12, 2023
1 parent 5589995 commit 14a899f
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 21 deletions.
2 changes: 1 addition & 1 deletion backend/internal/domain/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func isAuthenticated(ctx context.Context) error {
}

func (s *Service) Find(ctx context.Context, offset, limit int, isPublic bool, isBookmark bool, fields map[string]struct{}) mo.Result[[]*diagramitem.DiagramItem] {
shouldLoadText := slices.Contains(graphql.CollectAllFields(ctx), "Text")
shouldLoadText := slices.Contains(graphql.CollectAllFields(ctx), "text")

if err := isAuthenticated(ctx); err != nil {
return mo.Err[[]*diagramitem.DiagramItem](err)
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/infra/firebase/item/diagramitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,5 @@ func (r *FirestoreItemRepository) deleteToFirestore(ctx context.Context, userID

func (r *FirestoreItemRepository) deleteToCloudStorage(ctx context.Context, userID, itemID string) mo.Result[bool] {
storage := firebase.NewCloudStorage(r.storage)
return storage.Delete(ctx, userID, itemID)
return storage.Delete(ctx, storageRoot, userID, itemID)
}
7 changes: 5 additions & 2 deletions backend/internal/infra/firebase/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"compress/gzip"
"context"
"fmt"
"io"
"strings"

Expand Down Expand Up @@ -94,14 +95,16 @@ func (s *CloudStorage) Get(ctx context.Context, prefix string, paths ...string)
return mo.Ok(string(body))
}

func (s *CloudStorage) Delete(ctx context.Context, uid, itemID string) mo.Result[bool] {
func (s *CloudStorage) Delete(ctx context.Context, prefix, uid, itemID string) mo.Result[bool] {
bucket, err := s.client.DefaultBucket()

if err != nil {
return mo.Err[bool](err)
}

if err = bucket.Object(getObjectName(uid, itemID)).Delete(ctx); err != nil {
fmt.Println(getObjectName(prefix, uid, itemID))

if err = bucket.Object(getObjectName(prefix, uid, itemID)).Delete(ctx); err != nil {
return mo.Err[bool](err)
}

Expand Down
13 changes: 11 additions & 2 deletions frontend/src/elm/Api/Request.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Api.Request exposing
( allItems
, allItemsWithText
, bookmark
, bulkSave
, delete
, deleteGist
, gistItem
Expand Down Expand Up @@ -160,9 +161,17 @@ publicItem idToken id =
|> Task.mapError toError


save : Maybe IdToken -> InputItem -> Bool -> Task RequestError DiagramItem
bulkSave : Maybe IdToken -> List InputItem -> Bool -> Task RequestError (List DiagramItem)
bulkSave idToken inputs isPublic =
List.map
(save idToken isPublic)
inputs
|> Task.sequence


save : Maybe IdToken -> Bool -> InputItem -> Task RequestError DiagramItem
save idToken input isPublic =
Mutation.save input isPublic
Mutation.save isPublic input
|> Http.mutationRequest graphQLUrl
|> authHeaders idToken
|> Http.toTask
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ changePublicState : (Result DiagramItem DiagramItem -> msg) -> { isPublic : Bool
changePublicState msg { isPublic, item, session } =
Request.save
(Session.getIdToken session)
(DiagramItem.toInputItem item)
isPublic
(DiagramItem.toInputItem item)
|> Task.mapError (\_ -> item)
|> Task.attempt msg
|> Return.command
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/elm/Effect/Diagram.elm
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ saveToRemote msg { diagram, session, settings } =
Request.saveGist (Session.getIdToken session) accessToken (DiagramItem.toInputGistItem diagram) (Text.toString diagram.text)

_ ->
Request.save (Session.getIdToken session) (DiagramItem.toInputItem diagram) diagram.isPublic
Request.save (Session.getIdToken session) diagram.isPublic (DiagramItem.toInputItem diagram)
)
|> Task.attempt msg
|> Return.command
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1397,14 +1397,20 @@ processDiagramListMsg msg =
DiagramList.GotDiagrams (Err _) ->
showErrorMessage Message.messagEerrorOccurred

DiagramList.ImportComplete json ->
DiagramList.ImportDiagrams json ->
case DiagramItem.stringToList json of
Ok _ ->
showInfoMessage Message.messageImportCompleted

Err _ ->
showErrorMessage Message.messagEerrorOccurred

DiagramList.ImportedRemoteDiagrams (Ok _) ->
showInfoMessage Message.messageImportCompleted

DiagramList.ImportedRemoteDiagrams (Err _) ->
showErrorMessage Message.messagEerrorOccurred

_ ->
stopProgress

Expand Down
14 changes: 10 additions & 4 deletions frontend/src/elm/Models/Diagram/Item.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Models.Diagram.Item exposing
, empty
, encoder
, getId
, id
, isRemoteDiagram
, listToString
, listToValue
Expand Down Expand Up @@ -220,6 +221,11 @@ location =
Lens .location (\b a -> { a | location = b })


id : Lens DiagramItem (Maybe DiagramId)
id =
Lens .id (\b a -> { a | id = b })


stringToList : String -> Result D.Error (List DiagramItem)
stringToList json =
D.decodeString (D.list decoder) json
Expand All @@ -229,8 +235,8 @@ toInputGistItem : DiagramItem -> InputGistItem
toInputGistItem item =
{ id =
case item.id of
Just id ->
OptionalArgument.Present <| Graphql.Scalar.Id <| DiagramId.toString id
Just id_ ->
OptionalArgument.Present <| Graphql.Scalar.Id <| DiagramId.toString id_

Nothing ->
OptionalArgument.Absent
Expand All @@ -252,8 +258,8 @@ toInputItem : DiagramItem -> InputItem
toInputItem item =
{ id =
case item.id of
Just id ->
OptionalArgument.Present <| Graphql.Scalar.Id <| DiagramId.toString id
Just id_ ->
OptionalArgument.Present <| Graphql.Scalar.Id <| DiagramId.toString id_

Nothing ->
OptionalArgument.Absent
Expand Down
31 changes: 26 additions & 5 deletions frontend/src/elm/Page/List.elm
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ type Msg
| Export
| Import
| ImportFile File
| ImportComplete String
| ImportDiagrams String
| ImportedRemoteDiagrams (Result RequestError (List DiagramItem))
| ShowConfirmDialog DiagramItem


Expand Down Expand Up @@ -1011,17 +1012,37 @@ update model message =
Return.command <| Select.file [ "application/json" ] ImportFile

ImportFile file ->
Return.command <| Task.perform ImportComplete <| File.toString file
Return.command <| Task.perform ImportDiagrams <| File.toString file

ImportComplete json ->
ImportDiagrams json ->
DiagramItem.stringToList json
|> Result.toMaybe
|> Maybe.map
(\diagrams ->
Return.command <| importDiagram <| DiagramItem.listToValue diagrams
if Session.isSignedIn model.session then
Request.bulkSave (Session.getIdToken model.session)
(List.map
(\diagram ->
(DiagramItem.location.set (Just DiagramLocation.Remote) >> DiagramItem.id.set Nothing) diagram
|> DiagramItem.toInputItem
)
diagrams
)
False
|> Task.attempt ImportedRemoteDiagrams
|> Return.command

else
Return.command <| importDiagram <| DiagramItem.listToValue diagrams
)
|> Maybe.withDefault Return.zero

ImportedRemoteDiagrams (Ok _) ->
reload

ImportedRemoteDiagrams (Err _) ->
Return.zero

Export ->
case model.diagramList of
DiagramList.AllList (Success _) _ _ ->
Expand All @@ -1037,7 +1058,7 @@ update model message =
GotExportDiagrams (Ok diagrams) ->
case model.diagramList of
DiagramList.AllList (Success localDiagrams) _ _ ->
List.concat [ localDiagrams, diagrams ]
List.concat [ diagrams, localDiagrams ]
|> ListEx.uniqueBy .id
|> DiagramItem.listToString
|> Download.string "textusm.json" "application/json"
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/ts/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { type FirebaseOptions, initializeApp } from 'firebase/app';
import {
type AuthProvider,
signOut as firebaseSignOut,
signInWithRedirect,
signInWithPopup as firebaseSignInWithPopup,
GoogleAuthProvider,
GithubAuthProvider,
getAuth,
onAuthStateChanged as firebaseOnAuthStateChanged,
connectAuthEmulator,
type UserCredential,
} from 'firebase/auth';
import { getPerformance } from 'firebase/performance';

Expand Down Expand Up @@ -38,9 +38,9 @@ if (import.meta.env.DEV && process.env.FIREBASE_AUTH_EMULATOR_HOST) {
connectAuthEmulator(auth, `http://${process.env.FIREBASE_AUTH_EMULATOR_HOST}`);
}

export const signIn = async (provider: AuthProvider): Promise<void> =>
export const signIn = async (provider: AuthProvider): Promise<UserCredential> =>
new Promise((resolve, reject) => {
signInWithRedirect(auth, provider)
firebaseSignInWithPopup(auth, provider)
.then((result) => {
resolve(result);
})
Expand Down

0 comments on commit 14a899f

Please sign in to comment.