Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Js2 #289

Open
wants to merge 129 commits into
base: main
Choose a base branch
from
Open

Js2 #289

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
85417c1
Create index.html
Voidwaker Mar 23, 2024
cc9ec0c
bootstrap up and running
Voidwaker Mar 23, 2024
e73e5c4
added nav bar and some of the login on the homepage
Voidwaker Mar 24, 2024
fe3759f
added all the pages and just some small html
Voidwaker Mar 24, 2024
6f5f94a
added marin to the content
Voidwaker Mar 24, 2024
34a0263
Update index.html
Voidwaker Mar 24, 2024
7ebea2c
html
Voidwaker Mar 24, 2024
d0182b8
sass
Voidwaker Mar 24, 2024
bb9e828
Update index.html
Voidwaker Mar 24, 2024
21bff20
forgot to add a</div>
Voidwaker Mar 24, 2024
f7eb7c3
Update index.html
Voidwaker Mar 25, 2024
2ac0c88
html
Voidwaker Mar 25, 2024
ad9fc71
adding custom colours and fonts to h1 and h1
Voidwaker Apr 2, 2024
2ef8bbc
information
Voidwaker Apr 2, 2024
a9481c6
Update package.json
Voidwaker Apr 2, 2024
eb9def8
added comments, and profile details
Voidwaker Apr 3, 2024
b7fec36
updated nav bar
Voidwaker Apr 3, 2024
c152c9d
got my scss file to work.
Voidwaker Apr 3, 2024
dd1dacc
trying to add custom color
Voidwaker Apr 3, 2024
7bc2668
alignment and scss
Voidwaker Apr 3, 2024
e4f808b
profile page col-10 etc
Voidwaker Apr 3, 2024
e9720d2
Update index.html
Voidwaker Apr 3, 2024
804c505
custom buttons
Voidwaker Apr 3, 2024
3376605
added nav bar and posts to the feed page
Voidwaker Apr 4, 2024
ecbafc7
Update index.html
Voidwaker Apr 4, 2024
072a695
Update index.html
Voidwaker Apr 4, 2024
9f925e5
trying to get custm button to work
Voidwaker Apr 4, 2024
cad1710
custom button trouble
Voidwaker Apr 4, 2024
5b0f2bb
still problems with custom buittons
Voidwaker Apr 4, 2024
c9b292f
scss not workign propparly
Voidwaker Apr 4, 2024
0e66b58
bullshit
Voidwaker Apr 4, 2024
1762614
no idea how, but it woeked.
Voidwaker Apr 4, 2024
d122829
Update index.html
Voidwaker Apr 4, 2024
a7e88b5
Update index.html
Voidwaker Apr 4, 2024
ecfde14
Update index.html
Voidwaker Apr 4, 2024
154d9b5
custom copulors on text
Voidwaker Apr 4, 2024
e81e41b
njkoløfd
Voidwaker Apr 4, 2024
a6792cd
Update index.html
Voidwaker Apr 4, 2024
badfad5
Update index.html
Voidwaker Apr 5, 2024
01756f6
custom green
Voidwaker Apr 5, 2024
1b3069a
still problems with sass and customize things
Voidwaker Apr 5, 2024
8971254
still no luck with the custom colors
Voidwaker Apr 5, 2024
69105a7
Update package-lock.json
Voidwaker Apr 5, 2024
5aa8f5a
tying to get this to work
Voidwaker Apr 5, 2024
2b162db
still truyig toi fuguyre oyt why iots not workiugn
Voidwaker Apr 5, 2024
33693b7
im going to get mental problems over this
Voidwaker Apr 5, 2024
1707e4f
fuyck this shit
Voidwaker Apr 5, 2024
8df0084
Update _variables.scss
Voidwaker Apr 5, 2024
3e4ee9c
Update index.html
Voidwaker Apr 5, 2024
a2df904
think its fixed now i have noe idea but i think its fixed
Voidwaker Apr 5, 2024
bce0a37
Update index.html
Voidwaker Apr 5, 2024
fe46c92
not workig (custotext-green)
Voidwaker Apr 5, 2024
33cbbab
think maby its fixed now, but not sure
Voidwaker Apr 5, 2024
8d1db5c
text-green (custom text color to match buttons
Voidwaker Apr 5, 2024
5dc4890
Update index.html
Voidwaker Apr 5, 2024
d1dbadd
text-green and text-blue
Voidwaker Apr 5, 2024
117f582
Update index.html
Voidwaker Apr 5, 2024
9f389f0
Update index.html
Voidwaker Apr 5, 2024
77faf86
custom font-family
Voidwaker Apr 7, 2024
fcd3485
Update index.html
Voidwaker Apr 7, 2024
972f211
Update index.html
Voidwaker Apr 7, 2024
c34302f
Update index.html
Voidwaker Apr 7, 2024
e64ba35
Update index.html
Voidwaker Apr 7, 2024
1de3247
some last minute alignment
Voidwaker Apr 7, 2024
57e084b
Update index.html
Voidwaker Apr 7, 2024
a29ee5f
had forgot to switch from norwegian to english
Voidwaker Apr 10, 2024
9ad4447
removed <link rel=stylesheet
Voidwaker Apr 11, 2024
52ef317
removed <lin rel=
Voidwaker Apr 11, 2024
3c6da6e
Update index.html
Voidwaker Apr 11, 2024
ab53cb9
added custom follow button
Voidwaker Apr 11, 2024
b0d3a8e
fixing horisontal scrollbar
Voidwaker Apr 11, 2024
ff7387e
Update index.html
Voidwaker Apr 11, 2024
8309d39
form validation
Voidwaker Apr 11, 2024
41d7765
Update index.html
Voidwaker Apr 11, 2024
2ef64ac
Update index.html
Voidwaker Apr 11, 2024
b255797
Update index.html
Voidwaker Apr 11, 2024
4aa6fe6
Update index.html
Voidwaker Apr 11, 2024
78d2289
Update index.html
Voidwaker Apr 11, 2024
4539ecd
Update index.html
Voidwaker Apr 11, 2024
c63a4d4
deleted index.css and index.map.css files
Voidwaker Apr 12, 2024
aef60f8
remove dist/css from tracking
Voidwaker Apr 15, 2024
0c06482
removed a button
Voidwaker Apr 16, 2024
204a782
trying to fix 405 error
Voidwaker Apr 16, 2024
40bf06a
Update index.html
Voidwaker Apr 16, 2024
26e343f
dev independencies
Voidwaker Apr 16, 2024
db68456
live-server
Voidwaker Apr 19, 2024
e458555
Update index.html
Voidwaker Apr 19, 2024
42643b3
api
Voidwaker May 12, 2024
d03192a
forms
Voidwaker May 12, 2024
2b0e5fd
Update index.html
Voidwaker May 12, 2024
8fe756b
Update index.html
Voidwaker May 12, 2024
eef5e40
form
Voidwaker May 12, 2024
4819fd3
register form fixed
Voidwaker May 12, 2024
ba409a8
login form
Voidwaker May 12, 2024
a4db607
login
Voidwaker May 12, 2024
9972362
redid my login and register
Voidwaker May 13, 2024
e87a74a
form
Voidwaker May 13, 2024
6a4326d
redid the register form js
Voidwaker May 13, 2024
5a61ea2
login/register
Voidwaker May 13, 2024
a3d9561
form
Voidwaker May 13, 2024
4480e90
accestoken error
Voidwaker May 13, 2024
3d7a09f
fixed login
Voidwaker May 14, 2024
d28d795
added local storage
Voidwaker May 16, 2024
22be1b3
alert when registration is sucessful
Voidwaker May 16, 2024
62376d4
login alert
Voidwaker May 16, 2024
927b332
update,read,delete posts
Voidwaker May 16, 2024
59238b3
create
Voidwaker May 19, 2024
7d6e7a6
create posts
Voidwaker May 19, 2024
6a02d9e
posts
Voidwaker May 20, 2024
6e9dd63
401 error fixed
Voidwaker May 20, 2024
3ba6060
test and fetch
Voidwaker May 20, 2024
e6e0080
fething 100 posts
Voidwaker May 20, 2024
f085ef1
fetching posts
Voidwaker May 20, 2024
b9559f6
fixed html for creating and editing a post
Voidwaker May 20, 2024
aaf3f32
Update index.html
Voidwaker May 21, 2024
a0ba631
posts
Voidwaker May 21, 2024
f3e4c25
Update post.mjs
Voidwaker May 21, 2024
263e1bd
Update updatePost.mjs
Voidwaker May 21, 2024
c64bbd8
Update updatePost.mjs
Voidwaker May 21, 2024
cdde4ca
Update updatePost.mjs
Voidwaker May 21, 2024
cc7e664
delete,sort,update and search
Voidwaker May 21, 2024
0730cfa
removed console.log
Voidwaker May 21, 2024
0f8f2e2
Update README.md
Voidwaker May 21, 2024
f14a339
Update update.mjs
Voidwaker May 22, 2024
b14e87c
Merge branch 'js2-try2' of https://github.com/Voidwaker/css-framework…
Voidwaker May 22, 2024
a4b01c9
updated nav
Voidwaker May 22, 2024
2928a02
some minor improvements
Voidwaker May 22, 2024
566b893
Update README.md
Voidwaker May 22, 2024
f224101
Update README.md
Voidwaker May 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules/
.DS_Store
dist/
dist/
117 changes: 115 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,115 @@
# css-frameworks-ca
Replace this text with a description of your social media project.
## js2 social media application
link to trello: https://trello.com/invite/b/HgMSDygC/ATTI59165adf424964b1c8ef6ef67039647001A570D6/javascrip2

this is my "social media application" you can register a user (with a valid @noroff(stud.noroff.no). the registerd ouser can login, make posts, edit posts and delete posts. and view others posts.
navigation is clear on the homepage(login) wher there is a button for registration and after registration, there is a button for login, when u have gotten the confiramtion that your logged inn, use the nav bar to get to feed or profile.


---
### made with:
<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/HTML.svg" width="50" height="50">
<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/CSS.svg" width="50" height="50">
<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/JavaScript.svg" width="50" height="50">
<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/VSCode-Dark.svg" width="50" height="50"> <img
---

Description--

## Brief
You have been tasked with producing a new JavaScript front-end client for an existing social media platform. The client application must be attractive and responsive, but you have an otherwise blank slate in terms of theme design language.

Using the provided API and API documentation, create a functioning user interface that allows for viewing, posting, editing and deleting social media content.

Social API routes require authorisation via JWT (JSON Web Tokens). You will need to register an account and login to access your token.

To complete the required features, you will also need to make use of GET, POST, PUT, and DELETE HTTP methods.

Using localStorage is highly recommended, especially for storing JWT tokens.

A finished project fulfils the requirements below with an easy to use and error-free user interface.

Required features
The following user stories are required for a passing submission:

User with @noroff.no or @stud.noroff.no email can register profile
Registered user can login
User can view a post content feed
User can filter the post content feed
User can search the post content feed
User can view a post content item by ID
User can create a post content item
User can update a post content item
User can delete a post content item
Additional features
The following user stories are optional:

User can create a comment on a post
User can edit profile media
User can follow/unfollow a profile
User can react to a post content item

## register
here u can register a profile with a @noroff.no or @stud.noroff.no email, when registrering, you will get a confimation if the registration is successfull, and you will get a error message if the registration was unsucessfull.

## login
after registring a user, you can take the same email and password and login.

## feed
in the feed page, when you have logged inn, you can create a post (with a title, body,tags(optionale) and media(optionale) further down the page, u can update(edit) a post that you have created,just click on the edit button on the post u want to edit (to get the post id) .you can also delete a post, if you are unhappy, or if u dont want it out there, its simple, just click on the delete button on the post u want to delete (to get the post id so the post can be deleted)
we have a search fuction, if u wanna see 100 posts of "test" just search test or example"
after that we have a sorting option, where the default is newest, but if you set it to the oldest, the oldests posts (out of the 100 fetched) is being displayed first.
last we have the feed, here you can see the time the posts, the time the have beed posted.

## profile

here you can see your profile
i did not get time to make the profile page alot of the things was optionale, so hopefully you can atleast edit your bio, and mabye press the follow button.

#### Getting Started

Installing

Clone the repo:

git clone git@github.com: https://github.com/Voidwaker/css-frameworks-ca/tree/js2-try2

Install the dependencies: N/A

npm install

Running

To run the app, run the following commands:

npm run dev





---

Contributing


As this is my js2 assignment, i dont want contributions, but feedback to how i can imporve the site is always velcome. Thank you!

Any suggestions will be happily taken into account- feel free to message me!
---

Contact:


Email me:
Sigurdvaaler@hotmail.com

<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/Gmail-Dark.svg" width="50" height="50"> <img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/Discord.svg" width="50" height="50">


Find me on Discord:
(Sigurd Vaaler
Voidwaker1)

---

Acknowledgments:
108 changes: 108 additions & 0 deletions feed/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Feed</title>
<link rel="stylesheet" href="/dist/css/index.css">
<script defer src="/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script type="module" src="/js/index.mjs" defer></script>
</head>
<body class="bg-dark">
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="/">Home</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/profile">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="/feed/index.html">Feed</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<main class="container mt-4">
<div class="card border-dark mb-3 mx-auto">
<div class="card-body">
<h5 class="card-title mb-3 text-green text-center">Create New Post</h5>
<form id="createPost">
<div class="form-group mb-3 text-green">
<label for="postTitle">Title</label>
<input class="form-control" type="text" id="postTitle" name="title" required>
</div>
<div class="form-group mb-3 text-green">
<label for="postBody">Body</label>
<textarea class="form-control" id="postBody" name="body" required></textarea>
</div>
<div class="form-group mb-3 text-green">
<label for="postTags">Tags (comma separated)</label>
<input class="form-control" type="text" id="postTags" name="tags">
</div>
<div class="form-group mb-3 text-green">
<label for="postMedia">Media</label>
<input class="form-control" type="url" id="postMedia" name="media">
</div>
<div class="d-flex justify-content-center">
<button class="btn btn-success" type="submit">Create Post</button>
</div>
</form>
</div>
</div>

<div class="card border-dark mb-3 mx-auto">
<h1 class="fst-italic fw-bold text-center">Edit Posts</h1>
<div class="card-body">
<form id="editPost">
<div class="form-group mb-3 text-green">
<label for="editPostTitle">Title</label>
<input class="form-control" type="text" id="editPostTitle" name="title" required>
</div>
<div class="form-group mb-3 text-green">
<label for="editPostBody">Body</label>
<textarea class="form-control" id="editPostBody" name="body" required></textarea>
</div>
<div class="form-group mb-3 text-green">
<label for="editPostTags">Tags</label>
<input class="form-control" type="text" id="editPostTags" name="tags">
</div>
<div class="form-group mb-3 text-green">
<label for="editPostMedia">Media</label>
<input class="form-control" type="url" id="editPostMedia" name="media">
</div>
<div class="d-flex justify-content-center">
<button class="btn btn-success" type="submit">Update Post</button>
</div>
</form>
</div>
</div>

<div class="d-flex justify-content-center mb-3">
<div class="col-md-6 col-lg-4">
<select id="filterPosts" class="form-control text-green">
<option value="newest">Newest</option>
<option value="oldest">Oldest</option>
<option value="popular">Most Popular</option>
</select>
</div>
</div>

<div class="d-flex justify-content-center mb-3">
<div class="col-md-8">
<input id="searchPosts" type="text" class="form-control text-green" placeholder="Search for posts...">
</div>
</div>

<h1 class="fst-italic fw-bold text-center">Posts</h1>
<div id="posts" class="mt-4"></div>
</main>
</body>
</html>

57 changes: 57 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login/Registrer</title>
<link rel="stylesheet" href="dist/css/index.css">
<script defer src="node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script type="module" src="./js/index.mjs" defer></script>

</head>
<body class="bg-dark">
<header class="container-fluid">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="/">Home</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/profile">Profil</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/feed/index.html">Feed</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/index.html">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container-sm col-6 mt-5">
<h2 class="text-center">Logg Inn</h2>
<form id="loginForm">
<div class="mb-3">
<label for="loginEmail" class="form-label text-blue">E-post</label>
<input type="email" class="form-control text-green" id="loginEmail" name="email" placeholder="Email@example.com" required>
</div>
<div class="mb-3">
<label for="loginPassword" class="form-label text-blue">Passord</label>
<input type="password" class="form-control text-green" id="loginPassword" name="password" placeholder="Password" required minlength="8">
</div>
<div class="d-flex justify-content-center">
<button type="submit" class="btn btn-custom">Logg Inn</button>
</div>
</form>
<div id="errorDisplay" style="color: red;"></div>
<div class="d-flex justify-content-center mt-3">
<a href="register.html" class="btn btn-custom">Register</a>
</div>
</div>
</body>
</html>
33 changes: 33 additions & 0 deletions js/api/auth/authFetch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { load } from "../../storage/index.mjs";

export function headers() {
const token = load("token");

return {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
};
}

export async function authFetch(url, options = {}){
const requestOptions = {
...options,
headers: {
...headers(),
...options.headers
}
};

try {
const response = await fetch(url, requestOptions);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A conditional statement is missing here to check if the response is OK or not.

return response;
} catch (error) {
console.error('Feil under fetch:', error);
throw error;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch block: to suppress an error
throw: to create an error

Understand the differences, they have different purposes. Here you're basically catching an error and throwing it again.

Suggestion: remove the throw from the catch block and use the try/catch block in a UI/UX code block e.g event listener.

}
}





27 changes: 27 additions & 0 deletions js/api/auth/login.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { API_SOCIAL_URL } from "../constants.mjs";
import * as storage from "../../storage/index.mjs";

const action = "/auth/login";
const method = "POST";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed opportunity for JSDocs here.

export async function login(profile){
const loginURL = API_SOCIAL_URL + action;
const body = JSON.stringify(profile);

const Response = await fetch(loginURL, {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. There should be a try/catch here.

  2. A conditional statement should also be here to check if the response is OK or not. Response should be in small caps.

headers: {
'Content-Type': 'application/json'
},
method,
body
});

const {accessToken, ...user} = await Response.json();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object destructuring - good job!

storage.save('token', accessToken);
storage.save('profile', user);

alert('Login successful');
}



20 changes: 20 additions & 0 deletions js/api/auth/register.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { API_SOCIAL_URL } from "../constants.mjs";

const action = "/auth/register";
const method = "POST";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed opportunity for JSDocs here.

export async function register(profile){
const registerURL = API_SOCIAL_URL + action;
const body = JSON.stringify(profile);

const Response = await fetch(registerURL, {
headers: {
'Content-Type': 'application/json'
},
method,
body
});

const response = await Response.json();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. There should be a try/catch here.

  2. A conditional statement should also be here to check if the response is OK or not. Response should be in small caps.

alert('Registration successful');
}
4 changes: 4 additions & 0 deletions js/api/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const API_HOST_URL = 'https://api.noroff.dev/api/v1';
export const API_BASE = '/api/v1';
export const API_SOCIAL_BASE = '/social';
export const API_SOCIAL_URL = `${API_HOST_URL}${API_SOCIAL_BASE}`;
Loading