浏览代码

Add a timespan component

theenglishway (time) 2 年之前
父节点
当前提交
b293458540
共有 3 个文件被更改,包括 19 次插入6 次删除
  1. 17 0
      lib/views/date.ex
  2. 1 3
      lib/views/education.ex
  3. 1 3
      lib/views/work.ex

+ 17 - 0
lib/views/date.ex

@@ -1,6 +1,23 @@
 defmodule CvGenView.Date do
   use Phoenix.Component
 
+  attr(:start_date, :string, required: true)
+  attr(:end_date, :string, default: nil)
+
+  def time_span(assigns) when assigns.start_date == assigns.end_date,
+    do: ~H"""
+    <div class="period">
+      <.date date={@start_date} />
+    </div>
+    """
+
+  def time_span(assigns),
+    do: ~H"""
+    <div class="period">
+      <.date date={@start_date} /> - <.date date={@end_date} />
+    </div>
+    """
+
   attr(:date, :any)
   attr(:rest, :global)
 

+ 1 - 3
lib/views/education.ex

@@ -11,9 +11,7 @@ defmodule CvGenView.Education do
   def education(assigns) do
     ~H"""
     <div class="education">
-      <div class="period">
-        <Date.date date={@start_date} /> - <Date.date date={@end_date} />
-      </div>
+      <Date.time_span start_date={@start_date} end_date={@end_date} />
       <div class="box">
         <h1><%= @institution %></h1>
         <h2><%= @area %></h2>

+ 1 - 3
lib/views/work.ex

@@ -16,9 +16,7 @@ defmodule CvGenView.Work do
       <div class="heading">
         <h1><%= @name %></h1>
         <span class="location"><%= @location %></span>
-        <div class="period">
-          <Date.date date={@start_date} /> - <Date.date date={@end_date} />
-        </div>
+        <Date.time_span start_date={@start_date} end_date={@end_date} />
       </div>
 
       <h1><%= @position %></h1>