Code cleanup

This commit is contained in:
Jack Harley 2021-01-28 23:42:48 +00:00
parent a5859ff737
commit 05eeaae01a
1 changed files with 8 additions and 11 deletions

View File

@ -32,7 +32,7 @@ setup w = void $ do
UI.div #. "container" # set UI.id_ "cont" #+ [ UI.div #. "container" # set UI.id_ "cont" #+ [
UI.h1 #+ [string "Minesweeper"], UI.h1 #+ [string "Minesweeper"],
UI.h4 #+ [string "Jack Harley jharley@tcd.ie"], UI.h4 #+ [string "Jack Harley jharley@tcd.ie"],
mkElement "table" # set UI.id_ "grid" #+ rows iob b 0 mkElement "table" # set UI.id_ "table" #+ rows iob b 0
]] ]]
where where
@ -44,22 +44,19 @@ setup w = void $ do
cell iob b (r,c) = do cell iob b (r,c) = do
cell <- mkElement "td" #. (squareBgColour b (r,c) ++ " " ++ squareTextColour b (r,c)) cell <- mkElement "td" #. (squareBgColour b (r,c) ++ " " ++ squareTextColour b (r,c))
#+ [string $ squareAscii b (r,c)] #+ [string $ squareAscii b (r,c)]
on UI.click cell $ \_ -> do on UI.click cell $ \_ -> do
liftIO $ modifyIORef' iob $ \oldB -> uncover oldB (r,c) liftIO $ modifyIORef' iob $ \oldB -> uncover oldB (r,c)
b <- liftIO $ readIORef iob b <- liftIO $ readIORef iob
cont <- getElementById w "cont" table <- getElementById w "table"
let cont' = fromJust cont let table' = fromJust table
getBody w #+ [ cont <- getElementById w "cont"
UI.div #. "container" # set UI.id_ "cont" # set children [] #+ [ let cont' = return $ fromJust cont
UI.h1 #+ [string "Minesweeper"], cont' #+ [mkElement "table" # set UI.id_ "table" #+ rows iob b 0]
UI.h4 #+ [string "Jack Harley jharley@tcd.ie"],
mkElement "table" # set UI.id_ "grid" #+ rows iob b 0
]]
delete cont' delete table'
return cell return cell