Adapt code to i18n and date-fns changes.

This commit is contained in:
Andrey Antukh 2020-01-16 19:29:45 +01:00
parent d16d506a78
commit 0e35e33607
6 changed files with 32 additions and 33 deletions

View file

@ -300,7 +300,7 @@
:default-value (:name icon)}]
[:h3 {:on-double-click on-edit}
(:name icon)])
(str (tr "ds.uploaded-at" (dt/format (:created-at icon) "DD/MM/YYYY")))]]))
(str (tr "ds.uploaded-at" (dt/format (:created-at icon) "dd/MM/yyyy")))]]))
;; --- Grid

View file

@ -75,6 +75,12 @@
;; --- Grid Item
(mf/defc grid-item-metadata
[{:keys [modified-at]}]
(let [locale (i18n/use-locale)
time (dt/timeago modified-at {:locale locale})]
(str (t locale "ds.updated-at" time))))
(mf/defc grid-item
{:wrap [mf/wrap-memo]}
[{:keys [file] :as props}]
@ -105,9 +111,7 @@
;; :on-click on-edit
:default-value (:name file)}]
[:h3 (:name file)])
[:span.date
(str (tr "ds.updated-at" (dt/timeago (:modified-at file))))]]
[:& grid-item-metadata {:modified-at (:modified-at file)}]]
[:div.project-th-actions
;; [:div.project-th-icon.pages
;; i/page

View file

@ -47,7 +47,7 @@
transform (when (pos? rotation)
(str (-> (gmt/matrix)
(gmt/rotate* rotation center))))
(gmt/rotate rotation center))))
props {:id (str "shape-" id)
:class (classnames :move-cursor moving?)

View file

@ -38,7 +38,7 @@
(let [x-center (+ x1 (/ width 2))
y-center (+ y1 (/ height 2))
center (gpt/point x-center y-center)]
(gmt/rotate* mt rotation center)))
(gmt/rotate mt rotation center)))
(mf/defc icon-shape
[{:keys [shape] :as props}]

View file

@ -75,9 +75,6 @@
(rotate-matrix angle)
(translate-matrix (gpt/negate center)))))
;; TODO: temporal backward compatibility
(def rotate* rotate)
(defn scale
"Apply scale transformation to the matrix."
([m scale] (multiply m (scale-matrix scale)))

View file

@ -2,38 +2,36 @@
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2015-2020 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.time
(:require [vendor.datefns]
[cognitect.transit :as t]))
(:require
[vendor.datefns]
[goog.object :as gobj]))
(def ^:private dateFns js/dateFns)
(defn format
"Returns a string representation of the Instant
instance with optional `fmt` format parameter.
You can use `:iso` and `:unix` shortcuts as
format parameter.
You can read more about format tokens here:
http://momentjs.com/docs/#/displaying/format/
"
([v] (format v :iso))
([v fmt]
{:pre [(inst? v)]}
(case fmt
:offset (.getTime v)
:iso (.format dateFns v)
(.format dateFns v fmt))))
(def ^:private locales (gobj/get js/dateFns "locales"))
(defn now
"Return the current Instant."
[]
(js/Date.))
(defn format
([v fmt] (format v fmt nil))
([v fmt {:keys [locale]
:or {locale "default"}}]
(.format dateFns v fmt #js {:locale (gobj/get locales locale)})))
(defn timeago
[v]
{:pre [(inst? v)]}
(.distanceInWordsToNow dateFns v))
([v] (timeago v nil))
([v {:keys [seconds? locale]
:or {seconds? true
locale "default"}}]
(.formatDistanceToNow dateFns v
#js {:includeSeconds seconds?
:addSuffix true
:locale (gobj/get locales locale)})))