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
table <- getElementById w "table"
let table' = fromJust table
cont <- getElementById w "cont" cont <- getElementById w "cont"
let cont' = fromJust cont let cont' = return $ fromJust cont
cont' #+ [mkElement "table" # set UI.id_ "table" #+ rows iob b 0]
getBody w #+ [ delete table'
UI.div #. "container" # set UI.id_ "cont" # set children [] #+ [
UI.h1 #+ [string "Minesweeper"],
UI.h4 #+ [string "Jack Harley jharley@tcd.ie"],
mkElement "table" # set UI.id_ "grid" #+ rows iob b 0
]]
delete cont'
return cell return cell