Show thumbnails

This commit is contained in:
towards-a-new-leftypol 2024-01-25 23:51:59 -05:00
parent 0a75e96f27
commit 57e1fe590e
6 changed files with 62 additions and 21 deletions

View File

@ -4,6 +4,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="postgrest-root" content="http://10.4.0.96:3000"> <meta name="postgrest-root" content="http://10.4.0.96:3000">
<meta name="postgrest-fetch-count" content="1000"> <meta name="postgrest-fetch-count" content="1000">
<meta name="media-root" content="http://10.4.0.1:8888">
<title>Chandlr</title> <title>Chandlr</title>
<link href="static/style.css" rel="stylesheet" /> <link href="static/style.css" rel="stylesheet" />
<script language="javascript" src="./dist/build/chandlr/chandlr.jsexe/rts.js"></script> <script language="javascript" src="./dist/build/chandlr/chandlr.jsexe/rts.js"></script>

@ -1 +1 @@
Subproject commit 9e9d7babe6352b2fdf19d4ab43a557c71ca2e2ff Subproject commit 3f420d3131eb0477b522103a582732a5ba365f19

View File

@ -9,14 +9,15 @@ module Component.CatalogGrid
, update , update
) where ) where
import Data.List (intercalate)
import Data.Maybe (maybeToList) import Data.Maybe (maybeToList)
import Data.JSString (append) import Data.Text (pack, Text)
import qualified Data.Text as T
import Data.JSString (append, JSString)
import Miso import Miso
( View, div_ , class_ , img_ , href_ , a_ ( View, div_ , class_ , img_ , href_ , a_
, src_ , title_ , strong_ , span_ , src_ , title_ , strong_ , span_
, p_ , br_ , id_ , Effect , noEff, width_ , p_ , id_ , Effect , noEff
, height_, text, rawHtml , text, rawHtml
) )
import Miso.String (toMisoString, MisoString) import Miso.String (toMisoString, MisoString)
@ -24,11 +25,15 @@ import Network.CatalogPostType (CatalogPost)
import qualified Network.CatalogPostType as CatalogPost import qualified Network.CatalogPostType as CatalogPost
data Model = Model data Model = Model
{ displayItems :: [ CatalogPost ] { display_items :: [ CatalogPost ]
, media_root :: MisoString
} deriving Eq } deriving Eq
initialModel :: Model initialModel :: JSString -> Model
initialModel = Model { displayItems = [] } initialModel media_root = Model
{ display_items = []
, media_root = toMisoString media_root
}
data Action = DisplayItems [ CatalogPost ] data Action = DisplayItems [ CatalogPost ]
@ -42,7 +47,7 @@ update
-> Action -> Action
-> Model -> Model
-> Effect a Model -> Effect a Model
update _ (DisplayItems xs) m = noEff (m { displayItems = xs }) update _ (DisplayItems xs) m = noEff (m { display_items = xs })
-- update _ _ m = noEff m -- update _ _ m = noEff m
view :: Interface a -> Model -> View a view :: Interface a -> Model -> View a
@ -53,12 +58,12 @@ view iface model =
[ class_ "threads" ] [ class_ "threads" ]
[ div_ [ div_
[ id_ "Grid" ] [ id_ "Grid" ]
(map gridItem (displayItems model)) (map (gridItem model) (display_items model))
] ]
] ]
gridItem :: CatalogPost -> View a gridItem :: Model -> CatalogPost -> View a
gridItem post = gridItem m post =
div_ div_
[ class_ "mix" ] [ class_ "mix" ]
[ div_ [ div_
@ -67,7 +72,7 @@ gridItem post =
[ href_ thread_url ] [ href_ thread_url ]
[ img_ [ img_
[ class_ "thread-image" [ class_ "thread-image"
, src_ "/a/thumb/1111111111111.png" , src_ thumb_url
, title_ ( toMisoString $ show $ CatalogPost.bump_time post ) , title_ ( toMisoString $ show $ CatalogPost.bump_time post )
] ]
] ]
@ -96,9 +101,28 @@ gridItem post =
post_count_str :: MisoString post_count_str :: MisoString
post_count_str = "R: " `append` (toMisoString $ CatalogPost.estimated_post_count post) `append` "+" post_count_str = "R: " `append` (toMisoString $ CatalogPost.estimated_post_count post) `append` "+"
thumb_url :: MisoString
thumb_url =
case mthumb_path of
-- TODO: what about embeds!?
Nothing -> "/static/default_thumbnail.png"
Just thumb_path -> (media_root m) `append` (toMisoString thumb_path)
mthumb_path :: Maybe Text
mthumb_path = do
file_name <- CatalogPost.file_name post
thumb_ext <- CatalogPost.file_thumb_extension post
return $
"/" <> CatalogPost.site_name post
<> "/" <> CatalogPost.pathpart post
<> "/" <> (pack $ show $ CatalogPost.board_thread_id post)
<> "/thumbnail_" <> file_name
<> "." <> thumb_ext
thread_url :: MisoString thread_url :: MisoString
thread_url = toMisoString $ intercalate "/" thread_url = toMisoString $ T.intercalate "/"
[ CatalogPost.site_name post [ CatalogPost.site_name post
, CatalogPost.pathpart post , CatalogPost.pathpart post
, show $ CatalogPost.board_thread_id post , pack $ show $ CatalogPost.board_thread_id post
] ]

View File

@ -0,0 +1,11 @@
module Component.ThreadView
( Model
) where
import Common.PostsType (Post)
data Model = Model
{ thread_id :: Integer
, thread_posts :: [ Post ]
, thread_loading :: Bool
} deriving Eq

View File

@ -63,9 +63,10 @@ initialActionFromRoute model uri = either (const NoAction) id routing_result
initialModel initialModel
:: JSString :: JSString
-> Int -> Int
-> JSString
-> Model -> Model
initialModel pgroot client_fetch_count = Model initialModel pgroot client_fetch_count media_root = Model
{ gridModel = Grid.initialModel { gridModel = Grid.initialModel media_root
, clientModel = Client.Model , clientModel = Client.Model
{ Client.pgApiRoot = pgroot { Client.pgApiRoot = pgroot
, Client.fetchCount = client_fetch_count , Client.fetchCount = client_fetch_count
@ -99,7 +100,10 @@ main = do
pg_fetch_count <- getMetadata "postgrest-fetch-count" >>= pg_fetch_count <- getMetadata "postgrest-fetch-count" >>=
return . maybe 1000 (read . fromJSString) return . maybe 1000 (read . fromJSString)
let initial_model = initialModel pg_api_root pg_fetch_count media_root <- getMetadata "media-root" >>=
return . maybe "undefined" id
let initial_model = initialModel pg_api_root pg_fetch_count media_root
startApp App startApp App
{ model = initial_model { model = initial_model

View File

@ -25,12 +25,13 @@ data CatalogPost = CatalogPost
, thread_id :: Int , thread_id :: Int
-- , post_count :: Int -- , post_count :: Int
, estimated_post_count :: Int , estimated_post_count :: Int
, site_name :: String , site_name :: Text
, pathpart :: String , pathpart :: Text
-- , site_id :: Int -- , site_id :: Int
, file_mimetype :: Maybe Text , file_mimetype :: Maybe Text
, file_illegal :: Maybe Bool , file_illegal :: Maybe Bool
-- , file_resolution :: Maybe Dimension -- , file_resolution :: Maybe Dimension
, file_sha256_hash :: Maybe Text , file_name :: Maybe Text
, file_extension :: Maybe Text , file_extension :: Maybe Text
, file_thumb_extension :: Maybe Text
} deriving (Show, Generic, FromJSON, ToJSON, Eq) } deriving (Show, Generic, FromJSON, ToJSON, Eq)