Skip to content

Commit

Permalink
Implement isdigram using OOP b00tc4mp#391
Browse files Browse the repository at this point in the history
  • Loading branch information
PereHDZ committed Mar 13, 2024
1 parent 7de96c3 commit 92e0725
Show file tree
Hide file tree
Showing 40 changed files with 2,826 additions and 368 deletions.
28 changes: 28 additions & 0 deletions staff/pere-hernandez/isdigram copy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ISDIGram

## Functional Description

### Functionalities

- Crate a post
- take picture with camera
- upload picture from phone
- apply filter to picture
- Tag a user
- View other people's posts
- Send messages
- Follow user
- Search user
- Search post (by hashtag)
- Toggle like a post
- Toggle save a post
- Comment a post
- Video-call user
- Live video streaming
- Publsh a story

### UI Design

#### Layout

#### Prototype
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added staff/pere-hernandez/isdigram copy/chat-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions staff/pere-hernandez/isdigram copy/chat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions staff/pere-hernandez/isdigram copy/data/Collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
function Collection(name){
this.name = name
}



//helpers

Collection.prototype._generateId = function() {
return (+((parseInt(Math.random() * 10 ** 17)).toString())).toString(36)
}

Collection.prototype._loadDocuments = function () {
var documentsJSON = localStorage[this.name]

var documents = JSON.parse(documentsJSON || '[]')

return documents
}

Collection.prototype._saveDocuments = function (documents) {
//validation

if (!(documents instanceof Array))
throw new TypeError ('documents is not an Array')

documents.forEach(function (document){
if(!(document instanceof Object))
throw new TypeError('some elements in documents are not a document')
})

//logic
var documentsJSON = JSON.stringify(documents)

localStorage[this.name] = documentsJSON
}

Collection.prototype._backup = function (){
localStorage[this.name + '_backup'] = localStorage[this.name]
}

Collection.prototype._restore = function (){
localStorage[this.name] = localStorage[this.name + '_backup']
}



// CRUD

Collection.prototype.findOne = function (callback) {
//validation

if (!(callback instanceof Function))
throw new TypeError ('callback is not a Function')

//logic
var documents = this._loadDocuments()

var document = documents.find(callback)

return document
}

Collection.prototype.insertOne = function (document) {
//validation

if (!(document instanceof Object))
throw new TypeError ('document is not an Object')

//logic
var documents = this._loadDocuments()

document.id = this._generateId()

documents.push(document)

this._saveDocuments(documents)
}

Collection.prototype.updateOne = function (document) {
//validation

if (!(document instanceof Object))
throw new TypeError('document is not an Object')
if (typeof document.id !== 'string')
throw new TypeError('id must be a string')

//logic
var documents = this._loadDocuments()

var index = documents.findIndex(function (document2) {
return document2.id === document.id
})

if (index > -1){
documents.splice(index, 1, document)

this._saveDocuments(documents)
}
}

Collection.prototype.deleteOne = function (callback){
//validation

if (!(callback instanceof Function))
throw new TypeError ('callback is not a Function')

//logic
var documents = this._loadDocuments()

var index = documents.findIndex(callback)

if (index > -1){
documents.splice(index, 1)

this._saveDocuments(documents)
}
}

Collection.prototype.getAll = function (){
var documents = this._loadDocuments()

return documents
}

Collection.prototype.printAll = function () {
var documents = this._loadDocuments()

console.table(documents)
}
17 changes: 17 additions & 0 deletions staff/pere-hernandez/isdigram copy/data/Collection.spec.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Collection spec</title>
</head>

<body>
<h1>Collection spec</h1>

<script src="../vendor/matcha.js"></script>

<script src="Collection.js"></script>
<script src="Collection.spec.js"></script>
</body>
</html>
Loading

0 comments on commit 92e0725

Please sign in to comment.