Skip to content

Commit f643e66

Browse files
authored
Merge pull request #260 from citizennet/wenbo/API-3333/support-default-time
API-3333 Support Default Time
2 parents a20d3e2 + 3efa6bd commit f643e66

30 files changed

+3929
-3896
lines changed

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ PACKAGE_LOCK := $(ROOT_DIR)/package-lock.json
2525

2626
FORMAT_SRC_PURS_TIDY_STAMP := $(BUILD_DIR)/.format-src-purs-tidy-stamp
2727
FORMAT_TEST_PURS_TIDY_STAMP := $(BUILD_DIR)/.format-test-purs-tidy-stamp
28+
FORMAT_UI_GUIDE_PURS_TIDY_STAMP := $(BUILD_DIR)/.format-ui-guide-purs-tidy-stamp
2829

2930
FORMAT_DEPENDENCIES := \
3031
$(FORMAT_SRC_PURS_TIDY_STAMP) \
31-
$(FORMAT_TEST_PURS_TIDY_STAMP)
32+
$(FORMAT_TEST_PURS_TIDY_STAMP) \
33+
$(FORMAT_UI_GUIDE_PURS_TIDY_STAMP)
3234

3335
# Colors for printing
3436
CYAN := \033[0;36m
@@ -88,6 +90,10 @@ $(FORMAT_TEST_PURS_TIDY_STAMP): $(TEST_FILES) $(NODE_MODULES_STAMP) | $(BUILD)
8890
$(PURS_TIDY) $(PURS_TIDY_CMD) $(TEST_DIR)
8991
@touch $@
9092

93+
$(FORMAT_UI_GUIDE_PURS_TIDY_STAMP): $(TEST_FILES) $(NODE_MODULES_STAMP) | $(BUILD)
94+
$(PURS_TIDY) $(PURS_TIDY_CMD) $(UI_GUIDE_DIR)
95+
@touch $@
96+
9197
$(NODE_MODULES): $(PACKAGE_JSON) $(PACKAGE_LOCK)
9298
npm install
9399
touch $@
@@ -116,6 +122,10 @@ check-format-src: $(FORMAT_SRC_PURS_TIDY_STAMP) ## Validate formatting of the `s
116122
check-format-test: PURS_TIDY_CMD=check
117123
check-format-test: $(FORMAT_TEST_PURS_TIDY_STAMP) ## Validate formatting of the `test` directory
118124

125+
.PHONY: check-format-ui-guide
126+
check-format-ui-guide: PURS_TIDY_CMD=check
127+
check-format-ui-guide: $(FORMAT_UI-GUIDE_PURS_TIDY_STAMP) ## Validate formatting of the `test` directory
128+
119129
.PHONY: clean
120130
clean: $(CLEAN_DEPS) ## Remove all dependencies and build artifacts, starting with a clean slate
121131
rm -fr \
@@ -138,6 +148,10 @@ format-src: $(FORMAT_SRC_PURS_TIDY_STAMP) ## Format the `src` directory
138148
format-test: PURS_TIDY_CMD=format-in-place
139149
format-test: $(FORMAT_TEST_PURS_TIDY_STAMP) ## Format the `test` directory
140150

151+
.PHONY: format-ui-guide
152+
format-ui-guide: PURS_TIDY_CMD=format-in-place
153+
format-ui-guide: $(FORMAT_UI_GUIDE_PURS_TIDY_STAMP) ## Format the `test` directory
154+
141155
.PHONY: help
142156
help: $(BUILD_DIR)/help ## Display this help message
143157
@awk 'BEGIN {FS = ":.*?## "}; {printf "$(CYAN)%-30s$(RESET) %s\n", $$1, $$2}' $<

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "purescript-ocelot",
3-
"version": "0.34.2",
3+
"version": "0.35.0",
44
"private": true,
55
"scripts": {
66
"build-all": "make build",

src/DateTimePicker.purs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ type ComponentM m a = H.HalogenM State Action ChildSlots Output m a
5252
type ComponentRender m = State -> ComponentHTML m
5353

5454
type Input =
55-
{ disabled :: Boolean
55+
{ defaultTime :: Maybe Time
56+
, disabled :: Boolean
5657
, interval :: Maybe Interval
5758
, selection :: Maybe DateTime
5859
, targetDate :: Maybe (Year /\ Month)
@@ -79,6 +80,7 @@ type Slot = H.Slot Query Output
7980

8081
type State =
8182
{ date :: Maybe Date
83+
, defaultTime :: Maybe Time
8284
, disabled :: Boolean
8385
, interval :: Maybe Interval
8486
, targetDate :: Maybe (Year /\ Month)
@@ -110,17 +112,26 @@ handleAction = case _ of
110112
HandleDate msg -> case msg of
111113
DatePicker.SelectionChanged date' -> do
112114
state <- H.get
113-
raiseSelectionChanged state.interval date' state.time
114-
H.modify_ _ { date = date' }
115+
case state.defaultTime, state.time of
116+
Just defaultTime, Nothing -> do
117+
H.tell _timepicker unit $ TimePicker.SetSelection $ Just defaultTime
118+
H.modify_ _ { date = date', time = Just defaultTime }
119+
raiseSelectionChanged state.interval date' (Just defaultTime)
120+
_, _ -> do
121+
H.modify_ _ { date = date' }
122+
raiseSelectionChanged state.interval date' state.time
115123
_ -> H.raise $ DateOutput msg
116124
HandleTime msg -> case msg of
117125
TimePicker.SelectionChanged time' -> do
118126
state <- H.get
119-
raiseSelectionChanged state.interval state.date time'
120127
H.modify_ _ { time = time' }
128+
raiseSelectionChanged state.interval state.date time'
121129
_ -> H.raise $ TimeOutput msg
122130
Receive input -> do
123-
H.modify_ _ { interval = input.interval }
131+
H.modify_ _
132+
{ disabled = input.disabled
133+
, interval = input.interval
134+
}
124135

125136
handleQuery :: forall m a. Query a -> ComponentM m (Maybe a)
126137
handleQuery = case _ of
@@ -144,6 +155,7 @@ handleQuery = case _ of
144155
initialState :: Input -> State
145156
initialState input =
146157
{ date: input.selection <#> Date.DateTime.date
158+
, defaultTime: input.defaultTime
147159
, disabled: input.disabled
148160
, interval: input.interval
149161
, targetDate: input.targetDate
@@ -164,16 +176,22 @@ raiseSelectionChanged ::
164176
Maybe Date ->
165177
Maybe Time ->
166178
ComponentM m Unit
167-
raiseSelectionChanged mInterval mDate mTime = case mInterval of
168-
Nothing -> H.raise $ SelectionChanged mDateTime
169-
Just interval -> case mDateTime of
170-
Nothing -> H.raise $ SelectionChanged mDateTime
171-
Just dateTime
172-
| isWithinInterval interval dateTime -> H.raise $ SelectionChanged mDateTime
173-
| otherwise -> pure unit -- NOTE transient state during parent-child synchronization
179+
raiseSelectionChanged mInterval mDate mTime = case maybeSelection of
180+
Nothing -> pure unit
181+
Just selection -> case mInterval of
182+
Nothing -> H.raise $ SelectionChanged selection
183+
Just interval -> case selection of
184+
Nothing -> H.raise $ SelectionChanged selection
185+
Just dateTime
186+
| isWithinInterval interval dateTime -> H.raise $ SelectionChanged selection
187+
| otherwise -> pure unit -- NOTE transient state during parent-child synchronization
174188
where
175-
mDateTime :: Maybe DateTime
176-
mDateTime = DateTime <$> mDate <*> mTime
189+
maybeSelection :: Maybe (Maybe DateTime)
190+
maybeSelection = case mDate, mTime of
191+
Nothing, Nothing -> Just Nothing
192+
Nothing, Just _ -> Nothing
193+
Just _, Nothing -> Nothing
194+
Just date, Just time -> Just $ Just $ Date.DateTime.DateTime date time
177195

178196
render :: forall m. MonadAff m => ComponentRender m
179197
render state =

ui-guide/App/App.purs

Lines changed: 83 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,16 @@ instance showGroup :: Show Group where
6565
type HTML m = H.ComponentHTML Action Slots m
6666

6767
type Slots =
68-
( child :: H.Slot (Const Void) Void String )
68+
(child :: H.Slot (Const Void) Void String)
69+
6970
_child = Proxy :: Proxy "child"
7071

7172
-- | Takes stories config and mount element, and renders the storybook.
72-
runStorybook
73-
:: Stories Aff
74-
-> Array Group
75-
-> HTMLElement
76-
-> Aff Unit
73+
runStorybook ::
74+
Stories Aff ->
75+
Array Group ->
76+
HTMLElement ->
77+
Aff Unit
7778
runStorybook stories groups body = do
7879
app' <- runUI app { stories, groups } body
7980
void $ H.liftEffect $ hashes $ \_ next ->
@@ -84,7 +85,7 @@ type Input m =
8485
, groups :: Array Group
8586
}
8687

87-
app :: m. H.Component Query (Input m) Void m
88+
app :: forall m. H.Component Query (Input m) Void m
8889
app =
8990
H.mkComponent
9091
{ initialState
@@ -99,31 +100,32 @@ app =
99100
render :: State m -> HTML m
100101
render state =
101102
HH.body_
102-
[ HH.div
103-
[ HP.class_ $ HH.ClassName "min-h-screen" ]
104-
[ renderSidebar state
105-
, renderContainer state
103+
[ HH.div
104+
[ HP.class_ $ HH.ClassName "min-h-screen" ]
105+
[ renderSidebar state
106+
, renderContainer state
107+
]
106108
]
107-
]
108109

109110
renderContainer :: State m -> HTML m
110111
renderContainer state =
111112
HH.div
112-
[ HP.class_ $ HH.ClassName "md:ml-80" ]
113-
[ HH.div
114-
[ HP.class_ $ HH.ClassName "fixed w-full" ]
113+
[ HP.class_ $ HH.ClassName "md:ml-80" ]
115114
[ HH.div
116-
[ HP.class_ $ HH.ClassName "pin-t bg-white md:hidden relative border-b border-grey-light h-12 py-8 flex items-center" ]
117-
[ HH.a
118-
[ HP.class_ $ HH.ClassName "mx-auto inline-flex items-center"
119-
, HP.href "" ]
120-
[ HH.text "CitizenNet UI Guide" ]
121-
]
115+
[ HP.class_ $ HH.ClassName "fixed w-full" ]
116+
[ HH.div
117+
[ HP.class_ $ HH.ClassName "pin-t bg-white md:hidden relative border-b border-grey-light h-12 py-8 flex items-center" ]
118+
[ HH.a
119+
[ HP.class_ $ HH.ClassName "mx-auto inline-flex items-center"
120+
, HP.href ""
121+
]
122+
[ HH.text "CitizenNet UI Guide" ]
123+
]
124+
]
125+
, HH.div
126+
[ HP.class_ $ HH.ClassName "p-12 w-full container mx-auto" ]
127+
[ renderSlot state ]
122128
]
123-
, HH.div
124-
[ HP.class_ $ HH.ClassName "p-12 w-full container mx-auto" ]
125-
[ renderSlot state ]
126-
]
127129

128130
renderSlot :: State m -> HTML m
129131
renderSlot state =
@@ -135,71 +137,71 @@ app =
135137
renderSidebar :: State m -> HTML m
136138
renderSidebar state =
137139
Backdrop.backdrop
138-
[ HP.id "sidebar"
139-
, HP.classes
140-
( HH.ClassName <$>
141-
[ "hidden"
142-
, "fixed"
143-
, "pin-y"
144-
, "pin-l"
145-
, "overflow-y-auto"
146-
, "md:overflow-visible"
147-
, "scrolling-touch"
148-
, "md:scrolling-auto"
149-
, "w-4/5"
150-
, "md:w-full"
151-
, "md:max-w-xs"
152-
, "flex-none"
153-
-- , "border-r-2"
154-
-- , "border-grey-light"
155-
, "md:flex"
156-
, "flex-col"
157-
]
158-
)
159-
]
160-
[ HH.div
161-
[ HP.class_ $ HH.ClassName "flex-1 p-6 overflow-y-auto" ]
162-
[ HH.header_
163-
[ Format.heading
164-
[ HP.class_ $ HH.ClassName "flex" ]
165-
[ HH.img
166-
[ HP.class_ $ HH.ClassName "mr-2"
167-
, HP.src "https://citizennet.com/manager/images/logo.svg"
168-
]
169-
, HH.text "Ocelot"
140+
[ HP.id "sidebar"
141+
, HP.classes
142+
( HH.ClassName <$>
143+
[ "hidden"
144+
, "fixed"
145+
, "pin-y"
146+
, "pin-l"
147+
, "overflow-y-auto"
148+
, "md:overflow-visible"
149+
, "scrolling-touch"
150+
, "md:scrolling-auto"
151+
, "w-4/5"
152+
, "md:w-full"
153+
, "md:max-w-xs"
154+
, "flex-none"
155+
-- , "border-r-2"
156+
-- , "border-grey-light"
157+
, "md:flex"
158+
, "flex-col"
159+
]
160+
)
161+
]
162+
[ HH.div
163+
[ HP.class_ $ HH.ClassName "flex-1 p-6 overflow-y-auto" ]
164+
[ HH.header_
165+
[ Format.heading
166+
[ HP.class_ $ HH.ClassName "flex" ]
167+
[ HH.img
168+
[ HP.class_ $ HH.ClassName "mr-2"
169+
, HP.src "https://citizennet.com/manager/images/logo.svg"
170+
]
171+
, HH.text "Ocelot"
172+
]
173+
]
174+
, HH.nav
175+
[ HP.class_ $ HH.ClassName "text-base overflow-y-auto" ]
176+
(renderGroups state)
170177
]
171-
]
172-
, HH.nav
173-
[ HP.class_ $ HH.ClassName "text-base overflow-y-auto" ]
174-
(renderGroups state)
175178
]
176-
]
177179

178180
renderGroups :: State m -> Array (HTML m)
179181
renderGroups state =
180182
mapFlipped (M.toUnfoldable state.partitions) $ \(Tuple group stories) ->
181183
HH.div
182-
[ HP.class_ $ HH.ClassName "mb-6" ]
183-
[ Format.caption_
184-
[ HH.text $ show group ]
185-
, renderGroup state.route stories
186-
]
184+
[ HP.class_ $ HH.ClassName "mb-6" ]
185+
[ Format.caption_
186+
[ HH.text $ show group ]
187+
, renderGroup state.route stories
188+
]
187189

188190
renderGroup :: String -> Stories m -> HTML m
189191
renderGroup route stories =
190-
HH.ul [ HP.class_ $ HH.ClassName "list-reset" ] $
191-
mapFlipped (M.toUnfoldable stories) $ \(Tuple href { anchor }) ->
192-
HH.li
193-
[ HP.class_ $ HH.ClassName "mb-3" ]
194-
[ HH.a
195-
[ HP.classes $
196-
Format.linkClasses <>
197-
( if href == route then [ HH.ClassName "font-medium" ] else [] )
198-
, HP.href $ "#" <> unsafeEncodeURI href
199-
]
200-
[ HH.text anchor ]
201-
]
202-
192+
HH.ul [ HP.class_ $ HH.ClassName "list-reset" ]
193+
$ mapFlipped (M.toUnfoldable stories)
194+
$ \(Tuple href { anchor }) ->
195+
HH.li
196+
[ HP.class_ $ HH.ClassName "mb-3" ]
197+
[ HH.a
198+
[ HP.classes $
199+
Format.linkClasses <>
200+
(if href == route then [ HH.ClassName "font-medium" ] else [])
201+
, HP.href $ "#" <> unsafeEncodeURI href
202+
]
203+
[ HH.text anchor ]
204+
]
203205

204206
eval :: forall a. Query a -> H.HalogenM (State m) Action Slots Void m (Maybe a)
205207
eval (RouteChange route next) = do
@@ -209,7 +211,7 @@ app =
209211
----------
210212
-- Helpers
211213

212-
partitionByGroup :: m. Group -> Stories m -> Tuple Group (Stories m)
214+
partitionByGroup :: forall m. Group -> Stories m -> Tuple Group (Stories m)
213215
partitionByGroup g = Tuple g <<< M.filter (\{ group } -> group == g)
214216

215217
unsafeEncodeURI :: String -> String

0 commit comments

Comments
 (0)