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.h1 #+ [string "Minesweeper"],
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
@ -44,22 +44,19 @@ setup w = void $ do
cell iob b (r,c) = do
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
liftIO $ modifyIORef' iob $ \oldB -> uncover oldB (r,c)
b <- liftIO $ readIORef iob
cont <- getElementById w "cont"
let cont' = fromJust cont
table <- getElementById w "table"
let table' = fromJust table
getBody w #+ [
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
]]
cont <- getElementById w "cont"
let cont' = return $ fromJust cont
cont' #+ [mkElement "table" # set UI.id_ "table" #+ rows iob b 0]
delete cont'
delete table'
return cell