tangled
alpha
login
or
join now
oppi.li
/
gleam-ci-tests
forked from
lesbian.skin/website
0
fork
atom
not my website
0
fork
atom
overview
issues
pulls
pipelines
Remove dark mode handling from the model
lesbian.skin
2 years ago
e915d4e8
8ef10a59
+92
-78
2 changed files
expand all
collapse all
unified
split
src
ffi.mjs
website.gleam
+8
-5
src/ffi.mjs
···
2
2
return window.location.pathname
3
3
}
4
4
5
5
-
// TODO: Add localStorage as well
6
6
-
export function prefers_dark_mode() {
7
7
-
const matches = window.matchMedia('(prefers-color-scheme:dark)').matches
8
8
-
if (matches) {
5
5
+
export function init_theme() {
6
6
+
if (window.matchMedia('(prefers-color-scheme:dark)').matches) {
9
7
document.documentElement.classList.add("dark")
8
8
+
} else {
9
9
+
document.documentElement.classList.remove("dark")
10
10
}
11
11
-
return matches
11
11
+
}
12
12
+
13
13
+
export function is_dark_mode() {
14
14
+
return document.documentElement.classList.contains("dark")
12
15
}
13
16
14
17
export function switch_theme() {
+84
-73
src/website.gleam
···
30
30
current_route: Route,
31
31
posts: List(posts.Post(Msg)),
32
32
projects: List(projects.Project(Msg)),
33
33
-
dark_mode: Bool,
34
33
)
35
34
}
36
35
···
45
44
@external(javascript, "./ffi.mjs", "get_route")
46
45
fn do_get_route() -> String
47
46
48
48
-
@external(javascript, "./ffi.mjs", "prefers_dark_mode")
49
49
-
fn prefers_dark_mode() -> Bool
47
47
+
@external(javascript, "./ffi.mjs", "init_theme")
48
48
+
fn init_theme() -> Bool
49
49
+
50
50
+
@external(javascript, "./ffi.mjs", "is_dark_mode")
51
51
+
fn is_dark_mode() -> Bool
50
52
51
53
@external(javascript, "./ffi.mjs", "switch_theme")
52
54
fn do_switch_theme() -> Nil
···
75
77
current_route: get_route(),
76
78
projects: projects.all(),
77
79
posts: posts.all(),
78
78
-
dark_mode: prefers_dark_mode(),
79
80
),
80
80
-
modem.init(on_route_change),
81
81
+
{
82
82
+
init_theme()
83
83
+
modem.init(on_route_change)
84
84
+
},
81
85
)
82
86
}
83
87
···
105
109
Model(..model, current_route: route),
106
110
effect.none(),
107
111
)
108
108
-
ChangeDarkMode -> #(
109
109
-
Model(..model, dark_mode: !model.dark_mode),
110
110
-
switch_theme(),
111
111
-
)
112
112
+
ChangeDarkMode -> #(model, switch_theme())
112
113
DoneChangeDarkMode -> #(model, effect.none())
113
114
}
114
115
}
···
182
183
],
183
184
[
184
185
html.h1([attr.class("m-0")], [
185
185
-
case model.dark_mode {
186
186
+
case is_dark_mode() {
186
187
True -> element.text("🌕")
187
188
False -> element.text("☀️")
188
189
},
···
193
194
}
194
195
195
196
fn view_home(_model: Model) -> Element(Msg) {
196
196
-
html.div(
197
197
-
[
198
198
-
attr.class(
199
199
-
"drop-shadow-md text-xl p-4 mb-4 rounded-xl bg-gray-200 dark:bg-neutral-800 dark:text-neutral-200",
200
200
-
),
201
201
-
],
202
202
-
[
203
203
-
html.p([attr.class("mb-4")], [
204
204
-
element.text(
205
205
-
"Hi! I'm Naomi (or Mia), a trans girl from the UK who loves to code! I mostly make Minecraft mods, but have started
197
197
+
html.div([], [
198
198
+
html.div(
199
199
+
[
200
200
+
attr.class(
201
201
+
"drop-shadow-md text-xl p-4 mb-4 rounded-xl bg-gray-200 dark:bg-neutral-800 dark:text-neutral-200",
202
202
+
),
203
203
+
],
204
204
+
[
205
205
+
html.p([attr.class("mb-4")], [
206
206
+
element.text(
207
207
+
"Hi! I'm Naomi (or Mia), a trans girl from the UK who loves to code! I mostly make Minecraft mods, but have started
206
208
to begin other projects like ",
207
207
-
),
208
208
-
common.link("Sheetr", "https://sheetr.app/"),
209
209
-
element.text(" and "),
210
210
-
common.link("Lilypad", "https://codeberg.org/naomi/lilypad"),
211
211
-
element.text(
212
212
-
". Both projects are in their infancy, but I hope that they can both become useful to someone
209
209
+
),
210
210
+
common.link("Sheetr", "https://sheetr.app/"),
211
211
+
element.text(" and "),
212
212
+
common.link("Lilypad", "https://codeberg.org/naomi/lilypad"),
213
213
+
element.text(
214
214
+
". Both projects are in their infancy, but I hope that they can both become useful to someone
213
215
out there!",
214
214
-
),
215
215
-
]),
216
216
-
html.p([], [
217
217
-
element.text(
218
218
-
"I absolutely love learning new languages, so here is what I know:",
219
219
-
),
220
220
-
cluster.of(
221
221
-
html.div,
222
222
-
[attr.class("gap-4 sm:gap-20 flex flex-col sm:flex-row")],
223
223
-
[
224
224
-
ui.stack([], [
225
225
-
html.h3([attr.class("text-2xl underline")], [
226
226
-
element.text("Proficient"),
216
216
+
),
217
217
+
]),
218
218
+
html.p([], [
219
219
+
element.text(
220
220
+
"I absolutely love learning new languages, so here is what I know:",
221
221
+
),
222
222
+
cluster.of(
223
223
+
html.div,
224
224
+
[attr.class("gap-4 sm:gap-20 flex flex-col sm:flex-row")],
225
225
+
[
226
226
+
ui.stack([], [
227
227
+
html.h3([attr.class("text-2xl underline")], [
228
228
+
element.text("Proficient"),
229
229
+
]),
230
230
+
html.ul([attr.class("list-disc pl-8")], [
231
231
+
html.li([], [element.text("⭐ Gleam")]),
232
232
+
html.li([], [element.text("☕ Java")]),
233
233
+
html.li([], [element.text("📜 JavaScript")]),
234
234
+
html.li([], [element.text("🐍 Python")]),
235
235
+
html.li([], [element.text("❓mcfunction")]),
236
236
+
]),
227
237
]),
228
228
-
html.ul([attr.class("list-disc pl-8")], [
229
229
-
html.li([], [element.text("⭐ Gleam")]),
230
230
-
html.li([], [element.text("☕ Java")]),
231
231
-
html.li([], [element.text("📜 JavaScript")]),
232
232
-
html.li([], [element.text("🐍 Python")]),
233
233
-
html.li([], [element.text("❓mcfunction")]),
234
234
-
]),
235
235
-
]),
236
236
-
ui.stack([], [
237
237
-
html.h3([attr.class("text-2xl underline")], [
238
238
-
element.text("Learning"),
239
239
-
]),
240
240
-
html.ul([attr.class("list-disc pl-8")], [
241
241
-
html.li([], [element.text("🦀 Rust")]),
242
242
-
html.li([], [element.text("🟦 Go")]),
243
243
-
html.li([], [element.text("🎮 C#")]),
244
244
-
html.li([], [element.text("💀 C++")]),
245
245
-
]),
246
246
-
]),
247
247
-
ui.stack([], [
248
248
-
html.h3([attr.class("text-2xl underline")], [
249
249
-
element.text("Want to learn"),
238
238
+
ui.stack([], [
239
239
+
html.h3([attr.class("text-2xl underline")], [
240
240
+
element.text("Learning"),
241
241
+
]),
242
242
+
html.ul([attr.class("list-disc pl-8")], [
243
243
+
html.li([], [element.text("🦀 Rust")]),
244
244
+
html.li([], [element.text("🟦 Go")]),
245
245
+
html.li([], [element.text("🎮 C#")]),
246
246
+
html.li([], [element.text("💀 C++")]),
247
247
+
]),
250
248
]),
251
251
-
html.ul([attr.class("list-disc pl-8")], [
252
252
-
html.li([], [element.text("⚡ Zig")]),
253
253
-
html.li([], [element.text("♻️ Kotlin")]),
249
249
+
ui.stack([], [
250
250
+
html.h3([attr.class("text-2xl underline")], [
251
251
+
element.text("Want to learn"),
252
252
+
]),
253
253
+
html.ul([attr.class("list-disc pl-8")], [
254
254
+
html.li([], [element.text("⚡ Zig")]),
255
255
+
html.li([], [element.text("♻️ Kotlin")]),
256
256
+
]),
254
257
]),
255
255
-
]),
256
256
-
],
258
258
+
],
259
259
+
),
260
260
+
]),
261
261
+
// html.p([], [
262
262
+
// element.text("As of this coming September, I will be studying a BSc in Computer Games Programming @ "),
263
263
+
// common.link("Staffs", "https://staffs.ac.uk/")
264
264
+
// ])
265
265
+
],
266
266
+
),
267
267
+
html.div(
268
268
+
[
269
269
+
attr.class(
270
270
+
"drop-shadow-md text-xl p-4 mb-4 rounded-xl bg-gray-200 dark:bg-neutral-800 dark:text-neutral-200",
257
271
),
258
258
-
]),
259
259
-
// html.p([], [
260
260
-
// element.text("As of this coming September, I will be studying a BSc in Computer Games Programming @ "),
261
261
-
// common.link("Staffs", "https://staffs.ac.uk/")
262
262
-
// ])
263
263
-
],
264
264
-
)
272
272
+
],
273
273
+
[html.h1([attr.class("text-3xl m-0 text-pink-400")],[element.text("Repositories")])],
274
274
+
),
275
275
+
])
265
276
}
266
277
267
278
fn view_projects(model: Model) -> Element(Msg) {