Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#22] Add contacts #96

Merged
merged 12 commits into from
Sep 12, 2018
Merged

[#22] Add contacts #96

merged 12 commits into from
Sep 12, 2018

Conversation

willbasky
Copy link
Contributor

@willbasky willbasky commented Sep 6, 2018

Resolves #22


This change is Reviewable

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r1.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @willbasky)


ff-core/lib/FF.hs, line 204 at r1 (raw file):

    -> Maybe Day
    -> Maybe Tracked
    -> m Note

?


ff-core/lib/FF.hs, line 209 at r1 (raw file):

    noteText     <- rgaFromText text
    noteStart    <- LWW.initialize start
    noteEnd      <- LWW.initialize end

?


ff-core/lib/FF/Options.hs, line 66 at r1 (raw file):

    }

newtype Contact = ContactShow (Maybe ContactCommand)

Show?


ff-core/lib/FF/Types.hs, line 57 at r1 (raw file):

data Contact = Contact
    { contactStatus :: LWW Status 

Контакт не может быть вики.


ff-core/lib/FF/Types.hs, line 85 at r1 (raw file):

instance Semilattice Note

instance Semilattice Contact

Лучше сгруппировать инстансы по типам, а не по классам.


ff-core/lib/FF/Types.hs, line 131 at r1 (raw file):

    , csTotal :: Natural
    }
    deriving (Eq, Show)

Объедини в один тип с параметром, потому что всё одинаковое. Sample NoteView, Sample ContactView


ff-core/lib/FF/Types.hs, line 205 at r1 (raw file):

    { cvId     = contactId
    , cvStatus = LWW.query contactStatus
    , cvName   = Text.pack $ RGA.toString contactName

rgaToText

@willbasky
Copy link
Contributor Author


ff-core/lib/FF.hs, line 204 at r1 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

?

?

@willbasky
Copy link
Contributor Author


ff-core/lib/FF.hs, line 204 at r1 (raw file):

Previously, willbasky (Vladislav Sabanov) wrote…

?

Длинно было.

@willbasky
Copy link
Contributor Author


ff-core/lib/FF/Options.hs, line 66 at r1 (raw file):

ContactShow

показывает все контакты

@willbasky
Copy link
Contributor Author


ff-core/lib/FF/Types.hs, line 57 at r1 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

Контакт не может быть вики.

А что значит тут вики?

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r2.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @cblp and @willbasky)


ff-core/lib/FF/Options.hs, line 66 at r1 (raw file):

Previously, willbasky (Vladislav Sabanov) wrote…
ContactShow

показывает все контакты

Удалять — это тоже показывать?


ff-core/lib/FF/Types.hs, line 57 at r1 (raw file):

Previously, willbasky (Vladislav Sabanov) wrote…

А что значит тут вики?

У типа Status есть значение Wiki. Оно имеет смысл только для заметок, но не для контактов.

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @willbasky)


ff-core/lib/FF/Options.hs, line 66 at r3 (raw file):

    }

newtype Contact = Contact (Maybe ContactCommand)

Бессмысленная обёртка. Можно в CmdContact класть сразу Maybe ContactCommand

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @willbasky)


ff-core/lib/FF/Types.hs, line 41 at r3 (raw file):

import           FF.Types.Internal (noteJsonOptions)

data StatusNote = Active | Archived | Deleted | Wiki

Как-то некрасивенько. Added и Removed имеют абсолютно такой же смысл, как Active и Deleted. И Archived тоже полезно бы иметь.

Предлагаю такое:

data Status = Active | Archived | Deleted
data Wiki = Wiki
...
, contactStatus :: Status
...
, noteStatus :: Either Wiki Status

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @willbasky)


ff-core/lib/FF/Types.hs, line 41 at r3 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

Как-то некрасивенько. Added и Removed имеют абсолютно такой же смысл, как Active и Deleted. И Archived тоже полезно бы иметь.

Предлагаю такое:

data Status = Active | Archived | Deleted
data Wiki = Wiki
...
, contactStatus :: Status
...
, noteStatus :: Either Wiki Status

всё под LWW, конечно

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r4.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @willbasky)


ff/Main.hs, line 179 at r4 (raw file):

cmdContact :: Maybe Contact -> Storage ()
cmdContact mCommand = case mCommand of

\case

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r5.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r6.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r7.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @willbasky)


ff-core/lib/FF/Types.hs, line 54 at r7 (raw file):

      where
        st = case ns of
            TaskStatus s -> show s

s/show/toJSON/


ff-core/lib/FF/Types.hs, line 55 at r7 (raw file):

        st = case ns of
            TaskStatus s -> show s
            _ -> show Wiki

вместо _ лучше явно написать Wiki для устойчивости к будущим изменениям


ff-core/lib/FF/Types.hs, line 59 at r7 (raw file):

instance FromJSON NoteStatus where
    parseJSON = withText "NoteStatus" $ \x -> do
        let s = case x of

можно не вводить s, а сразу написать return $ case ...


ff-core/lib/FF/Types.hs, line 64 at r7 (raw file):

                "Archived" -> TaskStatus Archived
                "Deleted"  -> TaskStatus Deleted
                _          -> error "Not NoteStatus type"

s/error/fail/


ff-core/lib/FF/Types.hs, line 65 at r7 (raw file):

                "Deleted"  -> TaskStatus Deleted
                _          -> error "Not NoteStatus type"
        return s

s/return/pure/


ff-test/test/ArbitraryOrphans.hs, line 25 at r7 (raw file):

instance Arbitrary NoteStatus where
    arbitrary = TaskStatus <$> arbitrary

такой генератор никогда не сгенерит Wiki

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @willbasky)


ff-core/lib/FF/Types.hs, line 63 at r7 (raw file):

                "Active"   -> TaskStatus Active
                "Archived" -> TaskStatus Archived
                "Deleted"  -> TaskStatus Deleted

эти 3 строчки можно сократить до TaskStatus <$> parseJSON v

@willbasky
Copy link
Contributor Author


ff-core/lib/FF/Types.hs, line 54 at r7 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

s/show/toJSON/

Что означает такой комментарий?

@willbasky
Copy link
Contributor Author


ff-core/lib/FF/Types.hs, line 63 at r7 (raw file):

TaskStatus <$> parseJSON v

Тогда будет ошибка

Couldn't match expected type ‘NoteStatus’
              with actual type ‘aeson-1.3.1.1:Data.Aeson.Types.Internal.Parser
                                  NoteStatus’

@willbasky
Copy link
Contributor Author


ff-core/lib/FF/Types.hs, line 63 at r7 (raw file):

v

Ок, даже если заменить, то откуда брать v обощенную и именно содержащую нужные строки, а не любые? Я сделал так сейчас

instance FromJSON NoteStatus where
    parseJSON = withText "NoteStatus" $ \case
        "Wiki"     -> parseJSON "Wiki"
        "Active"   -> TaskStatus <$> parseJSON "Active"
        "Archived" -> TaskStatus <$> parseJSON "Archived"
        "Deleted"  -> TaskStatus <$> parseJSON "Deleted"
        _          -> fail "Not NoteStatus type"

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 8 of 10 files reviewed, 6 unresolved discussions (waiting on @cblp and @willbasky)


ff-core/lib/FF/Types.hs, line 54 at r7 (raw file):

Previously, willbasky (Vladislav Sabanov) wrote…

Что означает такой комментарий?

заменить одно на другое


ff-core/lib/FF/Types.hs, line 53 at r8 (raw file):

    toJSON = \case
        TaskStatus s -> toJSON s
        Wiki -> toJSON Wiki

зависнет. вот здесь как раз настоящую реализацию надо написать

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 8 of 10 files reviewed, 3 unresolved discussions (waiting on @cblp and @willbasky)


ff-core/lib/FF/Types.hs, line 63 at r7 (raw file):

Previously, willbasky (Vladislav Sabanov) wrote…

v

Ок, даже если заменить, то откуда брать v обощенную и именно содержащую нужные строки, а не любые? Я сделал так сейчас

instance FromJSON NoteStatus where
    parseJSON = withText "NoteStatus" $ \case
        "Wiki"     -> parseJSON "Wiki"
        "Active"   -> TaskStatus <$> parseJSON "Active"
        "Archived" -> TaskStatus <$> parseJSON "Archived"
        "Deleted"  -> TaskStatus <$> parseJSON "Deleted"
        _          -> fail "Not NoteStatus type"

попробуй parseJSON v = TaskStatus <$> parseJSON v и подумай, куда здесь вставить Wiki

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r8.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @willbasky)


ff-test/test/ArbitraryOrphans.hs, line 25 at r8 (raw file):

instance Arbitrary NoteStatus where
    arbitrary = oneof [TaskStatus <$> arbitrary, arbitrary]

arbitrary @NoteStatus вызывает arbitrary @Status, а потом arbitrary @NoteStatus, то есть себя. зависнет

@willbasky
Copy link
Contributor Author


ff-test/test/ArbitraryOrphans.hs, line 25 at r7 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

такой генератор никогда не сгенерит Wiki

А каким образом складывать arbitrary для типов, у которых значения суммы?
Подобные вещи не проканывают, тест виснит:

arbitrary = elements [TaskStatus Active, TaskStatus Archived, TaskStatus Deleted, Wiki]

@willbasky
Copy link
Contributor Author


ff-test/test/ArbitraryOrphans.hs, line 25 at r7 (raw file):

Previously, willbasky (Vladislav Sabanov) wrote…

А каким образом складывать arbitrary для типов, у которых значения суммы?
Подобные вещи не проканывают, тест виснит:

arbitrary = elements [TaskStatus Active, TaskStatus Archived, TaskStatus Deleted, Wiki]

так тоже виснит

arbitrary = oneof [TaskStatus <$> arbitrary, pure Wiki]

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @cblp and @willbasky)


ff-test/test/ArbitraryOrphans.hs, line 25 at r7 (raw file):

Previously, willbasky (Vladislav Sabanov) wrote…

так тоже виснит

arbitrary = oneof [TaskStatus <$> arbitrary, pure Wiki]

Оба варианта правильные, зависает в другом месте.

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @willbasky)


ff-core/lib/FF/Types.hs, line 144 at r8 (raw file):

    deriving (Eq, Show)

type SampleContact = Sample ContactView

ContactSample


ff-core/lib/FF/Types.hs, line 146 at r8 (raw file):

type SampleContact = Sample ContactView

type SampleNote = Sample NoteView

NoteSample


ff-core/lib/FF/Types.hs, line 179 at r8 (raw file):

taskMode :: Day -> NoteView -> TaskMode
taskMode today NoteView { start, end } = case end of

лишние изменения в форматировании. прогнал brittany?


ff-core/lib/FF/Types.hs, line 181 at r8 (raw file):

taskMode today NoteView { start, end } = case end of
    Nothing | start <= today -> Actual
            | otherwise      -> starting start today

лишние изменения в форматировании. прогнал brittany?


ff-core/lib/FF/UI.hs, line 116 at r8 (raw file):

            , ["| end"      <+> pshow @Day e | Just e <- [end]]
            ]
        ++  [ "| tracking"  <+> strictText trackedUrl

лишние изменения в форматировании. прогнал brittany?


ff-test/test/ArbitraryOrphans.hs, line 4 at r8 (raw file):

module ArbitraryOrphans
    ()

лишние изменения в форматировании. прогнал brittany?

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @cblp and @willbasky)


ff-test/test/ArbitraryOrphans.hs, line 25 at r7 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

Оба варианта правильные, зависает в другом месте.

я даже написал комментарий о зависании в том месте

@willbasky
Copy link
Contributor Author


ff-core/lib/FF/Types.hs, line 179 at r8 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

лишние изменения в форматировании. прогнал brittany?

нее, это stylish-haskell шалил.

@willbasky
Copy link
Contributor Author


ff-core/lib/FF/UI.hs, line 116 at r8 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

лишние изменения в форматировании. прогнал brittany?

не вижу, где тут?

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @willbasky and @cblp)


ff-core/lib/FF/UI.hs, line 116 at r8 (raw file):

Previously, willbasky (Vladislav Sabanov) wrote…

не вижу, где тут?

https://github.com/ff-notes/ff/pull/96/files?utf8=✓&diff=unified#diff-47b8ca6074ea5df4616278d21d47162fL97

@willbasky
Copy link
Contributor Author


ff-core/lib/FF/Types.hs, line 53 at r8 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

зависнет. вот здесь как раз настоящую реализацию надо написать

По какой причине здесь зависает?

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @willbasky and @cblp)


ff-core/lib/FF/Types.hs, line 53 at r8 (raw file):

Previously, willbasky (Vladislav Sabanov) wrote…

По какой причине здесь зависает?

toJSON Wiki вычисляется через toJSON Wiki, то есть через себя

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r9.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @willbasky)


ff-core/lib/FF/Types.hs, line 52 at r9 (raw file):

instance ToJSON NoteStatus where
    toJSON (TaskStatus a) = toJSON a
    toJSON _ = String "Wiki"

Следует явно указать Wiki в аргументе для определённости и устойчивости к будущим изменениям (future-proof)


ff-core/lib/FF/Types.hs, line 57 at r9 (raw file):

    parseJSON v = case v of
        "Wiki" -> pure Wiki
        _ -> TaskStatus <$> parseJSON v

Идеально!

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @willbasky)


ff-core/lib/FF/Types.hs, line 52 at r9 (raw file):

Previously, cblp (Yuriy Syrovetskiy) wrote…

Следует явно указать Wiki в аргументе для определённости и устойчивости к будущим изменениям (future-proof)

Ещё мне больше нравится \case, но это вкусовщина, можно и так оставить.

Copy link
Member

@cblp cblp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r10.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@cblp cblp merged commit 6059167 into ff-notes:master Sep 12, 2018
@willbasky willbasky deleted the willbasky/22-contacts branch September 12, 2018 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants