index.astro 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. ---
  2. import Layout from "../layouts/Layout.astro";
  3. import Taskbar from "../components/taskbar.astro";
  4. import App from "../components/app.astro";
  5. import Aboutme from "../components/aboutme.astro";
  6. import Redirect from "../components/redirect.astro";
  7. import Contact from "../components/contact.astro";
  8. import Pgp from "../components/pgp.astro";
  9. import Projects from "../components/projects.astro";
  10. // Projects
  11. import Summize from "../components/projects/summize.astro";
  12. import Notion from "../components/projects/notion.astro";
  13. import Imdb from "../components/projects/imdb.astro";
  14. import "../styles/global.css";
  15. import me from "../assets/apps/me.png";
  16. import github from "../assets/apps/github.png";
  17. import pastwork from "../assets/apps/pastWork.png";
  18. import projects from "../assets/apps/projects.png";
  19. import blog from "../assets/apps/blog.png";
  20. import contact from "../assets/apps/contact.png";
  21. import pgp from "../assets/apps/pgp.png";
  22. function dragElement(elmnt) {
  23. var pos1 = 0,
  24. pos2 = 0,
  25. pos3 = 0,
  26. pos4 = 0;
  27. if (document.getElementById(elmnt.id + "header")) {
  28. // If present, the header is where you move the DIV from:
  29. document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
  30. document.getElementById(elmnt.id + "header").ontouchstart = dragMouseDown;
  31. } else {
  32. // Otherwise, move the DIV from anywhere inside the DIV:
  33. elmnt.onmousedown = dragMouseDown;
  34. elmnt.ontouchstart = dragMouseDown;
  35. }
  36. function dragMouseDown(e) {
  37. // e.preventDefault();
  38. raiseUpSpec(elmnt.id);
  39. // Get the initial touch point for touch events
  40. if (e.type == "touchstart") {
  41. pos3 = e.touches[0].clientX;
  42. pos4 = e.touches[0].clientY;
  43. } else {
  44. pos3 = e.clientX;
  45. pos4 = e.clientY;
  46. }
  47. document.onmouseup = closeDragElement;
  48. document.ontouchend = closeDragElement;
  49. document.onmousemove = elementDrag;
  50. document.ontouchmove = elementDrag;
  51. }
  52. function elementDrag(e) {
  53. // e.preventDefault();
  54. if (e.type == "touchmove") {
  55. // Calculate the new cursor position for touch
  56. pos1 = pos3 - e.touches[0].clientX;
  57. pos2 = pos4 - e.touches[0].clientY;
  58. pos3 = e.touches[0].clientX;
  59. pos4 = e.touches[0].clientY;
  60. } else {
  61. // Calculate the new cursor position for mouse
  62. pos1 = pos3 - e.clientX;
  63. pos2 = pos4 - e.clientY;
  64. pos3 = e.clientX;
  65. pos4 = e.clientY;
  66. }
  67. // Set the element's new position
  68. elmnt.style.top = elmnt.offsetTop - pos2 + "px";
  69. elmnt.style.left = elmnt.offsetLeft - pos1 + "px";
  70. }
  71. function closeDragElement() {
  72. // Stop moving when mouse button or touch is released
  73. document.onmouseup = null;
  74. document.ontouchend = null;
  75. document.onmousemove = null;
  76. document.ontouchmove = null;
  77. }
  78. }
  79. /** Raise up window with given ID */
  80. function raiseUpSpec(id: string) {
  81. // console.log("raising ", id);
  82. let els = document.getElementsByClassName("window");
  83. let elArray = Array.from(els as HTMLCollectionOf<HTMLElement>);
  84. // find the highest z-index
  85. let highestIndex = 0;
  86. for (let element in elArray) {
  87. let zindex = parseInt(elArray[element].style.zIndex);
  88. if (zindex > highestIndex) {
  89. highestIndex = zindex;
  90. }
  91. }
  92. // set the highest z-index plus one
  93. document.getElementById(id).style.zIndex = (highestIndex + 1).toString();
  94. }
  95. function updateRedirectMessage() {
  96. const redirectElement = document.getElementById("redirect");
  97. const redirectUrl = redirectElement.dataset.redirecturl; // Access the data attribute
  98. const messageElement = redirectElement.querySelector("h2");
  99. messageElement.innerHTML = `You are about to be redirected to <a class="redirUrl" style=" cursor: pointer;
  100. color: blue;
  101. text-decoration: underline; " href="${redirectUrl}"">${redirectUrl.replace("https://", "")}</a>`;
  102. const buttonElement = redirectElement.querySelector("#okButton");
  103. // open redirect url
  104. buttonElement.setAttribute(
  105. "onclick",
  106. `window.location.href = "${redirectUrl}"`
  107. );
  108. }
  109. let apps: app[] = [
  110. {
  111. name: "About Me",
  112. logo: me.src,
  113. onclick: () => {
  114. raiseUpSpec("aboutme");
  115. document.getElementById("aboutme").style.display = "block";
  116. },
  117. row: 1,
  118. },
  119. {
  120. name: "Blog",
  121. logo: blog.src,
  122. onclick: () => {
  123. raiseUpSpec("redirect");
  124. document.getElementById("redirect").style.display = "block";
  125. document.getElementById("redirect").dataset.redirecturl =
  126. "https://blog.simo.ng/";
  127. updateRedirectMessage();
  128. },
  129. row: 1,
  130. },
  131. {
  132. name: "Projects",
  133. logo: projects.src,
  134. onclick: () => {
  135. raiseUpSpec("projects");
  136. document.getElementById("projects").style.display = "block";
  137. },
  138. row: 1,
  139. },
  140. // {
  141. // name: "Past Work",
  142. // logo: pastwork.src,
  143. // row: 1,
  144. // },
  145. {
  146. name: "Github",
  147. logo: github.src,
  148. onclick: () => {
  149. // ignore
  150. raiseUpSpec("redirect");
  151. document.getElementById("redirect").style.display = "block";
  152. document.getElementById("redirect").dataset.redirecturl =
  153. "https://github.com/s1monlol/";
  154. updateRedirectMessage();
  155. },
  156. row: 2,
  157. },
  158. {
  159. name: "Contact",
  160. logo: contact.src,
  161. row: 2,
  162. onclick: () => {
  163. raiseUpSpec("contact");
  164. document.getElementById("contact").style.display = "block";
  165. },
  166. },
  167. {
  168. name: "PGP Key",
  169. logo: pgp.src,
  170. row: 2,
  171. onclick: () => {
  172. raiseUpSpec("pgp");
  173. document.getElementById("pgp").classList.add("fullscreen");
  174. document.getElementById("pgp").style.display = "block";
  175. },
  176. },
  177. ];
  178. let projectsArr: project[] = [
  179. {
  180. title: "Summize",
  181. id: "summize",
  182. },
  183. {
  184. title: "Notion2Canvas",
  185. id: "notion",
  186. },
  187. {
  188. title: "PGPCord",
  189. id: "pgpcord",
  190. },
  191. {
  192. title: "IMDB Frontend",
  193. id: "imdb",
  194. },
  195. ];
  196. const row1Items = apps.filter((item) => item.row === 1);
  197. const row2Items = apps.filter((item) => item.row === 2);
  198. let clientFunctions: Function[] | String[] = [
  199. raiseUpSpec,
  200. updateRedirectMessage,
  201. dragElement,
  202. updateRedirectMessage,
  203. ];
  204. clientFunctions = clientFunctions.map((item) => String(item));
  205. apps = apps.map((item) => {
  206. item.onclick = String(item.onclick);
  207. return item;
  208. });
  209. ---
  210. <Layout title="Simo">
  211. <div style="width: 100%; height: calc(100vh - 3.5rem); ">
  212. <Pgp />
  213. <div style="display: flex;">
  214. <div
  215. style="height: 20rem; display: flex; flex-direction: column; align-items: flex-start;"
  216. >
  217. {row1Items.map((item) => <App {item} />)}
  218. </div>
  219. <div
  220. style="height: 20rem; display: flex; flex-direction: column; align-items: flex-start;"
  221. >
  222. {row2Items.map((item) => <App {item} />)}
  223. </div>
  224. </div>
  225. <Aboutme />
  226. <Redirect />
  227. <Contact />
  228. <Projects projects={projectsArr} />
  229. <Summize />
  230. <Notion />
  231. <Imdb />
  232. </div>
  233. <Taskbar />
  234. </Layout>
  235. <script define:vars={{ apps, projectsArr, clientFunctions }}>
  236. let dino = `
  237. ██████████████
  238. ████░░████████████
  239. ██████████████████
  240. ██████████████████
  241. ██████████████████
  242. ████████
  243. ██████████████░░
  244. ██████
  245. ██ ██████████
  246. ██▒▒ ▒▒▒▒██████████▒▒▒▒
  247. ████▓▓ ██████████████ ▒▒
  248. ██████▒▒▒▒████████████████
  249. ██████████████████████████
  250. ██████████████████████
  251. ██████████████████
  252. ▒▒██████████████
  253. ▒▒██████▒▒██▓▓
  254. ████ ▓▓
  255. ██▒▒ ▓▓
  256. ██ ██
  257. `;
  258. console.log(dino);
  259. for (func in clientFunctions) {
  260. eval(clientFunctions[func]);
  261. }
  262. Array.from(document.getElementsByClassName("project")).forEach((project) => {
  263. // console.log(projectsArr[0].id + "item");
  264. let id = projectsArr.find((i) => i.id + "item" == project.id).id;
  265. // console.log(id);
  266. if (id == "pgpcord") {
  267. project.onclick = () => {
  268. setTimeout(() => {
  269. raiseUpSpec("redirect");
  270. document.getElementById("redirect").style.display = "block";
  271. document.getElementById("redirect").dataset.redirecturl =
  272. "https://blog.simo.ng/articles/WIP/pgpcord";
  273. updateRedirectMessage();
  274. }, 1);
  275. };
  276. return;
  277. }
  278. project.onclick = () => {
  279. setTimeout(() => {
  280. document.getElementById(id).style.display = "block";
  281. raiseUpSpec(id);
  282. // console.log("test");
  283. }, 1);
  284. };
  285. });
  286. Array.from(document.getElementsByClassName("window")).forEach((window) => {
  287. dragElement(window);
  288. window.addEventListener("click", () => {
  289. raiseUpSpec(window.id);
  290. });
  291. Array.from(document.querySelectorAll(".projectwindow a")).forEach(
  292. (link) => {
  293. link.addEventListener("click", (e) => {
  294. document.getElementById("redirect").style.display = "block";
  295. document.getElementById("redirect").dataset.redirecturl = link.href;
  296. updateRedirectMessage();
  297. e.preventDefault();
  298. setTimeout(() => {
  299. raiseUpSpec("redirect");
  300. }, 1);
  301. return false;
  302. });
  303. }
  304. );
  305. Array.from(window.getElementsByClassName("close")).forEach((button) => {
  306. button.addEventListener("click", () => {
  307. window.style.display = "none";
  308. });
  309. });
  310. });
  311. apps.forEach((app) => {
  312. let itemName = app.name.replace(" ", "");
  313. // console.log(itemName)
  314. if (app.onclick == "undefined") {
  315. return;
  316. }
  317. document.getElementById(itemName).addEventListener("click", () => {
  318. const appFunc = eval(app.onclick);
  319. appFunc();
  320. });
  321. });
  322. </script>