Skip to content

Commit

Permalink
added cookie message
Browse files Browse the repository at this point in the history
  • Loading branch information
cophilot committed Nov 10, 2023
1 parent 73e95b1 commit 50c977b
Showing 10 changed files with 175 additions and 49 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"version": "1.0.1",
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --open --port 4201",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
1 change: 1 addition & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<router-outlet></router-outlet>
<app-notification></app-notification>
<app-cookie-message></app-cookie-message>
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -59,6 +59,7 @@ import { AddFileComponent } from './user-input/add-file/add-file.component';
import { NotificationComponent } from './notification/notification.component';
import { DeploySpecComponent } from './user-input/deploy-spec/deploy-spec.component';
import { HeadingComponent } from './heading/heading.component';
import { CookieMessageComponent } from './cookie-message/cookie-message.component';
@NgModule({
declarations: [
AppComponent,
@@ -112,6 +113,7 @@ import { HeadingComponent } from './heading/heading.component';
NotificationComponent,
DeploySpecComponent,
HeadingComponent,
CookieMessageComponent,
],
imports: [
BrowserModule,
11 changes: 11 additions & 0 deletions src/app/cookie-message/cookie-message.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="message" *ngIf="isVisible()">
<p>
This website uses cookies to ensure you get the best experience on our
website.
<a href="https://www.cookiesandyou.com/" target="_blank">Learn more</a>
</p>
<div class="btnBox">
<button (click)="rejectCookies()">Reject</button>
<button (click)="acceptCookies()">Accept</button>
</div>
</div>
60 changes: 60 additions & 0 deletions src/app/cookie-message/cookie-message.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.message {
position: fixed;
width: 100%;
bottom: 0;
left: 0;
height: 300px;
z-index: 100;
background-color: var(--header-color);
color: var(--text-color);
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
p {
margin: 0;
padding: 0;
font-size: 25px;
text-align: center;
width: 90%;
}
.btnBox {
display: flex;
align-items: center;
justify-content: center;
flex-direction: row;
margin-top: 20px;
button {
margin: 0 10px;
border: none;
background-color: var(--primary-color);
color: var(--inverted-text-color);
border-radius: 5px;
padding: 10px;
font-size: 20px;
width: 100px;
cursor: pointer;
transition: 0.3s;
&:hover {
background-color: var(--secondary-color);
transform: scale(1.1);
}
}
}
}
@media screen and (max-width: 800px) {
.message {
p {
font-size: 20px;
}
.btnBox {
button {
font-size: 17px;
&:hover {
background-color: var(--primary-color);
transform: scale(1);
}
}
}
}
}
21 changes: 21 additions & 0 deletions src/app/cookie-message/cookie-message.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { CookieMessageComponent } from './cookie-message.component';

describe('CookieMessageComponent', () => {
let component: CookieMessageComponent;
let fixture: ComponentFixture<CookieMessageComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [CookieMessageComponent]
});
fixture = TestBed.createComponent(CookieMessageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
28 changes: 28 additions & 0 deletions src/app/cookie-message/cookie-message.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Component } from '@angular/core';
import { LocalStorageService } from '../services/local-storage.service';

@Component({
selector: 'app-cookie-message',
templateUrl: './cookie-message.component.html',
styleUrls: ['./cookie-message.component.scss'],
})
export class CookieMessageComponent {
static visible = false;

acceptCookies() {
LocalStorageService.acceptCookies();
CookieMessageComponent.visible = false;
}
rejectCookies() {
LocalStorageService.rejectCookies();
CookieMessageComponent.visible = false;
}

isVisible() {
return CookieMessageComponent.visible;
}

static show() {
CookieMessageComponent.visible = true;
}
}
35 changes: 0 additions & 35 deletions src/app/markdown-content/markdown-content.component.ts
Original file line number Diff line number Diff line change
@@ -98,40 +98,6 @@ export class MarkdownContentComponent {
language: style,
title: name,
});
} else if (lines[i].trim().startsWith('#')) {
//image
let name = lines[i].split('[')[1].split(']')[0];
let url = lines[i].split('(')[1].split(')')[0];
let style = '';
if (lines[i].split(')')[1].includes('{')) {
style = lines[i].split('{')[1].split('}')[0];
}
if (lines[i].startsWith('?[')) {
let urlToImage =
'http://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
'/woop/image/get/' +
url;
let newURL = await this.http
.get(urlToImage, { responseType: 'text' })
.toPromise()
.then((res) => {
return res;
});
if (newURL != undefined) {
url = newURL;
} else {
console.log('error getting image');
}
}
this.blocks.push({
type: 'image',
code: url,
language: style,
title: name,
});
} else if (lines[i].startsWith('$$$[')) {
//image
let name = lines[i].split('[')[1].split(']')[0];
@@ -157,7 +123,6 @@ export class MarkdownContentComponent {
!lines[i].startsWith('~~~') &&
!lines[i].startsWith('![') &&
!lines[i].startsWith('$$$[') &&
!lines[i].startsWith('#') &&
!lines[i].startsWith('?[')
) {
if (lines[i].startsWith('```')) {
57 changes: 45 additions & 12 deletions src/app/services/local-storage.service.ts
Original file line number Diff line number Diff line change
@@ -3,14 +3,22 @@ import { IrisinterfaceService } from './irisinterface.service';
import { UserManger, VerifyCache } from 'src/utils/classes';
import { Router } from '@angular/router';
import { ChaptermanagerService } from './chaptermanager.service';
import { CookieMessageComponent } from '../cookie-message/cookie-message.component';

@Injectable({
providedIn: 'root',
})
export class LocalStorageService {
rememberPage: boolean = true;

static cookiesAccepted: boolean = false;

constructor(private router: Router) {
LocalStorageService.cookiesAccepted = this.getCookiesAccepted();
if (!LocalStorageService.cookiesAccepted) {
CookieMessageComponent.show();
}

this.rememberPage = this.getRememberPage();
if (this.getStayLoggedIn()) {
const username = this.getUserName();
@@ -32,6 +40,14 @@ export class LocalStorageService {
}
}

getCookiesAccepted(): boolean {
let rememberPage = localStorage.getItem('WOOPCookiesAccepted');
if (rememberPage == null) {
return false;
}
return rememberPage == 'true';
}

getLanguageTo(): string {
let languageTo = localStorage.getItem('languageTo');
if (languageTo == null) {
@@ -41,7 +57,7 @@ export class LocalStorageService {
}

setLanguageTo(languageTo: string) {
localStorage.setItem('languageTo', languageTo);
LocalStorageService.setLS('languageTo', languageTo);
}

getRememberPage(): boolean {
@@ -53,12 +69,12 @@ export class LocalStorageService {
}

setRememberPage(rememberPage: boolean) {
localStorage.setItem('rememberPage', rememberPage ? 'true' : 'false');
LocalStorageService.setLS('rememberPage', rememberPage ? 'true' : 'false');
this.rememberPage = rememberPage;
}

setColorScheme(darkMode: boolean) {
localStorage.setItem('colorScheme', darkMode ? 'dark' : 'light');
LocalStorageService.setLS('colorScheme', darkMode ? 'dark' : 'light');
}

getColorScheme(): string | null {
@@ -67,7 +83,7 @@ export class LocalStorageService {
}

setFontSize(fontSize: number) {
localStorage.setItem('fontSize', fontSize.toString());
LocalStorageService.setLS('fontSize', fontSize.toString());
}

getFontSize(): number {
@@ -79,7 +95,7 @@ export class LocalStorageService {
}

setPageForChapter(chapterTitle: string, page: number) {
localStorage.setItem(chapterTitle, page.toString());
LocalStorageService.setLS(chapterTitle, page.toString());
}

getPageForChapter(chapterTitle: string): number {
@@ -103,7 +119,7 @@ export class LocalStorageService {
}

setServerHost(serverHost: string) {
localStorage.setItem('serverHost', serverHost);
LocalStorageService.setLS('serverHost', serverHost);
IrisinterfaceService.host = serverHost;
}

@@ -116,7 +132,7 @@ export class LocalStorageService {
}

setServerPort(serverPort: number) {
localStorage.setItem('serverPort', serverPort.toString());
LocalStorageService.setLS('serverPort', serverPort.toString());
IrisinterfaceService.port = serverPort;
}

@@ -125,11 +141,11 @@ export class LocalStorageService {
}

setUserName(userName: string) {
localStorage.setItem('userName', userName);
LocalStorageService.setLS('userName', userName);
}

setStayLoggedIn(stayLoggedIn: boolean) {
localStorage.setItem('stayLoggedIn', stayLoggedIn ? 'true' : 'false');
LocalStorageService.setLS('stayLoggedIn', stayLoggedIn ? 'true' : 'false');
}

getStayLoggedIn(): boolean {
@@ -149,7 +165,7 @@ export class LocalStorageService {
}

setPassword(password: string) {
localStorage.setItem('password', password);
LocalStorageService.setLS('password', password);
}

removePassword() {
@@ -182,7 +198,7 @@ export class LocalStorageService {
}
}
serverConnections.push({ name: name, host: host, port: port });
localStorage.setItem(
LocalStorageService.setLS(
'serverConnections',
JSON.stringify(serverConnections)
);
@@ -196,7 +212,7 @@ export class LocalStorageService {
break;
}
}
localStorage.setItem(
LocalStorageService.setLS(
'serverConnections',
JSON.stringify(serverConnections)
);
@@ -205,4 +221,21 @@ export class LocalStorageService {
clearAll() {
localStorage.clear();
}

static setLS(key: string, value: string) {
if (!this.cookiesAccepted) {
return;
}
localStorage.setItem(key, value);
}

static acceptCookies() {
LocalStorageService.cookiesAccepted = true;
LocalStorageService.setLS('WOOPCookiesAccepted', 'true');
}

static rejectCookies() {
LocalStorageService.cookiesAccepted = false;
localStorage.clear();
}
}
7 changes: 6 additions & 1 deletion src/utils/classes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LocalStorageService } from 'src/app/services/local-storage.service';

export class Chapter {
public Title: string;
public Pages: Page[];
@@ -120,7 +122,10 @@ export class VerifyCache {
return;
}
if (save) {
localStorage.setItem('verifyCache', JSON.stringify(this.verifyCache));
LocalStorageService.setLS(
'verifyCache',
JSON.stringify(this.verifyCache)
);
}
}

0 comments on commit 50c977b

Please sign in to comment.