localize dates on bookmark timestamps
This commit is contained in:
parent
828a388b90
commit
3aa59305a5
|
@ -13,7 +13,7 @@ import Data.String (null, split, take) as S
|
|||
import Data.String.Pattern (Pattern(..))
|
||||
import Data.Symbol (SProxy(..))
|
||||
import Effect.Aff (Aff)
|
||||
import Globals (app', setFocus)
|
||||
import Globals (app', setFocus, toLocaleDateString)
|
||||
import Halogen as H
|
||||
import Halogen.HTML (HTML, a, br_, button, div, div_, form, input, label, span, text, textarea)
|
||||
import Halogen.HTML as HH
|
||||
|
@ -125,8 +125,8 @@ bmark b' =
|
|||
[ text tag ])
|
||||
(S.split (Pattern " ") bm.tags)
|
||||
|
||||
, a [ class_ "link f7 dib gray w4", href (linkToFilterSingle bm.slug) ]
|
||||
[ text shtime ]
|
||||
, a [ class_ "link f7 dib gray w4", href (linkToFilterSingle bm.slug), title shdatetime ]
|
||||
[ text shdate ]
|
||||
|
||||
-- links
|
||||
, whenH app.dat.isowner $ \_ ->
|
||||
|
@ -193,7 +193,8 @@ bmark b' =
|
|||
editField f = Just <<< BEditField <<< f
|
||||
linkToFilterSingle slug = fromNullableStr app.userR <> "/b:" <> slug
|
||||
linkToFilterTag tag = fromNullableStr app.userR <> "/t:" <> tag
|
||||
shtime = S.take 16 bm.time `append` "Z"
|
||||
shdate = toLocaleDateString bm.time
|
||||
shdatetime = S.take 16 bm.time `append` "Z"
|
||||
|
||||
tagid bm = show bm.bid <> "_tags"
|
||||
|
||||
|
@ -227,7 +228,9 @@ bmark b' =
|
|||
bm <- use _bm
|
||||
_edit_bm .= bm
|
||||
_edit .= e
|
||||
H.liftEffect $ whenM (pure e) (setFocus (tagid bm))
|
||||
H.liftEffect $
|
||||
when e
|
||||
(setFocus (tagid bm))
|
||||
|
||||
-- | Update Form Field
|
||||
handleAction (BEditField f) = do
|
||||
|
|
|
@ -36,14 +36,6 @@ exports._createFormArray = function(formElement) {
|
|||
return Array.from(new FormData(formElement));
|
||||
}
|
||||
|
||||
exports._getDataAttribute = function(name, el) {
|
||||
return el.dataset[name];
|
||||
}
|
||||
|
||||
exports._setDataAttribute = function(name, value, el) {
|
||||
return el.dataset[name] = value;
|
||||
}
|
||||
|
||||
exports._moment8601 = function(tuple, s) {
|
||||
var m = moment(s, moment.ISO_8601);
|
||||
var s1 = m.fromNow();
|
||||
|
@ -69,3 +61,8 @@ exports._closeWindow = function (window) {
|
|||
exports._setFocus = function(elemId) {
|
||||
document.getElementById(elemId).focus();
|
||||
};
|
||||
|
||||
|
||||
exports._toLocaleDateString = function(dateString) {
|
||||
return new Date(dateString).toLocaleDateString(undefined, {dateStyle: 'medium'})
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
module Globals where
|
||||
|
||||
import Data.Function.Uncurried
|
||||
|
||||
import Data.Maybe (Maybe(..))
|
||||
import Data.Nullable (Nullable, toMaybe)
|
||||
import Data.Newtype (class Newtype)
|
||||
import Data.Nullable (Nullable)
|
||||
import Data.Tuple (Tuple(..))
|
||||
import Effect (Effect)
|
||||
import Data.Function.Uncurried
|
||||
import Effect.Uncurried
|
||||
import Model (Bookmark)
|
||||
import Prelude (Unit, pure, ($))
|
||||
import Web.DOM (Element, Node)
|
||||
import Prelude
|
||||
import Web.DOM (Node)
|
||||
import Web.HTML (HTMLElement, HTMLFormElement, Window)
|
||||
import Web.XHR.FormData (FormData)
|
||||
import Data.Newtype (class Newtype)
|
||||
|
||||
type App =
|
||||
{ csrfHeaderName :: String
|
||||
|
@ -36,30 +36,30 @@ foreign import _app :: Fn0 App
|
|||
app' :: Unit -> App
|
||||
app' _ = runFn0 _app
|
||||
|
||||
foreign import _closest :: forall a. Fn4 (a -> Maybe a) (Maybe a) String Node (Maybe Node)
|
||||
foreign import _closest :: forall a. EffectFn4 (a -> Maybe a) (Maybe a) String Node (Maybe Node)
|
||||
|
||||
closest :: String -> Node -> Effect (Maybe Node)
|
||||
closest selector node = pure $ runFn4 _closest Just Nothing selector node
|
||||
closest selector node = runEffectFn4 _closest Just Nothing selector node
|
||||
|
||||
foreign import _moment8601 :: Fn2 (String -> String -> Tuple String String) String (Tuple String String)
|
||||
foreign import _moment8601 :: EffectFn2 (String -> String -> Tuple String String) String (Tuple String String)
|
||||
|
||||
moment8601 :: String -> Effect (Tuple String String)
|
||||
moment8601 s = pure $ runFn2 _moment8601 Tuple s
|
||||
moment8601 s = runEffectFn2 _moment8601 Tuple s
|
||||
|
||||
foreign import _mmoment8601 :: forall a. Fn4 (a -> Maybe a) (Maybe a) (String -> String -> Tuple String String) String (Maybe (Tuple String String))
|
||||
|
||||
mmoment8601 :: String -> Maybe (Tuple String String)
|
||||
mmoment8601 s = runFn4 _mmoment8601 Just Nothing Tuple s
|
||||
|
||||
foreign import _innerHtml :: Fn1 HTMLElement String
|
||||
foreign import _innerHtml :: EffectFn1 HTMLElement String
|
||||
|
||||
innerHtml :: HTMLElement -> Effect String
|
||||
innerHtml n = pure $ runFn1 _innerHtml n
|
||||
innerHtml n = runEffectFn1 _innerHtml n
|
||||
|
||||
foreign import _setInnerHtml :: Fn2 String HTMLElement HTMLElement
|
||||
foreign import _setInnerHtml :: EffectFn2 String HTMLElement HTMLElement
|
||||
|
||||
setInnerHtml :: String -> HTMLElement -> Effect HTMLElement
|
||||
setInnerHtml c n = pure $ runFn2 _setInnerHtml c n
|
||||
setInnerHtml c n = runEffectFn2 _setInnerHtml c n
|
||||
|
||||
foreign import _createFormData :: Fn1 HTMLFormElement FormData
|
||||
|
||||
|
@ -77,26 +77,21 @@ foreign import _createFormArray :: Fn1 HTMLFormElement (Array (Array String))
|
|||
createFormArray :: HTMLFormElement -> (Array (Array String))
|
||||
createFormArray f = runFn1 _createFormArray f
|
||||
|
||||
foreign import _getDataAttribute :: Fn2 String Element (Nullable String)
|
||||
|
||||
getDataAttribute :: String -> Element -> Effect (Maybe String)
|
||||
getDataAttribute k n = pure $ toMaybe $ runFn2 _getDataAttribute k n
|
||||
|
||||
foreign import _setDataAttribute :: Fn3 String String Element Unit
|
||||
|
||||
setDataAttribute :: String -> String -> Element -> Effect Unit
|
||||
setDataAttribute k v n = pure $ runFn3 _setDataAttribute k v n
|
||||
|
||||
foreign import _closeWindow :: Fn1 Window Unit
|
||||
foreign import _closeWindow :: EffectFn1 Window Unit
|
||||
|
||||
closeWindow :: Window -> Effect Unit
|
||||
closeWindow win = pure $ runFn1 _closeWindow win
|
||||
closeWindow win = runEffectFn1 _closeWindow win
|
||||
|
||||
newtype RawHTML = RawHTML String
|
||||
|
||||
derive instance newtypeRawHTML :: Newtype RawHTML _
|
||||
|
||||
foreign import _setFocus :: Fn1 String Unit
|
||||
foreign import _setFocus :: EffectFn1 String Unit
|
||||
|
||||
setFocus :: String -> Effect Unit
|
||||
setFocus s = pure $ runFn1 _setFocus s
|
||||
setFocus s = runEffectFn1 _setFocus s
|
||||
|
||||
foreign import _toLocaleDateString :: Fn1 String String
|
||||
|
||||
toLocaleDateString :: String -> String
|
||||
toLocaleDateString s = runFn1 _toLocaleDateString s
|
||||
|
|
|
@ -143,3 +143,6 @@ maybeH m k = maybe (HH.text "") k m
|
|||
|
||||
fromNullableStr :: Nullable String -> String
|
||||
fromNullableStr = fromMaybe "" <<< toMaybe
|
||||
|
||||
monthNames :: Array String
|
||||
monthNames = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]
|
||||
|
|
2
static/js/app.min.js
vendored
2
static/js/app.min.js
vendored
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Loading…
Reference in a new issue