Output.purs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. module LinkedIn.Output where
  2. import Prelude
  3. import Data.Either (Either)
  4. import Data.Generic.Rep (class Generic)
  5. import Data.List.Types (NonEmptyList)
  6. import Data.Show.Generic (genericShow)
  7. import Effect (Effect)
  8. import LinkedIn (run)
  9. import LinkedIn.Jobs.JobOffer as JO
  10. import LinkedIn.Page.JobOffer (JobOfferPage)
  11. import LinkedIn.Page.Projects (ProjectsPage)
  12. import LinkedIn.Page.Skills (SkillsPage)
  13. import LinkedIn.Page.WorkExperiences (WorkExperiencesPage)
  14. import LinkedIn.PageUrl (PageUrl(..))
  15. import LinkedIn.Profile.Project (Project)
  16. import LinkedIn.Profile.Skill (Skill)
  17. import LinkedIn.Profile.WorkExperience (WorkExperience)
  18. import Type.Proxy (Proxy(..))
  19. import Web.DOM (Document)
  20. -- Surely the best solution would be that "extract" functions directly return a value of type Output
  21. -- instead of quasi-repeating the type definitions here.
  22. -- We'll probably need a unique Output type to be able to send out a return value anyway.
  23. data Output =
  24. Projects (NonEmptyList Project)
  25. | Skills (NonEmptyList Skill)
  26. | WorkExperiences (NonEmptyList WorkExperience)
  27. | JobOffer JO.JobOffer
  28. derive instance Generic Output _
  29. instance Show Output where
  30. show = genericShow
  31. toPage ∷ Partial ⇒ PageUrl → Document → Effect (Either String Output)
  32. toPage ctx dom = case ctx of
  33. UrlProjects _ -> map (map Projects) $ run (Proxy :: Proxy ProjectsPage) dom
  34. UrlSkills _ -> map (map Skills) $ run (Proxy :: Proxy SkillsPage) dom
  35. UrlWorkExperience _ -> map (map WorkExperiences) $ run (Proxy :: Proxy WorkExperiencesPage) dom
  36. UrlJobOffer _ -> map (map JobOffer) $ run (Proxy :: Proxy JobOfferPage) dom