feat(pastes): add new page to show owned pastes
Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
		
							parent
							
								
									f0efa78b89
								
							
						
					
					
						commit
						ebd9f7f52c
					
				| @ -21,6 +21,10 @@ defmodule Ketbin.Pastes do | ||||
|     Repo.all(Paste) | ||||
|   end | ||||
| 
 | ||||
|   def list_pastes_by_user(user_id) do | ||||
|     Repo.all(from(p in Paste, where: p.belongs_to == ^user_id)) | ||||
|   end | ||||
| 
 | ||||
|   @doc """ | ||||
|   Gets a single paste. | ||||
| 
 | ||||
|  | ||||
| @ -134,4 +134,9 @@ defmodule KetbinWeb.PageController do | ||||
|         render(conn, "edit.html", paste: paste, changeset: changeset) | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def pastes(%{assigns: %{current_user: current_user}} = conn, _params) do | ||||
|     pastes = Pastes.list_pastes_by_user(current_user.id) | ||||
|     render(conn, "pastes.html", pastes: pastes) | ||||
|   end | ||||
| end | ||||
|  | ||||
| @ -18,6 +18,13 @@ defmodule KetbinWeb.Router do | ||||
|     plug :fetch_current_user | ||||
|   end | ||||
| 
 | ||||
|   # scope to ensure user is authenticated | ||||
|   scope "/", KetbinWeb do | ||||
|     pipe_through [:browser, :require_authenticated_user] | ||||
| 
 | ||||
|     get "/pastes", PageController, :pastes | ||||
|   end | ||||
| 
 | ||||
|   scope "/", KetbinWeb do | ||||
|     pipe_through :browser | ||||
| 
 | ||||
|  | ||||
| @ -20,6 +20,7 @@ function toggleDropdown() { | ||||
|             <div id="dropdown" class="hidden right-0 z-50 bg-[#313131] px-4 py-2"> | ||||
|                 <li><%= link "Settings", to: Routes.user_settings_path(@conn, :edit) %></li> | ||||
|                 <li><%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %></li> | ||||
|                 <li><%= link "My Pastes", to: Routes.page_path(@conn, :pastes) %></li> | ||||
|             </div> | ||||
|         </div> | ||||
| 	<% else %> | ||||
|  | ||||
							
								
								
									
										11
									
								
								lib/ketbin_web/templates/page/pastes.html.heex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								lib/ketbin_web/templates/page/pastes.html.heex
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| <div class="flex relative flex-col w-full h-full"> | ||||
|     <ul class="break-word py-4 h-full w-full overflow-y-auto"> | ||||
|         <%= for paste <- @pastes do %> | ||||
|             <li class="flex flex-row items-center justify-between"> | ||||
|                 <a href={ Routes.page_path(@conn, :show, paste) } class=""> | ||||
| https://katb.in/v/<%= paste.id %> | ||||
|                 </a> | ||||
|             </li>     | ||||
|         <% end %> | ||||
|     </ul> | ||||
| </div> | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user