index.astro 7.7 KB

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